|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Abel <abelvanhulst@gmail.com> |
| 3 | +Date: Tue, 12 Nov 2024 22:25:20 +0100 |
| 4 | +Subject: [PATCH] API to allow/disallow tick sleeping |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java |
| 8 | +index 5d070f036dae6d93f863c55192b557419634456d..663b4ecd520e82aa108d44f2d5c2a20cfc7bc01f 100644 |
| 9 | +--- a/src/main/java/net/minecraft/server/MinecraftServer.java |
| 10 | ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java |
| 11 | +@@ -332,6 +332,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa |
| 12 | + public volatile Thread shutdownThread; // Paper |
| 13 | + public volatile boolean abnormalExit = false; // Paper |
| 14 | + public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation |
| 15 | ++ private List<String> pluginsBlockingSleep = new ArrayList<>(); // Paper - API to allow/disallow tick sleeping |
| 16 | + |
| 17 | + public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) { |
| 18 | + AtomicReference<S> atomicreference = new AtomicReference(); |
| 19 | +@@ -1623,8 +1624,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa |
| 20 | + long i = Util.getNanos(); |
| 21 | + int j = this.pauseWhileEmptySeconds() * 20; |
| 22 | + |
| 23 | ++ this.removeDisabledPluginsBlockingSleep(); // Paper - API to allow/disallow tick sleeping |
| 24 | + if (j > 0) { |
| 25 | +- if (this.playerList.getPlayerCount() == 0 && !this.tickRateManager.isSprinting()) { |
| 26 | ++ if (this.playerList.getPlayerCount() == 0 && !this.tickRateManager.isSprinting() && this.pluginsBlockingSleep.isEmpty()) { // Paper - API to allow/disallow tick sleeping |
| 27 | + ++this.emptyTicks; |
| 28 | + } else { |
| 29 | + this.emptyTicks = 0; |
| 30 | +@@ -3191,5 +3193,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa |
| 31 | + public boolean isTickPaused() { |
| 32 | + return this.emptyTicks > 0 && this.emptyTicks >= this.pauseWhileEmptySeconds() * 20; |
| 33 | + } |
| 34 | ++ |
| 35 | ++ public void addPluginAllowingSleep(final String pluginName, final boolean value) { |
| 36 | ++ if (!value) { |
| 37 | ++ this.pluginsBlockingSleep.add(pluginName); |
| 38 | ++ } else { |
| 39 | ++ this.pluginsBlockingSleep.remove(pluginName); |
| 40 | ++ } |
| 41 | ++ } |
| 42 | ++ |
| 43 | ++ private void removeDisabledPluginsBlockingSleep() { |
| 44 | ++ if (this.pluginsBlockingSleep.isEmpty()) { |
| 45 | ++ return; |
| 46 | ++ } |
| 47 | ++ this.pluginsBlockingSleep.removeIf(plugin -> ( |
| 48 | ++ !io.papermc.paper.plugin.manager.PaperPluginManagerImpl.getInstance().isPluginEnabled(plugin) |
| 49 | ++ )); |
| 50 | ++ } |
| 51 | + // Paper end - API to check if the server is sleeping |
| 52 | + } |
| 53 | +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 54 | +index 605662917a7720a6c5134fd1d93aa2d26116b76d..cac8592e3a2f438fe9ca167a4fdcd65152bbb2de 100644 |
| 55 | +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 56 | ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java |
| 57 | +@@ -3252,5 +3252,10 @@ public final class CraftServer implements Server { |
| 58 | + public boolean isPaused() { |
| 59 | + return this.console.isTickPaused(); |
| 60 | + } |
| 61 | ++ |
| 62 | ++ @Override |
| 63 | ++ public void allowPausing(final Plugin plugin, final boolean value) { |
| 64 | ++ this.console.addPluginAllowingSleep(plugin.getName(), value); |
| 65 | ++ } |
| 66 | + // Paper end - API to check if the server is sleeping |
| 67 | + } |
0 commit comments