Fix farmland moisturize (#3978)

* fix: Fix farmland gets moisturizes

Signed-off-by: ByteExceptionM <git@byteexception.eu>

* chore: Revert code reformat

Signed-off-by: ByteExceptionM <git@byteexception.eu>

---------

Signed-off-by: ByteExceptionM <git@byteexception.eu>
This commit is contained in:
ByteExceptionM 2023-03-05 10:15:05 +01:00 committed by GitHub
parent c46cc73f52
commit fc3137cd96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,22 +710,35 @@ 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)) {
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);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onChange(BlockFromToEvent event) {