Some events for threaded regions
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrHua269 <novau233@163.com>
|
||||||
|
Date: Fri, 9 Feb 2024 03:28:48 +0000
|
||||||
|
Subject: [PATCH] Threaded region remove and create event
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/me/earthme/luminol/api/events/TickRegionCreateEvent.java b/src/main/java/me/earthme/luminol/api/events/TickRegionCreateEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..9f842aeb33e658f3db540b6195f848d2a56ce14f
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/me/earthme/luminol/api/events/TickRegionCreateEvent.java
|
||||||
|
@@ -0,0 +1,32 @@
|
||||||
|
+package me.earthme.luminol.api.events;
|
||||||
|
+
|
||||||
|
+import org.bukkit.event.Event;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * This event was called when a new threaded region was created.When the event called,it means this region was already added to the region list
|
||||||
|
+ * Notice: It may be called when splitting or merging regions
|
||||||
|
+ */
|
||||||
|
+public class TickRegionCreateEvent extends Event {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final long id;
|
||||||
|
+
|
||||||
|
+ public TickRegionCreateEvent(long id) {
|
||||||
|
+ this.id = id;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the id of the threaded region which was created
|
||||||
|
+ * @return The id of the threaded region
|
||||||
|
+ */
|
||||||
|
+ public long getId() {
|
||||||
|
+ return this.id;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public @NotNull HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/me/earthme/luminol/api/events/TickRegionRemoveEvent.java b/src/main/java/me/earthme/luminol/api/events/TickRegionRemoveEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..aa3d3868f9d0c3353380960db36ee60a6b4aeb03
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/me/earthme/luminol/api/events/TickRegionRemoveEvent.java
|
||||||
|
@@ -0,0 +1,28 @@
|
||||||
|
+package me.earthme.luminol.api.events;
|
||||||
|
+
|
||||||
|
+import org.bukkit.event.Event;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * This event was called when a new threaded region was removed.When the event called,it means this region was already removed from the region list
|
||||||
|
+ * Notice: It may be called when splitting or merging regions
|
||||||
|
+ */
|
||||||
|
+public class TickRegionRemoveEvent extends Event {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final long id;
|
||||||
|
+
|
||||||
|
+ public TickRegionRemoveEvent(long id) {
|
||||||
|
+ this.id = id;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public long getId() {
|
||||||
|
+ return this.id;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public @NotNull HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrHua269 <novau233@163.com>
|
||||||
|
Date: Fri, 9 Feb 2024 03:32:05 +0000
|
||||||
|
Subject: [PATCH] Threaded region start tick and finished tick event
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/me/earthme/luminol/api/events/TickRegionFinishedTickEvent.java b/src/main/java/me/earthme/luminol/api/events/TickRegionFinishedTickEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..29b98728d3ca4a439c6b3333cd123c0e0b8a2846
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/me/earthme/luminol/api/events/TickRegionFinishedTickEvent.java
|
||||||
|
@@ -0,0 +1,42 @@
|
||||||
|
+package me.earthme.luminol.api.events;
|
||||||
|
+
|
||||||
|
+import org.bukkit.event.Event;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when a region finished its tick task.
|
||||||
|
+ */
|
||||||
|
+public class TickRegionFinishedTickEvent extends Event {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final long currTime;
|
||||||
|
+ private final long regionId;
|
||||||
|
+
|
||||||
|
+ public TickRegionFinishedTickEvent(long currTime, long regionId) {
|
||||||
|
+ this.currTime = currTime;
|
||||||
|
+ this.regionId = regionId;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the time of tick end
|
||||||
|
+ * @return The time of tick end in nanoseconds
|
||||||
|
+ */
|
||||||
|
+ public long getFinishedTime() {
|
||||||
|
+ return this.currTime;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the id of current region
|
||||||
|
+ * Notice: The id of global region is -1 in this event
|
||||||
|
+ * @return The id of current region
|
||||||
|
+ */
|
||||||
|
+ public long getRegionId() {
|
||||||
|
+ return this.regionId;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public @NotNull HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/me/earthme/luminol/api/events/TickRegionStartTickEvent.java b/src/main/java/me/earthme/luminol/api/events/TickRegionStartTickEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..1f3cba43ebd873965c24b96ca116abfb149ab4e6
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/me/earthme/luminol/api/events/TickRegionStartTickEvent.java
|
||||||
|
@@ -0,0 +1,41 @@
|
||||||
|
+package me.earthme.luminol.api.events;
|
||||||
|
+
|
||||||
|
+import org.bukkit.event.Event;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when a tick was started.
|
||||||
|
+ */
|
||||||
|
+public class TickRegionStartTickEvent extends Event {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+ private final long currTime;
|
||||||
|
+ private final long regionId;
|
||||||
|
+
|
||||||
|
+ public TickRegionStartTickEvent(long currTime, long regionId) {
|
||||||
|
+ this.currTime = currTime;
|
||||||
|
+ this.regionId = regionId;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the id of current region
|
||||||
|
+ * Notice: The id of global region is -1 in this event
|
||||||
|
+ * @return The id of current region
|
||||||
|
+ */
|
||||||
|
+ public long getRegionId() {
|
||||||
|
+ return this.regionId;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the time of tick start
|
||||||
|
+ * @return The time of tick start in nanoseconds
|
||||||
|
+ */
|
||||||
|
+ public long getStartTime(){
|
||||||
|
+ return this.currTime;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public @NotNull HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrHua269 <novau233@163.com>
|
||||||
|
Date: Fri, 9 Feb 2024 03:28:48 +0000
|
||||||
|
Subject: [PATCH] Threaded region remove and create event
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
|
||||||
|
index 531aa50f2c84e13358e8918bb0c15ea3cd036cb5..26183f979e24de369fd8f5e72a26a6a9ba44f601 100644
|
||||||
|
--- a/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
|
||||||
|
+++ b/src/main/java/io/papermc/paper/threadedregions/ThreadedRegionizer.java
|
||||||
|
@@ -805,6 +805,7 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio
|
||||||
|
private void onCreate() {
|
||||||
|
this.regioniser.onRegionCreate(this);
|
||||||
|
this.regioniser.callbacks.onRegionCreate(this);
|
||||||
|
+ new me.earthme.luminol.api.events.TickRegionCreateEvent(this.id).callEvent(); //Luminol - Threaded regions API
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRemove(final boolean wasActive) {
|
||||||
|
@@ -813,6 +814,7 @@ public final class ThreadedRegionizer<R extends ThreadedRegionizer.ThreadedRegio
|
||||||
|
}
|
||||||
|
this.regioniser.callbacks.onRegionDestroy(this);
|
||||||
|
this.regioniser.onRegionDestroy(this);
|
||||||
|
+ new me.earthme.luminol.api.events.TickRegionRemoveEvent(this.id).callEvent(); //Luminol - Threaded regions API
|
||||||
|
}
|
||||||
|
|
||||||
|
private final boolean hasNoAliveSections() {
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrHua269 <novau233@163.com>
|
||||||
|
Date: Fri, 9 Feb 2024 03:32:05 +0000
|
||||||
|
Subject: [PATCH] Threaded region start tick and finished tick event
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||||||
|
index 865044d40a95d201765435cbc14b0384980eebf6..ab5f832aafc479eca1c5da012e180d6374e32325 100644
|
||||||
|
--- a/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||||||
|
+++ b/src/main/java/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||||||
|
@@ -389,7 +389,7 @@ public final class TickRegionScheduler {
|
||||||
|
|
||||||
|
final long scheduledStart = this.getScheduledStart();
|
||||||
|
final long scheduledEnd = scheduledStart + TIME_BETWEEN_TICKS;
|
||||||
|
-
|
||||||
|
+ new me.earthme.luminol.api.events.TickRegionStartTickEvent(this.region == null ? -1 : this.region.region.id,System.nanoTime()); //Luminol - Threaded regions API
|
||||||
|
synchronized (this) {
|
||||||
|
this.currentTickData = new TickTime(
|
||||||
|
lastTickStart, scheduledStart, tickStart, cpuStart,
|
||||||
|
@@ -424,6 +424,7 @@ public final class TickRegionScheduler {
|
||||||
|
);
|
||||||
|
|
||||||
|
this.addTickTime(time);
|
||||||
|
+ new me.earthme.luminol.api.events.TickRegionFinishedTickEvent(this.region == null ? -1 : this.region.region.id,System.nanoTime()); //Luminol - Threaded regions API
|
||||||
|
TickRegionScheduler.setTickTask(null);
|
||||||
|
if (this.region != null) {
|
||||||
|
TickRegionScheduler.setTickingRegion(null);
|
||||||
Reference in New Issue
Block a user