diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f5e5223..0bdb747ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ * Fixed #2450 * Fixed Steel Thrusters being used to milk cows * Fixed #2424 +* Fixed #2468 ## Release Candidate 16 (07 Sep 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16 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 023a8df4c..00fc2b18f 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 @@ -39,6 +39,7 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; * and {@link BlockBreakEvent}. * * @author TheBusyBiscuit + * @author Linox * * @see BlockPlaceHandler * @see BlockBreakHandler @@ -51,17 +52,22 @@ public class BlockListener implements Listener { plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onBlockPlace(BlockPlaceEvent e) { + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPlaceExisting(BlockPlaceEvent e) { + // This prevents Players from placing a block where another block already exists + // While this can cause ghost blocks it also prevents them from replacing grass + // or saplings etc... if (BlockStorage.hasBlockInfo(e.getBlock())) { e.setCancelled(true); - return; } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent e) { ItemStack item = e.getItemInHand(); - SlimefunItem sfItem = SlimefunItem.getByItem(item); - if (sfItem != null && Slimefun.isEnabled(e.getPlayer(), sfItem, true) && !(sfItem instanceof NotPlaceable)) { + + if (sfItem != null && !(sfItem instanceof NotPlaceable) && Slimefun.isEnabled(e.getPlayer(), sfItem, true)) { if (!Slimefun.hasUnlocked(e.getPlayer(), sfItem, true)) { e.setCancelled(true); } else { @@ -75,7 +81,7 @@ public class BlockListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock()); @@ -94,6 +100,7 @@ public class BlockListener implements Listener { dropItems(e, drops); } + @ParametersAreNonnullByDefault private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List drops) { SlimefunItem tool = SlimefunItem.getByItem(item); @@ -106,6 +113,7 @@ public class BlockListener implements Listener { } } + @ParametersAreNonnullByDefault private void callBlockHandler(BlockBreakEvent e, ItemStack item, int fortune, List drops) { SlimefunItem sfItem = BlockStorage.check(e.getBlock()); @@ -183,16 +191,19 @@ public class BlockListener implements Listener { } private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) { - int fortune = 1; + int amount = 1; - if (item != null && item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) { - Random random = ThreadLocalRandom.current(); + if (item != null) { int fortuneLevel = item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS); - fortune = Math.max(1, random.nextInt(fortuneLevel + 2) - 1); - fortune = (b.getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1); + if (fortuneLevel > 0 && !item.containsEnchantment(Enchantment.SILK_TOUCH)) { + Random random = ThreadLocalRandom.current(); + + amount = Math.max(1, random.nextInt(fortuneLevel + 2) - 1); + amount = (b.getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (amount + 1); + } } - return fortune; + return amount; } }