Search in sources :

Example 11 with Enchantment

use of org.bukkit.enchantments.Enchantment in project MyPet by xXKeyleXx.

the class ItemStackComparator method compareEnchantments.

public static boolean compareEnchantments(ItemStack i1, ItemStack i2) {
    if (i1 == null || i2 == null) {
        return false;
    }
    if (i1.getEnchantments().size() == i2.getEnchantments().size()) {
        Map<Enchantment, Integer> e1 = i1.getEnchantments();
        Map<Enchantment, Integer> e2 = i2.getEnchantments();
        Enchantment[] e1l = new Enchantment[e1.size()];
        int i = 0;
        for (Enchantment enchantment : e1.keySet()) {
            e1l[i++] = enchantment;
        }
        i = 0;
        for (Enchantment enchantment : e2.keySet()) {
            if (e1l[i].getId() != enchantment.getId()) {
                // MyPetLogger.write("enchantment: " + e1l[i].getId() + "<->" + enchantment.getId());
                return false;
            } else if (!e1.get(e1l[i]).equals(e2.get(enchantment))) {
                // MyPetLogger.write("level: " + e1.get(e1l[i]) + "<->" + e2.get(enchantment));
                return false;
            }
            i++;
        }
        return true;
    }
    // MyPetLogger.write("size: " + i1.getEnchantments().size() + "<->" + i2.getEnchantments().size());
    return false;
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment)

Example 12 with Enchantment

use of org.bukkit.enchantments.Enchantment in project MyPet by xXKeyleXx.

the class ItemStackComparator method compareEnchantments.

public static boolean compareEnchantments(ItemStack i1, ItemStack i2) {
    if (i1 == null || i2 == null) {
        return false;
    }
    if (i1.getEnchantments().size() == i2.getEnchantments().size()) {
        Map<Enchantment, Integer> e1 = i1.getEnchantments();
        Map<Enchantment, Integer> e2 = i2.getEnchantments();
        Enchantment[] e1l = new Enchantment[e1.size()];
        int i = 0;
        for (Enchantment enchantment : e1.keySet()) {
            e1l[i++] = enchantment;
        }
        i = 0;
        for (Enchantment enchantment : e2.keySet()) {
            if (e1l[i].getId() != enchantment.getId()) {
                // MyPetLogger.write("enchantment: " + e1l[i].getId() + "<->" + enchantment.getId());
                return false;
            } else if (!e1.get(e1l[i]).equals(e2.get(enchantment))) {
                // MyPetLogger.write("level: " + e1.get(e1l[i]) + "<->" + e2.get(enchantment));
                return false;
            }
            i++;
        }
        return true;
    }
    // MyPetLogger.write("size: " + i1.getEnchantments().size() + "<->" + i2.getEnchantments().size());
    return false;
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment)

Example 13 with Enchantment

use of org.bukkit.enchantments.Enchantment in project MyPet by xXKeyleXx.

the class ItemStackComparator method compareEnchantments.

public static boolean compareEnchantments(ItemStack i1, ItemStack i2) {
    if (i1 == null || i2 == null) {
        return false;
    }
    if (i1.getEnchantments().size() == i2.getEnchantments().size()) {
        Map<Enchantment, Integer> e1 = i1.getEnchantments();
        Map<Enchantment, Integer> e2 = i2.getEnchantments();
        Enchantment[] e1l = new Enchantment[e1.size()];
        int i = 0;
        for (Enchantment enchantment : e1.keySet()) {
            e1l[i++] = enchantment;
        }
        i = 0;
        for (Enchantment enchantment : e2.keySet()) {
            if (e1l[i].getId() != enchantment.getId()) {
                // MyPetLogger.write("enchantment: " + e1l[i].getId() + "<->" + enchantment.getId());
                return false;
            } else if (!e1.get(e1l[i]).equals(e2.get(enchantment))) {
                // MyPetLogger.write("level: " + e1.get(e1l[i]) + "<->" + e2.get(enchantment));
                return false;
            }
            i++;
        }
        return true;
    }
    // MyPetLogger.write("size: " + i1.getEnchantments().size() + "<->" + i2.getEnchantments().size());
    return false;
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment)

Example 14 with Enchantment

use of org.bukkit.enchantments.Enchantment in project MyPet by xXKeyleXx.

the class ItemStackComparator method compareEnchantments.

public static boolean compareEnchantments(ItemStack i1, ItemStack i2) {
    if (i1 == null || i2 == null) {
        return false;
    }
    if (i1.getEnchantments().size() == i2.getEnchantments().size()) {
        Map<Enchantment, Integer> e1 = i1.getEnchantments();
        Map<Enchantment, Integer> e2 = i2.getEnchantments();
        Enchantment[] e1l = new Enchantment[e1.size()];
        int i = 0;
        for (Enchantment enchantment : e1.keySet()) {
            e1l[i++] = enchantment;
        }
        i = 0;
        for (Enchantment enchantment : e2.keySet()) {
            if (e1l[i].getId() != enchantment.getId()) {
                // MyPetLogger.write("enchantment: " + e1l[i].getId() + "<->" + enchantment.getId());
                return false;
            } else if (!e1.get(e1l[i]).equals(e2.get(enchantment))) {
                // MyPetLogger.write("level: " + e1.get(e1l[i]) + "<->" + e2.get(enchantment));
                return false;
            }
            i++;
        }
        return true;
    }
    // MyPetLogger.write("size: " + i1.getEnchantments().size() + "<->" + i2.getEnchantments().size());
    return false;
}
Also used : Enchantment(org.bukkit.enchantments.Enchantment)

Example 15 with Enchantment

use of org.bukkit.enchantments.Enchantment in project Essentials by drtshock.

the class EssentialsConf method getItemStack.

@Override
public ItemStack getItemStack(final String path) {
    final ItemStack stack = new ItemStack(Material.valueOf(getString(path + ".type", "AIR")), getInt(path + ".amount", 1), (short) getInt(path + ".damage", 0));
    final ConfigurationSection enchants = getConfigurationSection(path + ".enchant");
    if (enchants != null) {
        for (String enchant : enchants.getKeys(false)) {
            final Enchantment enchantment = Enchantment.getByName(enchant.toUpperCase(Locale.ENGLISH));
            if (enchantment == null) {
                continue;
            }
            final int level = getInt(path + ".enchant." + enchant, enchantment.getStartLevel());
            stack.addUnsafeEnchantment(enchantment, level);
        }
    }
    return stack;
/*
         * ,
		 * (byte)getInt(path + ".data", 0)
		 */
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

Enchantment (org.bukkit.enchantments.Enchantment)38 ItemStack (org.bukkit.inventory.ItemStack)16 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)5 ItemMeta (org.bukkit.inventory.meta.ItemMeta)5 Map (java.util.Map)4 GlowEnchantment (net.glowstone.constants.GlowEnchantment)3 Entry (java.util.Map.Entry)2 CompoundTag (net.glowstone.util.nbt.CompoundTag)2 Color (org.bukkit.Color)2 FireworkEffect (org.bukkit.FireworkEffect)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 BookMeta (org.bukkit.inventory.meta.BookMeta)2 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)2 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 PotionEffect (org.bukkit.potion.PotionEffect)2 ChargeException (com.earth2me.essentials.ChargeException)1 MetaItemStack (com.earth2me.essentials.MetaItemStack)1 Trade (com.earth2me.essentials.Trade)1 ImmutableMap (com.google.common.collect.ImmutableMap)1