From a878521e981c49abd4e88c1b27e13f54ca50599b Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 10 Dec 2020 12:50:59 -0600 Subject: [PATCH] Redid how infinity works. --- .../listeners/BlockListeners.java | 14 ++++++++++++++ .../listeners/InteractListeners.java | 9 +-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java b/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java index 3e93b6c..0b187e2 100644 --- a/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/ultimaterepairing/listeners/BlockListeners.java @@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; /** @@ -46,4 +47,17 @@ public class BlockListeners implements Listener { anvil.setHologram(false); plugin.getAnvilManager().removeAnvil(event.getBlock().getLocation()); } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockDamage(BlockDamageEvent event) { + String loc = Methods.serializeLocation(event.getBlock()); + if (!event.getBlock().getType().name().contains("ANVIL") && !plugin.getConfig().contains("data.anvil." + loc)) + return; + + UAnvil anvil = plugin.getAnvilManager().getAnvil(event.getBlock()); + if (anvil.isInfinity()) + event.setCancelled(true); + } + + } \ No newline at end of file diff --git a/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java b/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java index 29000b8..9ed6e7e 100644 --- a/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java +++ b/src/main/java/com/songoda/ultimaterepairing/listeners/InteractListeners.java @@ -33,7 +33,6 @@ public class InteractListeners implements Listener { @EventHandler public void onAnvilClick(PlayerInteractEvent event) { boolean ourRepair = false; - boolean vanillaRepair = false; Player player = event.getPlayer(); Block block = event.getClickedBlock(); if (block == null) return; @@ -63,10 +62,7 @@ public class InteractListeners implements Listener { return; } ourRepair = true; - } else if (rightClick) { - // allowing normal repair - vanillaRepair = true; - } else if (!player.isSneaking()) { + } else if (!rightClick && !player.isSneaking()) { // that's us! ourRepair = true; } @@ -74,9 +70,6 @@ public class InteractListeners implements Listener { if (ourRepair) { RepairGui.newGui(player, anvil1.getLocation()); event.setCancelled(true); - } else if (vanillaRepair && anvil1.isInfinity()) { - player.openInventory(Bukkit.createInventory(null, InventoryType.ANVIL, ChatColor.DARK_GRAY + "Repair & Name")); - event.setCancelled(true); } } } \ No newline at end of file