CavePVP-Stuff/cSpigot-master/spigot-server-Patches/0111-Add-tick-timer-task.patch

100 lines
3.7 KiB
Diff

From f0e838ac944cdaab7f1b94f3ad4a6bd2184357d6 Mon Sep 17 00:00:00 2001
From: Poweruser_rs <poweruser.rs@hotmail.com>
Date: Sat, 12 Dec 2015 02:28:52 +0100
Subject: [PATCH] Add tick timer task
diff --git a/src/main/java/net/frozenorb/ThreadingManager.java b/src/main/java/net/frozenorb/ThreadingManager.java
index ef9eab186..0698caa61 100644
--- a/src/main/java/net/frozenorb/ThreadingManager.java
+++ b/src/main/java/net/frozenorb/ThreadingManager.java
@@ -9,6 +9,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -29,10 +30,15 @@ public class ThreadingManager {
private ScheduledExecutorService timerService = Executors.newScheduledThreadPool(1, new NamePriorityThreadFactory(Thread.NORM_PRIORITY + 2, "mSpigot_TimerService"));
private TickCounter tickCounter = new TickCounter();
+ private ScheduledFuture<Object> tickTimerTask;
+ private TickTimer tickTimerObject;
+ private static int timerDelay = 45;
+
public ThreadingManager() {
instance = this;
this.pathSearchThrottler = new PathSearchThrottlerThread(2);
this.timerService.scheduleAtFixedRate(this.tickCounter, 1, 1000, TimeUnit.MILLISECONDS);
+ this.tickTimerObject = new TickTimer();
}
public void shutdown() {
@@ -128,4 +134,41 @@ public class ThreadingManager {
public static TickCounter getTickCounter() {
return instance.tickCounter;
}
+
+ public static void startTickTimerTask() {
+ instance.tickTimerTask = instance.timerService.schedule(instance.tickTimerObject, timerDelay, TimeUnit.MILLISECONDS);
+ }
+
+ public static void cancelTimerTask(float tickTime) {
+ if(checkTickTime(tickTime) && instance.tickTimerTask.cancel(false)) {
+ instance.tickTimerObject.tickFinishedEarly();
+ }
+ }
+
+ private static boolean checkTickTime(float tickTime) {
+ if(tickTime > 45.0F) {
+ if(timerDelay > 40) {
+ timerDelay--;
+ }
+ } else {
+ if(timerDelay < 45) {
+ timerDelay++;
+ }
+ return tickTime < 40.0F;
+ }
+ return false;
+ }
+
+ private class TickTimer implements Callable<Object> {
+ public Object call() {
+ this.tickIsGoingToFinishLate();
+ return null;
+ }
+
+ public void tickIsGoingToFinishLate() {
+ }
+
+ public void tickFinishedEarly() {
+ }
+ }
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index ec48ff690..f6390520f 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -592,6 +592,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
long i = System.nanoTime();
ThreadingManager.getTickCounter().increaseTickCounter(); // Poweruser
+ ThreadingManager.startTickTimerTask(); // Poweruser
++this.ticks;
if (this.R) {
@@ -652,6 +653,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IMo
org.spigotmc.WatchdogThread.tick(); // Spigot
SpigotTimings.serverTickTimer.stopTiming(); // Spigot
this.lastTickTime = (System.nanoTime() - i) / 1000000F;
+ ThreadingManager.cancelTimerTask(this.lastTickTime); // Poweruser
org.spigotmc.CustomTimingsHandler.tick(); // Spigot
}
--
2.13.3