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, ..?).
This commit is contained in:
Pim van der Loos 2020-11-24 12:39:06 +01:00
parent 9cb58d885d
commit ebb6a9ce82
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8
3 changed files with 15 additions and 10 deletions

View File

@ -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())

View File

@ -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;

View File

@ -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)