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

The following examples show how to use org.bukkit.inventory.meta.PotionMeta#addCustomEffect() . 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: ChildrenLeftUnattended.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private void giveTeamReward(Player player){
    Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF);
    wolf.setTamed(true);
    wolf.setOwner(player);
    wolf.setAdult();

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta meta = (PotionMeta) potion.getItemMeta();
    meta.setMainEffect(PotionEffectType.SPEED);
    PotionEffect potionEffect = new PotionEffect(PotionEffectType.SPEED, 8*60*20, 0);
    meta.addCustomEffect(potionEffect, true);

    meta.setDisplayName(ChatColor.WHITE + "Potion of Swiftness");

    potion.setItemMeta(meta);

    player.getWorld().dropItem(player.getLocation(), potion);
}
 
Example 2
Source File: JsonItemUtils.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
private static ItemMeta parseCustomPotionEffects(ItemMeta meta, JsonArray jsonArray) throws ParseException{
    if (meta instanceof PotionMeta){
        PotionMeta potionMeta = (PotionMeta) meta;

        for (JsonElement jsonElement : jsonArray){
            JsonObject effect = jsonElement.getAsJsonObject();
            potionMeta.addCustomEffect(parsePotionEffect(effect), true);
        }

        return potionMeta;
    }else{
        return VersionUtils.getVersionUtils().applySuspiciousStewEffects(meta, jsonArray);
    }
}
 
Example 3
Source File: CustomPotion.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public CustomPotion(String name, int durability, String[] lore, PotionEffect effect) {
	super(Material.POTION, name, (ReflectionUtils.getVersion().startsWith("v1_8_")) ? durability: 0, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	if (ReflectionUtils.getVersion().startsWith("v1_8_")) meta.setMainEffect(PotionEffectType.SATURATION);
	else meta.setMainEffect(effect.getType());
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
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: CustomPotion.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public CustomPotion(String name, Color color, PotionEffect effect, String... lore) {
	super(Material.POTION, name, lore);
	PotionMeta meta = (PotionMeta) getItemMeta();
	meta.setColor(color);
	meta.addCustomEffect(effect, true);
	setItemMeta(meta);
}
 
Example 6
Source File: ItemStackParser.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void parsePotionEffects() {
  PotionMeta customPotionMeta = (PotionMeta) this.finalStack.getItemMeta();
  for (Object potionEffect : (List<Object>) this.linkedSection.get("effects")) {
    LinkedHashMap<String, Object> potionEffectSection =
        (LinkedHashMap<String, Object>) potionEffect;

    if (!potionEffectSection.containsKey("type")) {
      continue;
    }

    PotionEffectType potionEffectType = null;
    int duration = 1;
    int amplifier = 0;

    potionEffectType =
        PotionEffectType.getByName(potionEffectSection.get("type").toString().toUpperCase());

    if (potionEffectSection.containsKey("duration")) {
      duration = Integer.parseInt(potionEffectSection.get("duration").toString()) * 20;
    }

    if (potionEffectSection.containsKey("amplifier")) {
      amplifier = Integer.parseInt(potionEffectSection.get("amplifier").toString()) - 1;
    }

    if (potionEffectType == null) {
      continue;
    }

    customPotionMeta.addCustomEffect(new PotionEffect(potionEffectType, duration, amplifier),
        true);
  }

  this.finalStack.setItemMeta(customPotionMeta);
}