Search in sources :

Example 31 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project EliteMobs by MagmaGuy.

the class EliteDropsHandler method superDropParser.

public void superDropParser() {
    List<String> lootCount = lootCounter();
    for (String lootEntry : lootCount) {
        int itemPower = 0;
        StringBuilder path = new StringBuilder();
        path.append(lootEntry);
        String previousPath = path.toString();
        String itemType = itemTypeHandler(previousPath);
        itemPower += itemTypePower(Material.getMaterial(itemType));
        Bukkit.getLogger().info("Adding: " + previousPath);
        String itemName = itemNameHandler(previousPath);
        List itemLore = itemLoreHandler(previousPath);
        List itemEnchantments = itemEnchantmentHandler(previousPath);
        List potionEffects = itemPotionEffectHandler(previousPath);
        ItemStack itemStack = new ItemStack(Material.getMaterial(itemType), 1);
        ItemMeta itemMeta = itemStack.getItemMeta();
        itemMeta.setDisplayName(itemName);
        itemMeta.setLore(itemLore);
        if (itemEnchantments != null) {
            for (Object object : itemEnchantments) {
                String string = object.toString();
                String[] parsedString = string.split(",");
                String enchantmentName = parsedString[0];
                Enchantment enchantmentType = Enchantment.getByName(enchantmentName);
                int enchantmentLevel = Integer.parseInt(parsedString[1]);
                itemPower += enchantmentLevel;
                itemMeta.addEnchant(enchantmentType, enchantmentLevel, true);
            }
        }
        itemStack.setItemMeta(itemMeta);
        lootList.add(itemStack);
        List<PotionEffect> parsedPotionEffect = new ArrayList();
        //Add potion effects to a separate list to reduce i/o operations
        if (potionEffects != null) {
            for (Object object : potionEffects) {
                String string = object.toString();
                String[] parsedString = string.split(",");
                String potionEffectTypeString = parsedString[0];
                PotionEffectType potionEffectType = PotionEffectType.getByName(potionEffectTypeString);
                //this is a really bad way of doing things, two wrongs make a right
                if (parsedString.length % 2 != 0) {
                    getLogger().info("Your item " + itemName + " has a problematic potions effect entry.");
                }
                int potionEffectAmplifier = Integer.parseInt(parsedString[1]);
                itemPower += potionEffectAmplifier;
                PotionEffect potionEffect = new PotionEffect(potionEffectType, 40, potionEffectAmplifier);
                parsedPotionEffect.add(potionEffect);
            }
            potionEffectItemList.put(itemStack, parsedPotionEffect);
        }
        rankedItemMapCreator(itemPower, itemStack);
    }
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 32 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project CommandHelper by EngineHub.

the class BukkitMCLivingEntity method removeEffect.

@Override
public boolean removeEffect(int potionID) {
    PotionEffectType t = PotionEffectType.getById(potionID);
    boolean hasIt = false;
    for (PotionEffect pe : le.getActivePotionEffects()) {
        if (pe.getType() == t) {
            hasIt = true;
            break;
        }
    }
    le.removePotionEffect(t);
    return hasIt;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 33 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project CommandHelper by EngineHub.

the class BukkitMCPlayer method removeEffect.

@Override
public boolean removeEffect(int potionID) {
    PotionEffectType t = PotionEffectType.getById(potionID);
    boolean hasIt = false;
    for (PotionEffect pe : p.getActivePotionEffects()) {
        if (pe.getType() == t) {
            hasIt = true;
            break;
        }
    }
    p.removePotionEffect(t);
    return hasIt;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType)

Example 34 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project MagicPlugin by elBukkit.

the class ConfigurationUtils method getPotionEffectObjects.

@Nullable
public static List<PotionEffect> getPotionEffectObjects(ConfigurationSection baseConfig, String key, Logger log) {
    List<PotionEffect> potionEffects = null;
    Collection<ConfigurationSection> potionEffectList = getNodeList(baseConfig, key);
    if (potionEffectList != null) {
        potionEffects = new ArrayList<>();
        for (ConfigurationSection potionEffectSection : potionEffectList) {
            try {
                PotionEffectType effectType = PotionEffectType.getByName(potionEffectSection.getString("type").toUpperCase());
                if (effectType == null) {
                    log.log(Level.WARNING, "Invalid potion effect type: " + potionEffectSection.getString("type", "(null)"));
                    continue;
                }
                int ticks = (int) (potionEffectSection.getLong("duration", 3600000) / 50);
                ticks = potionEffectSection.getInt("ticks", ticks);
                int amplifier = potionEffectSection.getInt("amplifier", 0);
                boolean ambient = potionEffectSection.getBoolean("ambient", true);
                boolean particles = potionEffectSection.getBoolean("particles", true);
                potionEffects.add(new PotionEffect(effectType, ticks, amplifier, ambient, particles));
            } catch (Exception ex) {
                log.log(Level.WARNING, "Invalid potion effect type: " + potionEffectSection.getString("type", "(null)"), ex);
            }
        }
    }
    return potionEffects;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 35 with PotionEffectType

use of org.bukkit.potion.PotionEffectType in project MagicPlugin by elBukkit.

the class BaseSpell method getPotionEffects.

public static Collection<PotionEffect> getPotionEffects(ConfigurationSection parameters, Integer duration, boolean ambient, boolean particles) {
    List<PotionEffect> effects = new ArrayList<>();
    PotionEffectType[] effectTypes = PotionEffectType.values();
    for (PotionEffectType effectType : effectTypes) {
        // Why is there a null entry in this list? Maybe a 1.7 bug?
        if (effectType == null)
            continue;
        String parameterName = "effect_" + effectType.getName().toLowerCase();
        if (parameters.contains(parameterName)) {
            String value = parameters.getString(parameterName);
            int ticks = 10;
            int power = 1;
            try {
                if (value.contains(",")) {
                    String[] pieces = StringUtils.split(value, ',');
                    ticks = (int) Float.parseFloat(pieces[0]);
                    power = (int) Float.parseFloat(pieces[1]);
                } else {
                    power = (int) Float.parseFloat(value);
                    if (duration != null) {
                        ticks = duration / 50;
                    }
                }
            } catch (Exception ex) {
                Bukkit.getLogger().warning("Error parsing potion effect for " + effectType + ": " + value);
            }
            PotionEffect effect = new PotionEffect(effectType, ticks, power, ambient, particles);
            effects.add(effect);
        }
    }
    return effects;
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) ArrayList(java.util.ArrayList)

Aggregations

PotionEffectType (org.bukkit.potion.PotionEffectType)54 PotionEffect (org.bukkit.potion.PotionEffect)41 ArrayList (java.util.ArrayList)12 Player (org.bukkit.entity.Player)8 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)6 HashMap (java.util.HashMap)6 ItemStack (org.bukkit.inventory.ItemStack)6 Map (java.util.Map)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 PotionType (org.bukkit.potion.PotionType)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)4 Material (org.bukkit.Material)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 EntityTag (com.denizenscript.denizen.objects.EntityTag)3 File (java.io.File)3 IOException (java.io.IOException)3 List (java.util.List)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 Entity (org.bukkit.entity.Entity)3