Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added API to check if the server is sleeping #11605

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions patches/api/0496-API-to-check-if-the-server-is-sleeping.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Abel <[email protected]>
Date: Sun, 10 Nov 2024 16:32:51 +0100
Subject: [PATCH] API to check if the server is sleeping


diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 0b78564256ebc647ebac402e549d86ab6e307c8d..ba366576a571214e67bcc529dc1bca19e1d59ef8 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -2572,4 +2572,11 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*/
boolean isOwnedByCurrentRegion(@NotNull Entity entity);
// Paper end - Folia region threading API
+
+ // Paper start - API to check if the server is sleeping
+ /**
+ * Returns whether the server is sleeping/paused.
+ */
+ boolean isPaused();
+ // Paper end - API to check if the server is sleeping
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Abel <[email protected]>
Date: Sun, 10 Nov 2024 16:32:34 +0100
Subject: [PATCH] API to check if the server is sleeping


diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 64b56abf8900d0424100da460fc68ac964394793..f0f2111b5610e493baf718a8a2257f9fb8c679e7 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1614,9 +1614,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

public void onServerExit() {}

+ // Paper start - API to check if the server is sleeping
public boolean isPaused() {
Abelkrijgtalles marked this conversation as resolved.
Show resolved Hide resolved
- return false;
+ return this.emptyTicks >= this.pauseWhileEmptySeconds() * 20;
}
+ // Paper end - API to check if the server is sleeping

public void tickServer(BooleanSupplier shouldKeepTicking) {
org.spigotmc.WatchdogThread.tick(); // Spigot
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index dfddcfb1fe1679adaecf75375757dca720e76ce1..f98b9ae05618d8a4199aaf004f26a61be9d26008 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -3246,4 +3246,11 @@ public final class CraftServer implements Server {
return this.potionBrewer;
}
// Paper end
+
+ // Paper start - API to check if the server is sleeping
+ @Override
+ public boolean isPaused() {
+ return console.isPaused();
+ }
+ // Paper end - API to check if the server is sleeping
}
Loading