diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 23291dfc2..ddd212ed5 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -161,3 +161,13 @@ items-can-break-turtle-eggs ~~~~~~~~~~~~~~~~~~~~~~~~~~~ * **default**: false * **description**: Allow dropped items to damage/break turtle eggs + +block-tick-events +~~~~~~~~~~~~~~~~~ +* **default**: true +* **description**: Fire plugin events when blocks tick + +fluid-tick-events +~~~~~~~~~~~~~~~~~ +* **default**: true +* **description**: Fire plugin events when fluids tick diff --git a/patches/api/0012-Block-and-Fluid-Tick-Events.patch b/patches/api/0012-Block-and-Fluid-Tick-Events.patch new file mode 100644 index 000000000..47ede1eef --- /dev/null +++ b/patches/api/0012-Block-and-Fluid-Tick-Events.patch @@ -0,0 +1,167 @@ +From f1b7acbe7eaaa5f94fbe5fbf2bf8b907885dfecf Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Thu, 6 Jun 2019 23:23:45 -0500 +Subject: [PATCH] Block and Fluid Tick Events + +--- + .../purpur/event/block/BlockTickEvent.java | 49 +++++++++++++++++++ + .../purpur/event/block/FluidTickEvent.java | 49 +++++++++++++++++++ + src/main/java/org/bukkit/World.java | 30 ++++++++++++ + 3 files changed, 128 insertions(+) + create mode 100644 src/main/java/net/pl3x/purpur/event/block/BlockTickEvent.java + create mode 100644 src/main/java/net/pl3x/purpur/event/block/FluidTickEvent.java + +diff --git a/src/main/java/net/pl3x/purpur/event/block/BlockTickEvent.java b/src/main/java/net/pl3x/purpur/event/block/BlockTickEvent.java +new file mode 100644 +index 00000000..5325e0c0 +--- /dev/null ++++ b/src/main/java/net/pl3x/purpur/event/block/BlockTickEvent.java +@@ -0,0 +1,49 @@ ++package net.pl3x.purpur.event.block; ++ ++import org.bukkit.World; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.block.BlockEvent; ++ ++/** ++ * Called when a block is ticked by the server. ++ */ ++public class BlockTickEvent extends BlockEvent implements Cancellable { ++ private static final HandlerList handlers = new HandlerList(); ++ private final boolean isRandomTick; ++ private boolean cancelled; ++ ++ public BlockTickEvent(World world, int x, int y, int z) { ++ this(world, x, y, z, false); ++ } ++ ++ public BlockTickEvent(World world, int x, int y, int z, boolean isRandomTick) { ++ super(world.getBlockAt(x, y, z)); ++ this.isRandomTick = isRandomTick; ++ } ++ ++ /** ++ * Check if this is a random tick ++ * ++ * @return True if random ++ */ ++ public boolean isRandomTick() { ++ return isRandomTick; ++ } ++ ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ public void setCancelled(boolean cancel) { ++ cancelled = cancel; ++ } ++ ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +diff --git a/src/main/java/net/pl3x/purpur/event/block/FluidTickEvent.java b/src/main/java/net/pl3x/purpur/event/block/FluidTickEvent.java +new file mode 100644 +index 00000000..77d18fb8 +--- /dev/null ++++ b/src/main/java/net/pl3x/purpur/event/block/FluidTickEvent.java +@@ -0,0 +1,49 @@ ++package net.pl3x.purpur.event.block; ++ ++import org.bukkit.World; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.HandlerList; ++import org.bukkit.event.block.BlockEvent; ++ ++/** ++ * Called when a fluid is ticked by the server. ++ */ ++public class FluidTickEvent extends BlockEvent implements Cancellable { ++ private static final HandlerList handlers = new HandlerList(); ++ private final boolean isRandomTick; ++ private boolean cancelled; ++ ++ public FluidTickEvent(World world, int x, int y, int z) { ++ this(world, x, y, z, false); ++ } ++ ++ public FluidTickEvent(World world, int x, int y, int z, boolean isRandomTick) { ++ super(world.getBlockAt(x, y, z)); ++ this.isRandomTick = isRandomTick; ++ } ++ ++ /** ++ * Check if this is a random tick ++ * ++ * @return True if random ++ */ ++ public boolean isRandomTick() { ++ return isRandomTick; ++ } ++ ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ public void setCancelled(boolean cancel) { ++ cancelled = cancel; ++ } ++ ++ public HandlerList getHandlers() { ++ return handlers; ++ } ++ ++ public static HandlerList getHandlerList() { ++ return handlers; ++ } ++} +diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java +index 65dc8022..c99e4291 100644 +--- a/src/main/java/org/bukkit/World.java ++++ b/src/main/java/org/bukkit/World.java +@@ -2811,6 +2811,36 @@ public interface World extends PluginMessageRecipient, Metadatable { + @Nullable + public Location locateNearestStructure(@NotNull Location origin, @NotNull StructureType structureType, int radius, boolean findUnexplored); + ++ // Purpur start ++ /** ++ * Get if {@link net.pl3x.purpur.event.block.BlockTickEvent} is enabled for this world ++ * ++ * @return True if enabled ++ */ ++ boolean isBlockTickEventEnabled(); ++ ++ /** ++ * Set if {@link net.pl3x.purpur.event.block.BlockTickEvent} is enabled for this world ++ * ++ * @param enabled True to enable ++ */ ++ void setBlockTickEventEnabled(boolean enabled); ++ ++ /** ++ * Get if {@link net.pl3x.purpur.event.block.FluidTickEvent} is enabled for this world ++ * ++ * @return True if enabled ++ */ ++ boolean isFluidTickEventEnabled(); ++ ++ /** ++ * Set if {@link net.pl3x.purpur.event.block.FluidTickEvent} is enabled for this world ++ * ++ * @param enabled True to enable ++ */ ++ void setFluidTickEventEnabled(boolean enabled); ++ // Purpur end ++ + // Spigot start + public class Spigot + { +-- +2.20.1 + diff --git a/patches/server/0032-Block-and-Fluid-Tick-Events.patch b/patches/server/0032-Block-and-Fluid-Tick-Events.patch new file mode 100644 index 000000000..faba7b409 --- /dev/null +++ b/patches/server/0032-Block-and-Fluid-Tick-Events.patch @@ -0,0 +1,95 @@ +From 1533472cf35569ae6063e2c5734d0cf5cf150a73 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Thu, 6 Jun 2019 23:23:52 -0500 +Subject: [PATCH] Block and Fluid Tick Events + +--- + .../java/net/minecraft/server/WorldServer.java | 6 ++++-- + .../net/pl3x/purpur/PurpurWorldConfig.java | 7 +++++++ + .../org/bukkit/craftbukkit/CraftWorld.java | 18 ++++++++++++++++++ + 3 files changed, 29 insertions(+), 2 deletions(-) + +diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java +index 4f5fdc4ae..194be9ef1 100644 +--- a/src/main/java/net/minecraft/server/WorldServer.java ++++ b/src/main/java/net/minecraft/server/WorldServer.java +@@ -446,13 +446,13 @@ public class WorldServer extends World { + gameprofilerfiller.enter("randomTick"); + IBlockData iblockdata = chunksection.getType(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k); + +- if (iblockdata.q()) { ++ if (iblockdata.q()&& (!purpurConfig.blockTickEvent || new net.pl3x.purpur.event.block.BlockTickEvent(getWorld(), blockposition2.x, blockposition2.y, blockposition2.z, true).callEvent())) { // Purpur + iblockdata.b((World) this, blockposition2, this.random); + } + + Fluid fluid = chunksection.b(blockposition2.getX() - j, blockposition2.getY() - j1, blockposition2.getZ() - k); + +- if (fluid.g()) { ++ if (fluid.g() && (!purpurConfig.fluidTickEvent || new net.pl3x.purpur.event.block.FluidTickEvent(getWorld(), blockposition2.x, blockposition2.y, blockposition2.z, true).callEvent())) { // Purpur + fluid.b(this, blockposition2, this.random); + } + +@@ -541,6 +541,7 @@ public class WorldServer extends World { + Fluid fluid = this.getFluid(nextticklistentry.a); + + if (fluid.getType() == nextticklistentry.b()) { ++ if (purpurConfig.fluidTickEvent && !new net.pl3x.purpur.event.block.FluidTickEvent(getWorld(), nextticklistentry.a.x, nextticklistentry.a.y, nextticklistentry.a.z).callEvent()) return; // Purpur + fluid.a((World) this, nextticklistentry.a); + } + +@@ -550,6 +551,7 @@ public class WorldServer extends World { + IBlockData iblockdata = this.getType(nextticklistentry.a); + + if (iblockdata.getBlock() == nextticklistentry.b()) { ++ if (purpurConfig.blockTickEvent && !new net.pl3x.purpur.event.block.BlockTickEvent(getWorld(), nextticklistentry.a.x, nextticklistentry.a.y, nextticklistentry.a.z).callEvent()) return; // Purpur + iblockdata.a((World) this, nextticklistentry.a, this.random); + } + +diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +index a649a4c35..92eeaca42 100644 +--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java ++++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java +@@ -106,4 +106,11 @@ public class PurpurWorldConfig { + private void itemsCanBreakTurtleEggs() { + itemsCanBreakTurtleEggs = getBoolean("items-can-break-turtle-eggs", itemsCanBreakTurtleEggs); + } ++ ++ public boolean blockTickEvent = true; ++ public boolean fluidTickEvent = true; ++ private void tickEvents() { ++ blockTickEvent = getBoolean("block-tick-events", blockTickEvent); ++ fluidTickEvent = getBoolean("fluid-tick-events", fluidTickEvent); ++ } + } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +index 0c5379530..07f980158 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -2157,6 +2157,24 @@ public class CraftWorld implements World { + } + // Paper end + ++ // Purpur start ++ public boolean isBlockTickEventEnabled() { ++ return getHandle().purpurConfig.blockTickEvent; ++ } ++ ++ public void setBlockTickEventEnabled(boolean enabled) { ++ getHandle().purpurConfig.blockTickEvent = enabled; ++ } ++ ++ public boolean isFluidTickEventEnabled() { ++ return getHandle().purpurConfig.fluidTickEvent; ++ } ++ ++ public void setFluidTickEventEnabled(boolean enabled) { ++ getHandle().purpurConfig.fluidTickEvent = enabled; ++ } ++ // Purpur end ++ + // Spigot start + private final Spigot spigot = new Spigot() + { +-- +2.20.1 +