From 6a57a5c36917d7421688eed923b5ce616b2b586e Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 24 Jun 2021 16:40:10 +0200 Subject: [PATCH] Fixes #3100 --- .../bukkit/listener/BlockEventListener.java | 48 +++++++++++++++++++ 1 file changed, 48 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 864a68b85..a467541cd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -90,6 +90,7 @@ import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFertilizeEvent; import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockFromToEvent; import org.bukkit.event.block.BlockGrowEvent; @@ -1223,4 +1224,51 @@ public class BlockEventListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockFertilize(BlockFertilizeEvent event) { + Block block = event.getBlock(); + List blocks = event.getBlocks(); + Location location = BukkitUtil.adapt(blocks.get(0).getLocation()); + + PlotArea area = location.getPlotArea(); + if (area == null) { + for (int i = blocks.size() - 1; i >= 0; i--) { + location = BukkitUtil.adapt(blocks.get(i).getLocation()); + if (location.isPlotArea()) { + blocks.remove(i); + } + } + return; + } else { + Plot origin = area.getOwnedPlot(location); + if (origin == null) { + event.setCancelled(true); + return; + } + for (int i = blocks.size() - 1; i >= 0; i--) { + location = BukkitUtil.adapt(blocks.get(i).getLocation()); + if (!area.contains(location.getX(), location.getZ())) { + blocks.remove(i); + continue; + } + Plot plot = area.getOwnedPlot(location); + if (!Objects.equals(plot, origin)) { + event.getBlocks().remove(i); + } + } + } + Plot origin = area.getPlot(location); + if (origin == null) { + event.setCancelled(true); + return; + } + for (int i = blocks.size() - 1; i >= 0; i--) { + location = BukkitUtil.adapt(blocks.get(i).getLocation()); + Plot plot = area.getOwnedPlot(location); + if (!Objects.equals(plot, origin) && (!plot.isMerged() && !origin.isMerged())) { + event.getBlocks().remove(i); + } + } + } + }