From d7c2ab1d169df9b062ab0db2192d9a14bc14efc4 Mon Sep 17 00:00:00 2001 From: Traks <58818927+traksag@users.noreply.github.com> Date: Tue, 31 Jan 2023 11:22:13 +0100 Subject: [PATCH] Make farmland keep its moisture (#3952) Handle MoistureChangeEvent for farm land --- .../bukkit/listener/BlockEventListener.java | 23 +++++++++++++++++++ 1 file changed, 23 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 343acce06..fe58c41b7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -98,6 +98,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.MoistureChangeEvent; import org.bukkit.event.block.SpongeAbsorbEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.projectiles.BlockProjectileSource; @@ -703,6 +704,28 @@ public class BlockEventListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onMoistureChange(MoistureChangeEvent event) { + Block block = event.getBlock(); + Location location = BukkitUtil.adapt(block.getLocation()); + PlotArea area = location.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getOwnedPlot(location); + if (plot == null) { + event.setCancelled(true); + return; + } + Material blockType = block.getType(); + if (blockType == Material.FARMLAND) { + if (!plot.getFlag(SoilDryFlag.class)) { + plot.debug("Soil could not dry because soil-dry = false"); + event.setCancelled(true); + } + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onChange(BlockFromToEvent event) { Block fromBlock = event.getBlock();