From 9e96e764b42b6fda03515eac94caecb800c7ad55 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sat, 16 Dec 2023 18:08:05 +0100 Subject: [PATCH 1/5] Added back the drops for the main item --- .../implementation/listeners/BlockListener.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 91fb9eb291..f4fe92c92b 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 @@ -15,6 +15,7 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; +import org.bukkit.block.Container; import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -174,7 +175,7 @@ public void onBlockBreak(BlockBreakEvent e) { callBlockHandler(e, item, drops, sfItem); - dropItems(e, drops); + dropItems(e, item, drops); // Checks for vanilla sensitive blocks everywhere checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); @@ -224,7 +225,7 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List } @ParametersAreNonnullByDefault - private void dropItems(BlockBreakEvent e, List drops) { + private void dropItems(BlockBreakEvent e, ItemStack item, List drops) { if (!drops.isEmpty()) { // TODO: properly support loading inventories within unit tests if (!Slimefun.instance().isUnitTest()) { @@ -237,10 +238,16 @@ private void dropItems(BlockBreakEvent e, List drops) { // Disable normal block drops e.setDropItems(false); + // Fixes #4051 + Block b = e.getBlock(); + if (BlockStorage.check(b) == null) { + b.breakNaturally(item); + } + for (ItemStack drop : drops) { // Prevent null or air from being dropped if (drop != null && drop.getType() != Material.AIR) { - e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop); + b.getWorld().dropItemNaturally(b.getLocation(), drop); } } } From 98b0840ed9396c14e45340cc1ee09f697dba6b51 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sun, 25 Feb 2024 18:55:30 +0100 Subject: [PATCH 2/5] Prevent extra BS check --- .../implementation/listeners/BlockListener.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 f4fe92c92b..38d635bbd6 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 @@ -148,7 +148,8 @@ public void onBlockBreak(BlockBreakEvent e) { } ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); - SlimefunItem sfItem = BlockStorage.check(e.getBlock()); + Block b = e.getBlock(); + SlimefunItem sfItem = BlockStorage.check(b); // If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event and return if (sfItem != null) { @@ -175,7 +176,7 @@ public void onBlockBreak(BlockBreakEvent e) { callBlockHandler(e, item, drops, sfItem); - dropItems(e, item, drops); + dropItems(e, item, b, sfItem==null, drops); // Checks for vanilla sensitive blocks everywhere checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); @@ -225,7 +226,7 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List } @ParametersAreNonnullByDefault - private void dropItems(BlockBreakEvent e, ItemStack item, List drops) { + private void dropItems(BlockBreakEvent e, ItemStack item, Block b, boolean isBlockstorageNull, List drops) { if (!drops.isEmpty()) { // TODO: properly support loading inventories within unit tests if (!Slimefun.instance().isUnitTest()) { @@ -239,8 +240,7 @@ private void dropItems(BlockBreakEvent e, ItemStack item, List drops) e.setDropItems(false); // Fixes #4051 - Block b = e.getBlock(); - if (BlockStorage.check(b) == null) { + if (isBlockstorageNull) { b.breakNaturally(item); } From 12bc7a300c8843f99fefc0462ff70f8ebaf00687 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sun, 25 Feb 2024 19:56:05 +0100 Subject: [PATCH 3/5] Unused improt, comment --- .../slimefun4/implementation/listeners/BlockListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 38d635bbd6..6d20e36c3e 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 @@ -15,7 +15,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; -import org.bukkit.block.Container; import org.bukkit.block.data.BlockData; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -244,6 +243,7 @@ private void dropItems(BlockBreakEvent e, ItemStack item, Block b, boolean isBlo b.breakNaturally(item); } + // The list only contains other drops, not those from the block itself, so we still need to handle those for (ItemStack drop : drops) { // Prevent null or air from being dropped if (drop != null && drop.getType() != Material.AIR) { From bd264b48227fffc5bc743c176d80547f3fc14897 Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sun, 25 Feb 2024 20:08:15 +0100 Subject: [PATCH 4/5] Name and stuff --- .../implementation/listeners/BlockListener.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 6d20e36c3e..741301de04 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 @@ -148,11 +148,11 @@ public void onBlockBreak(BlockBreakEvent e) { ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); Block b = e.getBlock(); - SlimefunItem sfItem = BlockStorage.check(b); + SlimefunItem sfBlock = BlockStorage.check(b); // If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event and return - if (sfItem != null) { - SlimefunBlockBreakEvent breakEvent = new SlimefunBlockBreakEvent(e.getPlayer(), item, e.getBlock(), sfItem); + if (sfBlock != null) { + SlimefunBlockBreakEvent breakEvent = new SlimefunBlockBreakEvent(e.getPlayer(), item, e.getBlock(), sfBlock); Bukkit.getPluginManager().callEvent(breakEvent); if (breakEvent.isCancelled()) { @@ -173,9 +173,9 @@ public void onBlockBreak(BlockBreakEvent e) { // TODO: merge this with the vanilla sensitive block check (when 1.18- is dropped) checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), item); - callBlockHandler(e, item, drops, sfItem); + callBlockHandler(e, item, drops, sfBlock); - dropItems(e, item, b, sfItem==null, drops); + dropItems(e, item, b, sfBlock, drops); // Checks for vanilla sensitive blocks everywhere checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); @@ -225,7 +225,7 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List } @ParametersAreNonnullByDefault - private void dropItems(BlockBreakEvent e, ItemStack item, Block b, boolean isBlockstorageNull, List drops) { + private void dropItems(BlockBreakEvent e, ItemStack item, Block b, @Nullable SlimefunItem sfBlock, List drops) { if (!drops.isEmpty()) { // TODO: properly support loading inventories within unit tests if (!Slimefun.instance().isUnitTest()) { @@ -239,7 +239,7 @@ private void dropItems(BlockBreakEvent e, ItemStack item, Block b, boolean isBlo e.setDropItems(false); // Fixes #4051 - if (isBlockstorageNull) { + if (sfBlock == null) { b.breakNaturally(item); } From 9a562967f5be453ee3c3923a9bb5caca9351cf6d Mon Sep 17 00:00:00 2001 From: Alessio Colombo Date: Sun, 25 Feb 2024 20:09:53 +0100 Subject: [PATCH 5/5] Panda and blob are annoying --- .../implementation/listeners/BlockListener.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 741301de04..cb717fd41e 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 @@ -147,8 +147,8 @@ public void onBlockBreak(BlockBreakEvent e) { } ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); - Block b = e.getBlock(); - SlimefunItem sfBlock = BlockStorage.check(b); + Block block = e.getBlock(); + SlimefunItem sfBlock = BlockStorage.check(block); // If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event and return if (sfBlock != null) { @@ -175,7 +175,7 @@ public void onBlockBreak(BlockBreakEvent e) { callBlockHandler(e, item, drops, sfBlock); - dropItems(e, item, b, sfBlock, drops); + dropItems(e, item, block, sfBlock, drops); // Checks for vanilla sensitive blocks everywhere checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); @@ -225,12 +225,12 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List } @ParametersAreNonnullByDefault - private void dropItems(BlockBreakEvent e, ItemStack item, Block b, @Nullable SlimefunItem sfBlock, List drops) { + private void dropItems(BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List drops) { if (!drops.isEmpty()) { // TODO: properly support loading inventories within unit tests if (!Slimefun.instance().isUnitTest()) { // Notify plugins like CoreProtect - Slimefun.getProtectionManager().logAction(e.getPlayer(), e.getBlock(), Interaction.BREAK_BLOCK); + Slimefun.getProtectionManager().logAction(e.getPlayer(), block, Interaction.BREAK_BLOCK); } // Fixes #2560 @@ -240,14 +240,14 @@ private void dropItems(BlockBreakEvent e, ItemStack item, Block b, @Nullable Sli // Fixes #4051 if (sfBlock == null) { - b.breakNaturally(item); + block.breakNaturally(item); } // The list only contains other drops, not those from the block itself, so we still need to handle those for (ItemStack drop : drops) { // Prevent null or air from being dropped if (drop != null && drop.getType() != Material.AIR) { - b.getWorld().dropItemNaturally(b.getLocation(), drop); + block.getWorld().dropItemNaturally(block.getLocation(), drop); } } }