Java Code Examples for org.bukkit.enchantments.Enchantment#equals()

The following examples show how to use org.bukkit.enchantments.Enchantment#equals() . 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: ScalableItemConstructor.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
private static HashMap<Enchantment, Integer> updateDynamicEnchantments(HashMap<Enchantment, Integer> enchantmentsList, int itemTier) {

        if (enchantmentsList.containsKey(Enchantment.PROTECTION_ENVIRONMENTAL) &&
                enchantmentsList.get(Enchantment.PROTECTION_ENVIRONMENTAL) >
                        ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER))
            itemTier = ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER);

        if (enchantmentsList.containsKey(Enchantment.DAMAGE_ALL) &&
                enchantmentsList.get(Enchantment.DAMAGE_ALL) >
                        ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER))
            itemTier = ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER);

        if (enchantmentsList.containsKey(Enchantment.ARROW_DAMAGE) &&
                enchantmentsList.get(Enchantment.ARROW_DAMAGE) >
                        ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER))
            itemTier = ConfigValues.itemsDropSettingsConfig.getInt(ItemsDropSettingsConfig.MAXIMUM_LOOT_TIER);

        HashMap<Enchantment, Integer> newEnchantmentList = new HashMap<>();
        HashMap<Enchantment, Integer> secondaryEnchantmentList = new HashMap<>();

        /*
        Small limitation of this system, it doesn't take into account the material tier and just defaults to assume it's
        diamond (hence the -1 enchantment).
        It's such a small thing that I don't feel it's worth the hassle of adjusting it.
         */
        for (Enchantment enchantment : enchantmentsList.keySet())
            if (enchantment.equals(Enchantment.DAMAGE_ALL) ||
                    enchantment.equals(Enchantment.ARROW_DAMAGE) ||
                    enchantment.equals(Enchantment.PROTECTION_ENVIRONMENTAL))
                newEnchantmentList.put(enchantment, itemTier - 1);
            else
                secondaryEnchantmentList.put(enchantment, enchantmentsList.get(enchantment));

        if (itemTier < 2) return newEnchantmentList;

        int secondaryEnchantmentPool = ThreadLocalRandom.current().nextInt((int) Math.ceil((double) itemTier / 2));

        for (int i = 0; i < secondaryEnchantmentPool; i++) {

            if (secondaryEnchantmentList.isEmpty()) break;

            int randomIndex = ThreadLocalRandom.current().nextInt(secondaryEnchantmentList.size());
            Enchantment randomizedEnchantment = (Enchantment) secondaryEnchantmentList.keySet().toArray()[randomIndex];

            if (newEnchantmentList.isEmpty() || !newEnchantmentList.containsKey(randomizedEnchantment)) {
                newEnchantmentList.put(randomizedEnchantment, 1);
            } else {
                int newEnchantmentLevel = newEnchantmentList.get(randomizedEnchantment) + 1;
                newEnchantmentList.put(randomizedEnchantment, newEnchantmentLevel);
            }

            int leftoverPoolEnchantment = secondaryEnchantmentList.get(randomizedEnchantment) - 1;
            if (leftoverPoolEnchantment <= 0)
                secondaryEnchantmentList.remove(randomizedEnchantment);
            else
                secondaryEnchantmentList.put(randomizedEnchantment, leftoverPoolEnchantment);

        }


        return newEnchantmentList;

    }
 
Example 2
Source File: ItemTierFinder.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
private static int findMainEnchantment(HashMap<Enchantment, Integer> enchantmentMap, Enchantment enchantment) {

        int enchantments = 0;

        if (!enchantmentMap.isEmpty())
            for (Enchantment currentEnchantment : enchantmentMap.keySet())
                if (currentEnchantment.equals(enchantment))
                    enchantments += enchantmentMap.get(currentEnchantment);

        return enchantments;

    }