diff --git a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java index 2344887486..3e5657129e 100644 --- a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java +++ b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java @@ -11,6 +11,7 @@ import org.bukkit.ExplosionResult; import org.bukkit.block.Block; import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; @@ -19,6 +20,7 @@ public class VersionedEvent { private Constructor BLOCK_EXPLODE_EVENT_CONSTRUCTOR; private Method GET_TOP_INVENTORY; + private Method GET_CLICKED_INVENTORY; public void init() { if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { @@ -29,6 +31,11 @@ public void init() { GET_TOP_INVENTORY = Class.forName("org.bukkit.inventory.InventoryView").getMethod("getTopInventory"); GET_TOP_INVENTORY.setAccessible(true); + + GET_CLICKED_INVENTORY = Class.forName("org.bukkit.event.inventory.InventoryClickEvent") + .getMethod("getClickedInventory"); + GET_CLICKED_INVENTORY.setAccessible(true); + } catch (NoSuchMethodException | ClassNotFoundException e) { Slimefun.logger().log(Level.WARNING, "无法初始化事件版本兼容模块, 部分功能可能无法正常使用", e); } @@ -62,4 +69,17 @@ public Inventory getTopInventory(InventoryEvent event) { return (Inventory) GET_TOP_INVENTORY.invoke(event.getView()); } } + + @SneakyThrows + public Inventory getClickedInventory(InventoryClickEvent event) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { + return event.getClickedInventory(); + } else { + if (GET_CLICKED_INVENTORY == null) { + throw new IllegalStateException("Unable to get clicked inventory: missing method"); + } + + return (Inventory) GET_CLICKED_INVENTORY.invoke(event); + } + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index e77a0872fc..e5c2bb5e3b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -70,10 +70,6 @@ public ToolUseHandler getItemHandler() { List blocks = findBlocks(b); - if (!StorageCacheUtils.hasBlock(b.getLocation())) { - blocks.add(b); - } - breakBlocks(e, p, tool, b, blocks, drops); } }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 1be8b78169..6a2efb809a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -236,7 +236,7 @@ public void onBlockBreak(BlockBreakEvent e) { dropItems(e, drops); // Checks for vanilla sensitive blocks everywhere - checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); + // checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java index 70304f309d..730790bb8f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java @@ -31,7 +31,7 @@ public VillagerTradingListener(@Nonnull Slimefun plugin) { @EventHandler(ignoreCancelled = true) public void onPreTrade(InventoryClickEvent e) { - Inventory clickedInventory = e.getClickedInventory(); + Inventory clickedInventory = VersionedEvent.getClickedInventory(e); Inventory topInventory = VersionedEvent.getTopInventory(e); if (clickedInventory != null && topInventory.getType() == InventoryType.MERCHANT) {