From d6ea9cd02702b42ef955f19aab6e844cd7bd4161 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 4 Sep 2020 19:49:01 +0100 Subject: [PATCH] Fixed bugs from legacy target system --- .../com/willfp/ecoenchants/anvil/AnvilMerge.java | 3 ++- .../ecoenchants/display/EnchantDisplay.java | 5 +++-- .../ecoenchants/normal/Abrasion.java | 9 +++++---- .../ecoenchants/normal/Corrosive.java | 9 +++++---- .../ecoenchants/normal/Farmhand.java | 2 +- .../enchantments/util/checks/EnchantChecks.java | 16 ++++++++-------- .../listeners/EnchantingListeners.java | 4 ++-- .../ecoenchants/listeners/VillagerListeners.java | 5 ++++- .../ecoenchants/naturalloot/LootPopulator.java | 7 +++++-- 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java b/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java index becacc61..f9c60dcc 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.anvil; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.EnchantmentTarget; import com.willfp.ecoenchants.util.Pair; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -41,7 +42,7 @@ public class AnvilMerge { if(left.getEnchantments().containsKey(EcoEnchants.PERMANENCE_CURSE)) return new Pair<>(null, null); - if(!Target.Applicable.ALL.getMaterials().contains(left.getType()) || right == null || !Target.Applicable.ALL.getMaterials().contains(right.getType())) { + if(!EnchantmentTarget.ALL.contains(left.getType()) || right == null || EnchantmentTarget.ALL.contains(right.getType())) { ItemStack out = left.clone(); ItemMeta outMeta = out.getItemMeta(); outMeta.setDisplayName(name); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 0cb9c02e..fa56e7b9 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -5,6 +5,7 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.EnchantmentTarget; import com.willfp.ecoenchants.util.NumberUtils; import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; @@ -82,7 +83,7 @@ public class EnchantDisplay { public static ItemStack revertDisplay(ItemStack item) { if(item == null) return null; - if(!Target.Applicable.ALL.getMaterials().contains(item.getType())) + if(!EnchantmentTarget.ALL.contains(item.getType())) return item; ItemMeta meta = item.getItemMeta(); @@ -129,7 +130,7 @@ public class EnchantDisplay { ItemStack oldItem = item.clone(); - if(!Target.Applicable.ALL.getMaterials().contains(item.getType())) + if(!EnchantmentTarget.ALL.contains(item.getType())) return oldItem; item = revertDisplay(item); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java index a59f356e..75fd25ae 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Abrasion.java @@ -55,16 +55,17 @@ public class Abrasion extends EcoEnchant { if (armorPiece == null) continue; - if (Target.Applicable.HELMET.getMaterials().contains(armorPiece.getType())) { + + if(armorPiece.equals(victim.getInventory().getHelmet())) { ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39); } - if (Target.Applicable.CHESTPLATE.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getChestplate())) { ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38); } - if (Target.Applicable.LEGGINGS.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getLeggings())) { ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37); } - if (Target.Applicable.BOOTS.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getBoots())) { ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36); } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java index 4224f723..95af2d83 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Corrosive.java @@ -55,16 +55,17 @@ public class Corrosive extends EcoEnchant { if (armorPiece == null) continue; - if (Target.Applicable.HELMET.getMaterials().contains(armorPiece.getType())) { + + if(armorPiece.equals(victim.getInventory().getHelmet())) { ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39); } - if (Target.Applicable.CHESTPLATE.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getChestplate())) { ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38); } - if (Target.Applicable.LEGGINGS.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getLeggings())) { ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37); } - if (Target.Applicable.BOOTS.getMaterials().contains(armorPiece.getType())) { + if(armorPiece.equals(victim.getInventory().getBoots())) { ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36); } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Farmhand.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Farmhand.java index 7496842e..9c39c30a 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Farmhand.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Farmhand.java @@ -42,7 +42,7 @@ public class Farmhand extends EcoEnchant { if (!EnchantChecks.item(item, this)) return; - if (!(Target.Applicable.HOE.getMaterials().contains(item.getType()))) + if (!item.getType().toString().endsWith("_HOE")) return; if(!AntigriefManager.canBreakBlock(player, event.getClickedBlock())) return; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java index d216cbc6..89e49a54 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/checks/EnchantChecks.java @@ -89,17 +89,17 @@ public abstract class EnchantChecks { armorPoints.addAndGet(getItemLevel(itemStack, enchantment)); if(damage > 0 && isPlayer) { Player player = (Player) entity; - if (Target.Applicable.HELMET.getMaterials().contains(itemStack.getType())) { - ItemDurability.damageItem(player, player.getInventory().getHelmet(), 1, 39); + if(itemStack.equals(entity.getEquipment().getHelmet())) { + ItemDurability.damageItem(player, player.getInventory().getHelmet(), level, 39); } - if (Target.Applicable.CHESTPLATE.getMaterials().contains(itemStack.getType())) { - ItemDurability.damageItem(player, player.getInventory().getChestplate(), 1, 38); + if(itemStack.equals(entity.getEquipment().getChestplate())) { + ItemDurability.damageItem(player, player.getInventory().getChestplate(), level, 38); } - if (Target.Applicable.LEGGINGS.getMaterials().contains(itemStack.getType())) { - ItemDurability.damageItem(player, player.getInventory().getLeggings(), 1, 37); + if(itemStack.equals(entity.getEquipment().getLeggings())) { + ItemDurability.damageItem(player, player.getInventory().getLeggings(), level, 37); } - if (Target.Applicable.BOOTS.getMaterials().contains(itemStack.getType())) { - ItemDurability.damageItem(player, player.getInventory().getBoots(), 1, 36); + if(itemStack.equals(entity.getEquipment().getBoots())) { + ItemDurability.damageItem(player, player.getInventory().getBoots(), level, 36); } } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java index aaafdd58..3e5f7719 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java @@ -59,7 +59,7 @@ public class EnchantingListeners implements Listener { } double multiplier = 0.01; - if (Target.Applicable.BOOK.getMaterials().contains(item.getType())) { + if(item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) { multiplier /= ConfigManager.getConfig().getInt("enchanting-table.book-times-less-likely"); } @@ -80,7 +80,7 @@ public class EnchantingListeners implements Listener { continue; if (enchantment.getRarity().getMinimumLevel() > cost) continue; - if(enchantment.isEnabled()) + if(!enchantment.isEnabled()) continue; if (!enchantment.canGetFromTable()) continue; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java index 237918f1..c184903c 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.listeners; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.EnchantmentTarget; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Material; import org.bukkit.event.EventHandler; @@ -84,7 +85,7 @@ public class VillagerListeners implements Listener { @EventHandler public void onVillagerGainItemTrade(VillagerAcquireTradeEvent event) { - if(!Target.Applicable.ALL.getMaterials().contains(event.getRecipe().getResult().getType())) + if(!EnchantmentTarget.ALL.contains(event.getRecipe().getResult().getType())) return; if(event.getRecipe().getResult().getType().equals(Material.BOOK)) return; @@ -118,6 +119,8 @@ public class VillagerListeners implements Listener { continue; if(!enchantment.canEnchantItem(result)) continue; + if(!enchantment.isEnabled()) + continue; AtomicBoolean anyConflicts = new AtomicBoolean(false); toAdd.forEach((enchant, integer) -> { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java b/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java index bd8e837e..f0779373 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants.naturalloot; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.EnchantmentTarget; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.Chunk; import org.bukkit.Material; @@ -38,7 +39,7 @@ public class LootPopulator extends BlockPopulator { for(ItemStack item : inventory) { if(item == null) continue; - if(!Target.Applicable.ALL.getMaterials().contains(item.getType())) continue; + if(!EnchantmentTarget.ALL.contains(item.getType())) continue; if(item.getType().equals(Material.BOOK)) continue; HashMap toAdd = new HashMap<>(); @@ -47,7 +48,7 @@ public class LootPopulator extends BlockPopulator { Collections.shuffle(enchantments); // Prevent list bias towards early enchantments like telekinesis double multiplier = 0.01; - if (Target.Applicable.BOOK.getMaterials().contains(item.getType())) { + if (item.getType().equals(Material.BOOK) || item.getType().equals(Material.ENCHANTED_BOOK)) { multiplier /= ConfigManager.getConfig().getInt("loot.book-times-less-likely"); } @@ -64,6 +65,8 @@ public class LootPopulator extends BlockPopulator { continue; if(!enchantment.canEnchantItem(item)) continue; + if(!enchantment.isEnabled()) + continue; AtomicBoolean anyConflicts = new AtomicBoolean(false); toAdd.forEach((enchant, integer) -> {