From 7ee069fee5b5f0ec6b058599362715b2a151a3f3 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sat, 1 Aug 2020 00:51:21 +0200 Subject: [PATCH] Fix Sponges increasing level --- .../com/songoda/skyblock/listeners/Block.java | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/songoda/skyblock/listeners/Block.java b/src/main/java/com/songoda/skyblock/listeners/Block.java index ecad2d0f..2d97a90b 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Block.java +++ b/src/main/java/com/songoda/skyblock/listeners/Block.java @@ -336,6 +336,28 @@ public class Block implements Listener { && event.getPlayer().getItemInHand().getType() == CompatibleMaterial.ENDER_EYE.getMaterial()) return; islandLevelManager.updateLevel(island, blockLoc); + + // Sponge level dupe fix + if(ServerVersion.isServerVersionBelow(ServerVersion.V1_13) && + block.getType().equals(CompatibleMaterial.SPONGE.getBlockMaterial())) { + Bukkit.getScheduler().runTask(plugin, () -> { + if(blockLoc.getBlock().getType().equals(CompatibleMaterial.WET_SPONGE.getBlockMaterial())) { + IslandLevel level = island.getLevel(); + CompatibleMaterial material = CompatibleMaterial.SPONGE; + if (level.hasMaterial(material.name())) { + long materialAmount = level.getMaterialAmount(material.name()); + + if (materialAmount - 1 <= 0) { + level.removeMaterial(material.name()); + } else { + level.setMaterialAmount(material.name(), materialAmount - 1); + } + + islandLevelManager.updateLevel(island, blockLoc); + } + } + }); + } } @EventHandler @@ -792,7 +814,48 @@ public class Block implements Listener { return false; } - @EventHandler + @EventHandler(ignoreCancelled = true) + public void onSponge(SpongeAbsorbEvent event) { + IslandLevelManager islandLevelManager = plugin.getLevellingManager(); + IslandManager islandManager = plugin.getIslandManager(); + StackableManager stackableManager = plugin.getStackableManager(); + WorldManager worldManager = plugin.getWorldManager(); + + org.bukkit.block.Block block = event.getBlock(); + + if (worldManager.isIslandWorld(block.getWorld())) { + Location blockLocation = block.getLocation(); + + Island island = islandManager.getIslandAtLocation(blockLocation); + if (island != null) { + if (plugin.getPermissionManager().processPermission(event, island) && !event.isCancelled()) { + if (stackableManager == null || !stackableManager.isStacked(blockLocation)) { + IslandLevel level = island.getLevel(); + + CompatibleMaterial material = CompatibleMaterial.SPONGE; + if (level.hasMaterial(material.name())) { + long materialAmount = level.getMaterialAmount(material.name()); + + if (materialAmount - 1 <= 0) { + level.removeMaterial(material.name()); + } else { + level.setMaterialAmount(material.name(), materialAmount - 1); + } + + Bukkit.getScheduler().runTask(plugin, () -> islandLevelManager.updateLevel(island, blockLocation)); + } + } else { + event.setCancelled(true); + } + } + } else { + event.setCancelled(true); + } + } + + } + + @EventHandler(ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent event) { org.bukkit.block.Block block = event.getBlock(); WorldManager worldManager = plugin.getWorldManager();