Search in sources :

Example 1 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class GrowEntityAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (controller.isElemental(targetEntity)) {
        double elementalSize = controller.getElementalScale(targetEntity);
        elementalSize *= 1.2;
        controller.setElementalScale(targetEntity, elementalSize);
        return SpellResult.CAST;
    }
    if (!(targetEntity instanceof LivingEntity))
        return SpellResult.NO_TARGET;
    LivingEntity li = (LivingEntity) targetEntity;
    EntityType replaceType = null;
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    if (li instanceof Ageable && !((Ageable) li).isAdult() && !(li instanceof Player)) {
        context.registerModified(li);
        ((Ageable) li).setAdult();
    } else if (li instanceof Zombie) {
        Zombie zombie = (Zombie) li;
        if (compatibilityUtils.isAdult(zombie)) {
            replaceType = EntityType.GIANT;
        } else {
            context.registerModified(li);
            compatibilityUtils.setAdult((Zombie) li);
        }
    } else if (li instanceof Slime) {
        context.registerModified(li);
        Slime slime = (Slime) li;
        slime.setSize(slime.getSize() + 1);
    } else if (li instanceof Skeleton && skeletons) {
        try {
            replaceType = EntityType.valueOf("WITHER_SKELETON");
        } catch (Exception ex) {
            return SpellResult.NO_TARGET;
        }
    } else if (li.getType().name().equals("PHANTOM")) {
        int size = compatibilityUtils.getPhantomSize(li);
        compatibilityUtils.setPhantomSize(li, size + 1);
    } else {
        return SpellResult.NO_TARGET;
    }
    if (replaceType != null) {
        UndoList spawnedList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(li);
        context.registerModified(li);
        Entity replacement = controller.replaceMob(li, new EntityData(controller, replaceType), true, CreatureSpawnEvent.SpawnReason.CUSTOM);
        if (replacement == null) {
            return SpellResult.FAIL;
        }
        context.registerForUndo(replacement);
        if (spawnedList != null) {
            spawnedList.add(replacement);
        }
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Zombie(org.bukkit.entity.Zombie) EntityData(com.elmakers.mine.bukkit.entity.EntityData) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Ageable(org.bukkit.entity.Ageable) Slime(org.bukkit.entity.Slime) LivingEntity(org.bukkit.entity.LivingEntity) EntityType(org.bukkit.entity.EntityType) MageController(com.elmakers.mine.bukkit.api.magic.MageController) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Skeleton(org.bukkit.entity.Skeleton)

Example 2 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class CheckInventoryAction method parseEnchantmentList.

@Nullable
private Collection<Enchantment> parseEnchantmentList(CastContext context, ConfigurationSection parameters, String key) {
    Collection<Enchantment> enchantments = null;
    List<String> keys = parameters.getStringList(key);
    if (keys != null && !keys.isEmpty()) {
        enchantments = new ArrayList<>();
        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
        for (String enchantmentKey : keys) {
            Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantmentKey);
            if (enchantment != null) {
                enchantments.add(enchantment);
            } else {
                context.getLogger().warning("Invalid enchantment in CheckInventory action " + key + ": " + enchantmentKey);
            }
        }
    }
    return enchantments;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) Nullable(javax.annotation.Nullable)

Example 3 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class InventoryUtilsBase method addEnchantments.

@Override
public boolean addEnchantments(ItemStack item, ConfigurationSection enchantConfig) {
    if (item == null)
        return false;
    ItemMeta meta = item.getItemMeta();
    if (meta == null)
        return false;
    boolean addedAny = false;
    if (enchantConfig != null) {
        CompatibilityUtils compatibilityUtils = platform.getCompatibilityUtils();
        Collection<String> enchantKeys = enchantConfig.getKeys(false);
        for (String enchantKey : enchantKeys) {
            try {
                Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
                if (enchantment == null) {
                    platform.getLogger().warning("Invalid enchantment: " + enchantKey);
                    continue;
                }
                int level = enchantConfig.getInt(enchantKey);
                if (meta.getEnchantLevel(enchantment) >= level)
                    continue;
                if (!meta.hasEnchant(enchantment) && meta.hasConflictingEnchant(enchantment))
                    continue;
                if (meta.addEnchant(enchantment, level, false)) {
                    addedAny = true;
                }
            } catch (Exception ex) {
                platform.getLogger().log(Level.SEVERE, "Error adding enchantment to item " + item.getType() + ": " + enchantKey, ex);
            }
        }
    }
    if (addedAny) {
        item.setItemMeta(meta);
    }
    return addedAny;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) MalformedURLException(java.net.MalformedURLException)

Example 4 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class InventoryUtilsBase method applyEnchantments.

@Override
public void applyEnchantments(ItemStack item, ConfigurationSection enchantConfig) {
    if (item == null)
        return;
    Set<Enchantment> keep = null;
    if (enchantConfig != null) {
        keep = new HashSet<>();
        CompatibilityUtils compatibilityUtils = platform.getCompatibilityUtils();
        Collection<String> enchantKeys = enchantConfig.getKeys(false);
        for (String enchantKey : enchantKeys) {
            try {
                Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
                if (enchantment == null) {
                    platform.getLogger().warning("Invalid enchantment: " + enchantKey);
                    continue;
                }
                item.addUnsafeEnchantment(enchantment, enchantConfig.getInt(enchantKey));
                keep.add(enchantment);
            } catch (Exception ex) {
                platform.getLogger().log(Level.SEVERE, "Error adding enchantment to item " + item.getType() + ": " + enchantKey, ex);
            }
        }
    }
    Collection<Enchantment> existing = new ArrayList<>(item.getEnchantments().keySet());
    for (Enchantment enchantment : existing) {
        if (keep == null || !keep.contains(enchantment)) {
            item.removeEnchantment(enchantment);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) MalformedURLException(java.net.MalformedURLException)

Example 5 with CompatibilityUtils

use of com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils in project MagicPlugin by elBukkit.

the class EntityItemFrameData method canCycle.

@Override
public boolean canCycle(Entity entity) {
    if (!(entity instanceof ItemFrame)) {
        return false;
    }
    ItemFrame itemFrame = (ItemFrame) entity;
    ItemStack frameItem = itemFrame.getItem();
    CompatibilityUtils compatibilityUtils = PlatformInterpreter.getPlatform().getCompatibilityUtils();
    if (frameItem == null || !compatibilityUtils.isFilledMap(frameItem.getType())) {
        return false;
    }
    return true;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

CompatibilityUtils (com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)18 Enchantment (org.bukkit.enchantments.Enchantment)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)4 Entity (org.bukkit.entity.Entity)4 ItemMeta (org.bukkit.inventory.meta.ItemMeta)4 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 HashMap (java.util.HashMap)3 Block (org.bukkit.block.Block)3 LivingEntity (org.bukkit.entity.LivingEntity)3 EntityData (com.elmakers.mine.bukkit.entity.EntityData)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 Material (org.bukkit.Material)2 Ageable (org.bukkit.entity.Ageable)2 EntityType (org.bukkit.entity.EntityType)2 Player (org.bukkit.entity.Player)2 Slime (org.bukkit.entity.Slime)2 Zombie (org.bukkit.entity.Zombie)2