mirror of
https://github.com/PaperMC/Folia.git
synced 2025-04-22 20:29:19 +08:00
Implement Bukkit#getTps
Note that this requires the caller to be on a ticking region or the global region, otherwise it will throw UnsupportedOperationException. Now the function returns the TPS for the current region.
This commit is contained in:
parent
1f0b85d4e4
commit
87f8bd3e00
@ -5,10 +5,10 @@ Subject: [PATCH] Add TPS From Region
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 20bcfeef39746d547ef17ccf2b66d44ce1e6e354..755527ed59b50c95aeca71d0fc5fea224731ff51 100644
|
||||
index b254cab566110c590ba22b0bd48cc165bfd7ae27..bcd17eba9798747010ed96903992939a284199df 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -3333,4 +3333,68 @@ public final class CraftServer implements Server {
|
||||
@@ -3349,4 +3349,68 @@ public final class CraftServer implements Server {
|
||||
this.console.addPluginAllowingSleep(plugin.getName(), value);
|
||||
}
|
||||
// Paper end - API to check if the server is sleeping
|
||||
|
@ -91,6 +91,37 @@
|
||||
//Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes.
|
||||
if (world == null) {
|
||||
return false;
|
||||
@@ -3083,11 +_,27 @@
|
||||
|
||||
@Override
|
||||
public double[] getTPS() {
|
||||
+ // Folia start - region threading
|
||||
+ ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool.SchedulableTick task = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentTickingTask();
|
||||
+ if (task == null) {
|
||||
+ // might be on the shutdown thread, try retrieving the current region
|
||||
+ if (io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion() != null) {
|
||||
+ // we are on the shutdown thread
|
||||
+ task = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getRegionSchedulingHandle();
|
||||
+ }
|
||||
+ }
|
||||
+ if (!(task instanceof io.papermc.paper.threadedregions.TickRegionScheduler.RegionScheduleHandle tickHandle)) {
|
||||
+ throw new UnsupportedOperationException("Not on any region");
|
||||
+ }
|
||||
+
|
||||
+ // 1m, 5m, 15m
|
||||
+ long currTime = System.nanoTime();
|
||||
return new double[] {
|
||||
- net.minecraft.server.MinecraftServer.getServer().tps1.getAverage(),
|
||||
- net.minecraft.server.MinecraftServer.getServer().tps5.getAverage(),
|
||||
- net.minecraft.server.MinecraftServer.getServer().tps15.getAverage()
|
||||
+ tickHandle.getTickReport1m(currTime).tpsData().segmentAll().average(),
|
||||
+ tickHandle.getTickReport5m(currTime).tpsData().segmentAll().average(),
|
||||
+ tickHandle.getTickReport15m(currTime).tpsData().segmentAll().average(),
|
||||
};
|
||||
+ // Folia end - region threading
|
||||
}
|
||||
|
||||
// Paper start - adventure sounds
|
||||
@@ -3258,7 +_,7 @@
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user