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); + } + } }