From fc3137cd963abe3f8576e494a5ab8b504d7ab9cf Mon Sep 17 00:00:00 2001 From: ByteExceptionM Date: Sun, 5 Mar 2023 10:15:05 +0100 Subject: [PATCH] Fix farmland moisturize (#3978) * fix: Fix farmland gets moisturizes Signed-off-by: ByteExceptionM * chore: Revert code reformat Signed-off-by: ByteExceptionM --------- Signed-off-by: ByteExceptionM --- .../bukkit/listener/BlockEventListener.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) 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 fe58c41b7..8ae570bd1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/BlockEventListener.java @@ -71,6 +71,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Dispenser; +import org.bukkit.block.data.type.Farmland; import org.bukkit.entity.Entity; import org.bukkit.entity.Fireball; import org.bukkit.entity.Player; @@ -709,20 +710,33 @@ public class BlockEventListener implements Listener { 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); + + if (block.getBlockData() instanceof Farmland farmland && event.getNewState().getBlockData() instanceof Farmland newFarmland) { + int currentMoisture = farmland.getMoisture(); + int newMoisture = newFarmland.getMoisture(); + + // farmland gets moisturizes + if (newMoisture > currentMoisture) { + return; } + + if (plot.getFlag(SoilDryFlag.class)) { + return; + } + + plot.debug("Soil could not dry because soil-dry = false"); + event.setCancelled(true); } }