geforkt von Mirrors/Paper
Add API to allow/disallow tick sleeping (#11611)
Dieser Commit ist enthalten in:
Ursprung
9badea8a55
Commit
89bd3e5c99
25
patches/api/API-to-allow-disallow-tick-sleeping.patch
Normale Datei
25
patches/api/API-to-allow-disallow-tick-sleeping.patch
Normale Datei
@ -0,0 +1,25 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Abel <abelvanhulst@gmail.com>
|
||||
Date: Tue, 12 Nov 2024 22:25:35 +0100
|
||||
Subject: [PATCH] API to allow/disallow tick sleeping
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -0,0 +0,0 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
* Returns whether the server is sleeping/paused.
|
||||
*/
|
||||
boolean isPaused();
|
||||
+
|
||||
+ /**
|
||||
+ * Allows or disallows the server to sleep/pause.
|
||||
+ * If any plugin disallows pausing, the server will never pause.
|
||||
+ *
|
||||
+ * @param plugin The {@link org.bukkit.plugin.Plugin} that's allowing or disallowing pausing.
|
||||
+ * @param value Whether to allow sleeping of the server (defaults to true).
|
||||
+ */
|
||||
+ void allowPausing(@NotNull org.bukkit.plugin.Plugin plugin, boolean value);
|
||||
// Paper end - API to check if the server is sleeping
|
||||
}
|
67
patches/server/API-to-allow-disallow-tick-sleeping.patch
Normale Datei
67
patches/server/API-to-allow-disallow-tick-sleeping.patch
Normale Datei
@ -0,0 +1,67 @@
|
||||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
public volatile Thread shutdownThread; // Paper
|
||||
public volatile boolean abnormalExit = false; // Paper
|
||||
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
||||
+ private List<String> pluginsBlockingSleep = new ArrayList<>(); // Paper - API to allow/disallow tick sleeping
|
||||
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
||||
AtomicReference<S> atomicreference = new AtomicReference();
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren