From 3123a069bf04af331ae9194d223a7fd376535949 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 9 Sep 2018 18:53:38 +1000 Subject: [PATCH] SPIGOT-4352: MoistureChangeEvent --- nms-patches/BlockSoil.patch | 16 +++++++++++++++- .../craftbukkit/event/CraftEventFactory.java | 13 +++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/nms-patches/BlockSoil.patch b/nms-patches/BlockSoil.patch index c10f006263..75bc8516e5 100644 --- a/nms-patches/BlockSoil.patch +++ b/nms-patches/BlockSoil.patch @@ -12,7 +12,21 @@ public class BlockSoil extends Block { public static final BlockStateInteger MOISTURE = BlockProperties.ai; -@@ -63,14 +68,37 @@ +@@ -51,26 +56,49 @@ + + if (!a((IWorldReader) world, blockposition) && !world.isRainingAt(blockposition.up())) { + if (i > 0) { +- world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockSoil.MOISTURE, Integer.valueOf(i - 1)), 2); ++ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(world, blockposition, (IBlockData) iblockdata.set(BlockSoil.MOISTURE, Integer.valueOf(i - 1)), 2); // CraftBukkit + } else if (!a((IBlockAccess) world, blockposition)) { + b(iblockdata, world, blockposition); + } + } else if (i < 7) { +- world.setTypeAndData(blockposition, (IBlockData) iblockdata.set(BlockSoil.MOISTURE, Integer.valueOf(7)), 2); ++ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(world, blockposition, (IBlockData) iblockdata.set(BlockSoil.MOISTURE, Integer.valueOf(7)), 2); // CraftBukkit + } + + } } public void fallOn(World world, BlockPosition blockposition, Entity entity, float f) { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index daaf5037d3..c1acd202ee 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -373,6 +373,19 @@ public class CraftEventFactory { return event; } + public static boolean handleMoistureChangeEvent(World world, BlockPosition pos, IBlockData newBlock, int flag) { + CraftBlockState state = CraftBlockState.getBlockState(world, pos, flag); + state.setData(newBlock); + + MoistureChangeEvent event = new MoistureChangeEvent(state.getBlock(), state); + Bukkit.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + state.update(true); + } + return !event.isCancelled(); + } + public static boolean handleBlockSpreadEvent(World world, BlockPosition source, BlockPosition target, IBlockData block) { return handleBlockSpreadEvent(world, source, target, block, 2); }