Java Code Examples for org.bukkit.inventory.meta.PotionMeta#setBasePotionData()

The following examples show how to use org.bukkit.inventory.meta.PotionMeta#setBasePotionData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
private boolean onPotion(Player sender) {
    ItemStack itemStack = new ItemStack(Material.POTION);
    PotionMeta itemMeta = Objects.requireNonNull((PotionMeta) itemStack.getItemMeta());
    itemMeta.setBasePotionData(new PotionData(potion.getConfig().getRecipe().getBasePotion()));
    itemStack.setItemMeta(potion.convert(itemMeta));
    sender.getInventory().addItem(itemStack);
    return true;
}
 
Example 2
Source File: Potion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies the effects of this potion to the given {@link ItemStack}. The
 * ItemStack must be a potion.
 *
 * @param to The itemstack to apply to
 */
public void apply(ItemStack to) {
    Validate.notNull(to, "itemstack cannot be null");
    Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion");
    Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion");
    PotionMeta meta = (PotionMeta) to.getItemMeta();
    meta.setBasePotionData(new PotionData(type, extended, level == 2));
    to.setItemMeta(meta);
}
 
Example 3
Source File: Potion.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts this potion to an {@link ItemStack} with the specified amount
 * and a correct damage value.
 *
 * @param amount The amount of the ItemStack
 * @return The created ItemStack
 */
public ItemStack toItemStack(int amount) {
    Material material;
    if (isSplash()) {
        material = Material.SPLASH_POTION;
    } else {
        material = Material.POTION;
    }
    ItemStack itemStack = new ItemStack(material, amount);
    PotionMeta meta = (PotionMeta) itemStack.getItemMeta();
    meta.setBasePotionData(new PotionData(type, level == 2, extended));
    itemStack.setItemMeta(meta);
    return itemStack;
}
 
Example 4
Source File: CustomPotion.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public CustomPotion(String name, PotionType type, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setBasePotionData(new PotionData(type));
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
Example 5
Source File: GlobalItemParser.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException {
    int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1);

    // If the item is a potion with non-zero damage, and there is
    // no modern potion ID, decode the legacy damage value.
    final Potion legacyPotion;
    if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) {
        try {
            legacyPotion = Potion.fromDamage(damage);
        } catch(IllegalArgumentException e) {
            throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e);
        }

        // If the legacy splash bit is set, convert to a splash potion
        if(legacyPotion.isSplash()) {
            type = Material.SPLASH_POTION;
            legacyPotion.setSplash(false);
        }

        // Potions always have damage 0
        damage = 0;
    } else {
        legacyPotion = null;
    }

    ItemStack itemStack = new ItemStack(type, amount, damage);
    if(itemStack.getType() != type) {
        throw new InvalidXMLException("Invalid item/block", el);
    }

    final ItemMeta meta = itemStack.getItemMeta();
    if(meta != null) { // This happens if the item is "air"
        parseItemMeta(el, meta);

        // If we decoded a legacy potion, apply it now, but only if there are no custom effects.
        // This emulates the old behavior of custom effects overriding default effects.
        if(legacyPotion != null) {
            final PotionMeta potionMeta = (PotionMeta) meta;
            if(!potionMeta.hasCustomEffects()) {
                potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(),
                                                            legacyPotion.hasExtendedDuration(),
                                                            legacyPotion.getLevel() == 2));
            }
        }

        itemStack.setItemMeta(meta);
    }

    return itemStack;
}
 
Example 6
Source File: VersionUtils_1_13.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PotionMeta setBasePotionEffect(PotionMeta potionMeta, PotionData potionData) {
    potionMeta.setBasePotionData(potionData);
    return potionMeta;
}
 
Example 7
Source File: VersionUtils_1_12.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public PotionMeta setBasePotionEffect(PotionMeta potionMeta, PotionData potionData) {
    potionMeta.setBasePotionData(potionData);
    return potionMeta;
}
 
Example 8
Source File: AutoBrewer.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private ItemStack brew(Material input, Material potionType, PotionMeta potion) {
    PotionData data = potion.getBasePotionData();

    if (data.getType() == PotionType.WATER) {
        if (input == Material.FERMENTED_SPIDER_EYE) {
            potion.setBasePotionData(new PotionData(PotionType.WEAKNESS, false, false));
            return new ItemStack(potionType);
        }
        else if (input == Material.NETHER_WART) {
            potion.setBasePotionData(new PotionData(PotionType.AWKWARD, false, false));
            return new ItemStack(potionType);
        }
        else if (potionType == Material.POTION && input == Material.GUNPOWDER) {
            return new ItemStack(Material.SPLASH_POTION);
        }
        else if (potionType == Material.SPLASH_POTION && input == Material.DRAGON_BREATH) {
            return new ItemStack(Material.LINGERING_POTION);
        }
        else {
            return null;
        }

    }
    else if (input == Material.FERMENTED_SPIDER_EYE) {
        potion.setBasePotionData(new PotionData(fermentations.get(data.getType()), false, false));
        return new ItemStack(potionType);
    }
    else if (input == Material.REDSTONE) {
        potion.setBasePotionData(new PotionData(data.getType(), true, data.isUpgraded()));
        return new ItemStack(potionType);
    }
    else if (input == Material.GLOWSTONE_DUST) {
        potion.setBasePotionData(new PotionData(data.getType(), data.isExtended(), true));
        return new ItemStack(potionType);
    }
    else if (data.getType() == PotionType.AWKWARD && potionRecipes.containsKey(input)) {
        potion.setBasePotionData(new PotionData(potionRecipes.get(input), false, false));
        return new ItemStack(potionType);
    }
    else {
        return null;
    }
}