From ebb6a9ce82f4d39702643a8a3924093b1c3da45f Mon Sep 17 00:00:00 2001 From: Pim van der Loos Date: Tue, 24 Nov 2020 12:39:06 +0100 Subject: [PATCH] Allow anvil usage when Smithing is enabled - The anvil can now be used for everything other than creation when smithing table usage is enabled (so repairing, enchanting, ..?). --- .../java/nl/pim16aap2/armoredElytra/ArmoredElytra.java | 10 ++++------ .../pim16aap2/armoredElytra/handlers/AnvilHandler.java | 8 ++++++-- .../armoredElytra/handlers/SmithingTableHandler.java | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index 1088186..25b0e05 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -84,12 +84,6 @@ public class ArmoredElytra extends JavaPlugin implements Listener myLogger(Level.INFO, "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!"); - final Listener creationListener = config.craftingInSmithingTable() ? - new SmithingTableHandler(this, !config.uninstallMode()) : - new AnvilHandler(this, !config.uninstallMode()); - Bukkit.getPluginManager().registerEvents(creationListener, this); - - Bukkit.getPluginManager().registerEvents(new EventHandlers(this), this); getCommand("ArmoredElytra").setExecutor(new CommandHandler(this)); @@ -105,6 +99,10 @@ public class ArmoredElytra extends JavaPlugin implements Listener else myLogger(Level.INFO, "Durability penalty for flying enabled!"); + final Listener creationListener = config.craftingInSmithingTable() ? + new SmithingTableHandler(this) : new AnvilHandler(this); + Bukkit.getPluginManager().registerEvents(creationListener, this); + // Log all allowed enchantments. myLogger(Level.INFO, ("Allowed enchantments:")); for (final String s : config.allowedEnchantments()) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/AnvilHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/AnvilHandler.java index 759f31f..1a32489 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/AnvilHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/AnvilHandler.java @@ -25,6 +25,11 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener super(plugin, creationEnabled); } + public AnvilHandler(final ArmoredElytra plugin) + { + this(plugin, true); + } + // Valid inputs: // - Elytra (armored or not) + chestplate -> Create Armored Elytra // - Elytra (armored) + enchanted book -> Enchant @@ -55,7 +60,7 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener // If the elytra is to be combined with chest armor... if (Util.isChestPlate(matTwo)) - return Action.CREATE; + return creationEnabled ? Action.CREATE : Action.NONE; ArmorTier tier = ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemOne); @@ -71,7 +76,6 @@ public class AnvilHandler extends ArmoredElytraHandler implements Listener // If the armored elytra is to be combined with another armored elytra of the // same tier... - // TODO: Should this also be disabled by "creationEnabled"? if (ArmoredElytra.getInstance().getNbtEditor().getArmorTier(itemTwo) == tier) return creationEnabled ? Action.COMBINE : Action.NONE; diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableHandler.java index 36d7bb1..b041529 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/SmithingTableHandler.java @@ -4,6 +4,7 @@ import nl.pim16aap2.armoredElytra.ArmoredElytra; import nl.pim16aap2.armoredElytra.enchantment.EnchantmentManager; import nl.pim16aap2.armoredElytra.util.ArmorTier; import nl.pim16aap2.armoredElytra.util.Util; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -18,9 +19,11 @@ import java.util.logging.Level; public class SmithingTableHandler extends ArmoredElytraHandler implements Listener { - public SmithingTableHandler(final ArmoredElytra plugin, final boolean creationEnabled) + public SmithingTableHandler(final ArmoredElytra plugin) { - super(plugin, creationEnabled); + super(plugin, true); + // Register the anvil handler with creation disabled so AEs can still be repaired and stuff. + Bukkit.getPluginManager().registerEvents(new AnvilHandler(plugin, false), plugin); } @EventHandler(ignoreCancelled = true)