Files
Purpur/patches/api/0018-Add-block-and-fluid-tick-events.patch
William Blake Galbreath ddf1f8a586 Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly

Paper Changes:
01b965e0 Fix getChunkAtIfCachedImmediately (#2915)
0a897d6e Rebuild patches
5792c862 Updated Upstream (Bukkit/CraftBukkit/Spigot)
c9eebbb8 Fix Player#applyMending NPE (#2917)
d16a5d88 Performance patches prerequisite (#2802)
2020-01-29 21:58:09 -06:00

180 lines
5.1 KiB
Diff

From a826a72e5296e80f2858925861cbe089f149fe29 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Fri, 18 Oct 2019 23:58:29 -0500
Subject: [PATCH] Add block and fluid tick events
---
.../purpur/event/block/BlockTickEvent.java | 55 +++++++++++++++++++
.../purpur/event/block/FluidTickEvent.java | 55 +++++++++++++++++++
src/main/java/org/bukkit/World.java | 30 ++++++++++
3 files changed, 140 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 000000000..02787304f
--- /dev/null
+++ b/src/main/java/net/pl3x/purpur/event/block/BlockTickEvent.java
@@ -0,0 +1,55 @@
+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;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * 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(@NotNull World world, int x, int y, int z) {
+ this(world, x, y, z, false);
+ }
+
+ public BlockTickEvent(@NotNull 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;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ cancelled = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ 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 000000000..1a8f0b674
--- /dev/null
+++ b/src/main/java/net/pl3x/purpur/event/block/FluidTickEvent.java
@@ -0,0 +1,55 @@
+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;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * 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(@NotNull World world, int x, int y, int z) {
+ this(world, x, y, z, false);
+ }
+
+ public FluidTickEvent(@NotNull 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;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ cancelled = cancel;
+ }
+
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ 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 6fe025338..1edf1ec72 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -3058,6 +3058,36 @@ public interface World extends PluginMessageRecipient, Metadatable {
@NotNull
public List<Raid> getRaids();
+ // 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
+
/**
* Represents various map environment types that a world may be
*/
--
2.24.0