From fd4cec39c44fe92eaf96fe5359e12ddf7c801f9e Mon Sep 17 00:00:00 2001 From: Traks <58818927+traksag@users.noreply.github.com> Date: Tue, 3 Aug 2021 21:07:02 +0200 Subject: [PATCH] Fix sponge absorbing water across plot borders (#3191) * Fix sponge absorbing water across plot borders * Shorten for-loops by using removeIf * Use 'Location' instead of 'var' Co-authored-by: NotMyFault --- .../bukkit/listener/BlockEventListener.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java index 196c60c0b..cd2fec2b8 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -101,6 +101,7 @@ import org.bukkit.event.block.BlockSpreadEvent; import org.bukkit.event.block.CauldronLevelChangeEvent; import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.block.LeavesDecayEvent; +import org.bukkit.event.block.SpongeAbsorbEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.material.Directional; import org.bukkit.projectiles.BlockProjectileSource; @@ -1183,4 +1184,29 @@ public class BlockEventListener implements Listener { } + @EventHandler(ignoreCancelled = true) + public void onSpongeAbsorb(SpongeAbsorbEvent event) { + Block sponge = event.getBlock(); + Location location = BukkitUtil.adapt(sponge.getLocation()); + PlotArea area = location.getPlotArea(); + List blocks = event.getBlocks(); + if (area == null) { + blocks.removeIf(block -> BukkitUtil.adapt(block.getLocation()).isPlotArea()); + } else { + Plot origin = area.getOwnedPlot(location); + blocks.removeIf(block -> { + Location blockLocation = BukkitUtil.adapt(block.getLocation()); + if (!area.contains(blockLocation.getX(), blockLocation.getZ())) { + return true; + } + Plot plot = area.getOwnedPlot(blockLocation); + return !Objects.equals(plot, origin); + }); + } + if (blocks.isEmpty()) { + // Cancel event so the sponge block doesn't turn into a wet sponge + // if no water is being absorbed + event.setCancelled(true); + } + } }