2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Wed, 27 Mar 2019 21:58:55 -0400
|
|
|
|
Subject: [PATCH] Server Tick Events
|
|
|
|
|
|
|
|
Fires event at start and end of a server tick
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/server/ServerTickEndEvent.java b/src/main/java/com/destroystokyo/paper/event/server/ServerTickEndEvent.java
|
|
|
|
new file mode 100644
|
2024-02-01 10:15:57 +01:00
|
|
|
index 0000000000000000000000000000000000000000..17e9f39ce1cc7489e936c96f95b8b0579528b222
|
2021-06-11 14:02:28 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/server/ServerTickEndEvent.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -0,0 +1,62 @@
|
2021-06-11 14:02:28 +02:00
|
|
|
+package com.destroystokyo.paper.event.server;
|
|
|
|
+
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
2024-02-01 10:15:57 +01:00
|
|
|
+import org.jetbrains.annotations.ApiStatus;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Called when the server has finished ticking the main loop
|
|
|
|
+ */
|
|
|
|
+public class ServerTickEndEvent extends Event {
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ private final int tickNumber;
|
|
|
|
+ private final double tickDuration;
|
|
|
|
+ private final long timeEnd;
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ @ApiStatus.Internal
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ServerTickEndEvent(int tickNumber, double tickDuration, long timeRemaining) {
|
|
|
|
+ this.tickNumber = tickNumber;
|
|
|
|
+ this.tickDuration = tickDuration;
|
|
|
|
+ this.timeEnd = System.nanoTime() + timeRemaining;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return What tick this was since start (first tick = 1)
|
|
|
|
+ */
|
|
|
|
+ public int getTickNumber() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.tickNumber;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return Time in milliseconds of how long this tick took
|
|
|
|
+ */
|
|
|
|
+ public double getTickDuration() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.tickDuration;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Amount of nanoseconds remaining before the next tick should start.
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * <p>
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * If this value is negative, then that means the server has exceeded the tick time limit and TPS has been lost.
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * <p>
|
2023-03-31 06:09:13 +02:00
|
|
|
+ * Method will continuously return the updated time remaining value. (return value is not static)
|
2021-06-11 14:02:28 +02:00
|
|
|
+ *
|
|
|
|
+ * @return Amount of nanoseconds remaining before the next tick should start
|
|
|
|
+ */
|
|
|
|
+ public long getTimeRemaining() {
|
|
|
|
+ return this.timeEnd - System.nanoTime();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public HandlerList getHandlers() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static HandlerList getHandlerList() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/server/ServerTickStartEvent.java b/src/main/java/com/destroystokyo/paper/event/server/ServerTickStartEvent.java
|
|
|
|
new file mode 100644
|
2024-02-01 10:15:57 +01:00
|
|
|
index 0000000000000000000000000000000000000000..fb5bbfffea8b883e4c8769484a2b64dd895cb617
|
2021-06-11 14:02:28 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/server/ServerTickStartEvent.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -0,0 +1,35 @@
|
2021-06-11 14:02:28 +02:00
|
|
|
+package com.destroystokyo.paper.event.server;
|
|
|
|
+
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
2024-02-01 10:15:57 +01:00
|
|
|
+import org.jetbrains.annotations.ApiStatus;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+public class ServerTickStartEvent extends Event {
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ private final int tickNumber;
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ @ApiStatus.Internal
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ServerTickStartEvent(int tickNumber) {
|
|
|
|
+ this.tickNumber = tickNumber;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return What tick this is going be since start (first tick = 1)
|
|
|
|
+ */
|
|
|
|
+ public int getTickNumber() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.tickNumber;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public HandlerList getHandlers() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static HandlerList getHandlerList() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+}
|