mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 19:07:40 +01:00
68 lines
3.4 KiB
Diff
68 lines
3.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Abel <abelvanhulst@gmail.com>
|
|
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 1c5a439650146bee85a98d8072ee131300264eee..c3d02e4712a1543fc59d88e5d20adcb6c806be0f 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -328,6 +328,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// Spigot end
|
|
public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
|
|
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
|
+ private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
|
|
|
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
|
AtomicReference<S> atomicreference = new AtomicReference();
|
|
@@ -1500,8 +1501,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
long i = Util.getNanos();
|
|
int j = this.pauseWhileEmptySeconds() * 20;
|
|
|
|
+ this.removeDisabledPluginsBlockingSleep(); // Paper - API to allow/disallow tick sleeping
|
|
if (j > 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;
|
|
@@ -3031,5 +3033,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
public boolean isTickPaused() {
|
|
return this.emptyTicks > 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 df9cfdcc27d6f596d554d7271b1d6a30cd3fbc0e..6370b780af5043f32d07346ea4dd7f23c819f7a0 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
|
|
}
|