From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Abel Date: Tue, 12 Nov 2024 22:25:20 +0100 Subject: [PATCH] API to allow/disallow tick sleeping diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 135fb7f722947a57169f0ce584cb031f4c54c854..780582ebaa8deb0c0b0c8de17de5abcebafa4bd3 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -332,6 +332,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping public static S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); @@ -1623,8 +1624,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0) { - if (this.playerList.getPlayerCount() == 0 && !this.tickRateManager.isSprinting()) { + if (this.playerList.getPlayerCount() == 0 && !this.tickRateManager.isSprinting() && this.pluginsBlockingSleep.isEmpty()) { // Paper - API to allow/disallow tick sleeping ++this.emptyTicks; } else { this.emptyTicks = 0; @@ -3191,5 +3193,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0 && this.emptyTicks >= this.pauseWhileEmptySeconds() * 20; } + + public void addPluginAllowingSleep(final String pluginName, final boolean value) { + if (!value) { + this.pluginsBlockingSleep.add(pluginName); + } else { + this.pluginsBlockingSleep.remove(pluginName); + } + } + + private void removeDisabledPluginsBlockingSleep() { + if (this.pluginsBlockingSleep.isEmpty()) { + return; + } + this.pluginsBlockingSleep.removeIf(plugin -> ( + !io.papermc.paper.plugin.manager.PaperPluginManagerImpl.getInstance().isPluginEnabled(plugin) + )); + } // Paper end - API to check if the server is sleeping } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 7afc3d4244c096f78d48338da2eb65c4e834b6f1..ac8af406180bc680d46e8edc3da0fc2e5211345a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -3264,5 +3264,10 @@ public final class CraftServer implements Server { public boolean isPaused() { return this.console.isTickPaused(); } + + @Override + public void allowPausing(final Plugin plugin, final boolean value) { + this.console.addPluginAllowingSleep(plugin.getName(), value); + } // Paper end - API to check if the server is sleeping }