Search in sources :

Example 11 with CompatibilityUtils

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

the class DoorAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Block targetBlock = context.getTargetBlock();
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    Block[] doorBlocks = compatibilityUtils.getDoorBlocks(targetBlock);
    if (doorBlocks == null) {
        return SpellResult.NO_TARGET;
    }
    for (Block doorBlock : doorBlocks) {
        if (!context.hasBuildPermission(doorBlock)) {
            return SpellResult.INSUFFICIENT_PERMISSION;
        }
        if (!context.isDestructible(doorBlock)) {
            return SpellResult.NO_TARGET;
        }
    }
    if (!compatibilityUtils.checkDoorAction(doorBlocks, actionType)) {
        return SpellResult.NO_TARGET;
    }
    for (Block doorBlock : doorBlocks) {
        context.registerForUndo(doorBlock);
    }
    if (!CompatibilityLib.getCompatibilityUtils().performDoorAction(doorBlocks, actionType)) {
        return SpellResult.NO_TARGET;
    }
    context.setTargetLocation(doorBlocks[0].getLocation());
    return SpellResult.CAST;
}
Also used : Block(org.bukkit.block.Block) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)

Example 12 with CompatibilityUtils

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

the class Wand method getEnchantments.

@Override
@Nonnull
public Map<Enchantment, Integer> getEnchantments() {
    Map<Enchantment, Integer> enchantMap = new HashMap<>();
    ConfigurationSection enchantConfig = getConfigurationSection("enchantments");
    if (enchantConfig != null) {
        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
        Collection<String> enchantKeys = enchantConfig.getKeys(false);
        for (String enchantKey : enchantKeys) {
            try {
                Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantKey);
                if (enchantment == null) {
                    controller.getLogger().warning("Invalid enchantment in wand " + getTemplateKey() + ": " + enchantKey);
                } else {
                    enchantMap.put(enchantment, enchantConfig.getInt(enchantKey));
                }
            } catch (Exception ex) {
                controller.getLogger().log(Level.SEVERE, "Could not add enchantment: " + enchantKey + " to wand " + getTemplateKey(), ex);
            }
        }
    }
    return enchantMap;
}
Also used : HashMap(java.util.HashMap) CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nonnull(javax.annotation.Nonnull)

Example 13 with CompatibilityUtils

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

the class Wand method addEnchantments.

@Override
public boolean addEnchantments(Map<Enchantment, Integer> enchants) {
    if (enchants == null || item == null) {
        return false;
    }
    CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
    List<String> enchantmentsAllowed = getStringList("allowed_enchantments");
    Set<Enchantment> allowed = null;
    if (enchantmentsAllowed != null && !enchantmentsAllowed.isEmpty()) {
        allowed = new HashSet<>();
        for (String enchantmentKey : enchantmentsAllowed) {
            Enchantment enchantment = compatibilityUtils.getEnchantmentByKey(enchantmentKey);
            if (enchantment != null) {
                allowed.add(enchantment);
            }
        }
    }
    ConfigurationSection enchantments = ConfigurationUtils.newSection(configuration);
    for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
        Enchantment enchantment = entry.getKey();
        if (allowed != null && !allowed.contains(enchantment))
            continue;
        enchantments.set(compatibilityUtils.getEnchantmentKey(enchantment), entry.getValue());
    }
    if (enchantments.getKeys(false).isEmpty()) {
        return false;
    }
    if (CompatibilityLib.getInventoryUtils().addEnchantments(item, enchantments)) {
        enchantments = ConfigurationUtils.newSection(configuration);
        Map<Enchantment, Integer> newEnchants = item.getItemMeta().getEnchants();
        for (Map.Entry<Enchantment, Integer> entry : newEnchants.entrySet()) {
            enchantments.set(compatibilityUtils.getEnchantmentKey(entry.getKey()), entry.getValue());
        }
        setProperty("enchantments", enchantments);
        saveState();
        findAndUpdateLore();
        return true;
    }
    return false;
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) Map(java.util.Map) HashMap(java.util.HashMap) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 14 with CompatibilityUtils

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

the class Wand method setEnchantments.

@Override
public void setEnchantments(Map<Enchantment, Integer> enchants) {
    if (enchants == null) {
        setProperty("enchantments", null);
        if (item != null) {
            ItemMeta meta = item.getItemMeta();
            if (meta != null) {
                meta.getEnchants().clear();
                item.setItemMeta(meta);
            }
        }
    } else {
        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
        ConfigurationSection enchantments = ConfigurationUtils.newSection(configuration);
        for (Map.Entry<Enchantment, Integer> entry : enchants.entrySet()) {
            enchantments.set(compatibilityUtils.getEnchantmentKey(entry.getKey()), entry.getValue());
        }
        setProperty("enchantments", enchantments);
        if (item != null) {
            CompatibilityLib.getInventoryUtils().applyEnchantments(item, enchantments);
        }
        saveState();
        findAndUpdateLore();
    }
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils) Enchantment(org.bukkit.enchantments.Enchantment) Map(java.util.Map) HashMap(java.util.HashMap) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 15 with CompatibilityUtils

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

the class MagicWarp method checkMarker.

public void checkMarker(MagicController controller) {
    if (markerIcon != null) {
        CompatibilityUtils compatibilityUtils = CompatibilityLib.getCompatibilityUtils();
        String cleanName = ChatColor.stripColor(compatibilityUtils.translateColors(getName()));
        String cleanDescription = description;
        if (cleanDescription != null) {
            cleanDescription = ChatColor.stripColor(compatibilityUtils.translateColors(cleanDescription));
        }
        controller.addMarker("warp-" + key, markerIcon, getMarkerSet(), cleanName, getLocation(), cleanDescription);
    } else {
        removeMarker(controller);
    }
}
Also used : CompatibilityUtils(com.elmakers.mine.bukkit.utility.platform.CompatibilityUtils)

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