aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/ymc/acron/MinecraftServerHolder.java
diff options
context:
space:
mode:
authorYuuta Liang <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
committerTrumeet <yuuta@yuuta.moe>2022-07-13 11:16:27 -0700
commit85045e1e4a15e0a5657d189e83dd202a2c37f2b0 (patch)
tree944bc9ee7a86bd413dfc940e210f21d2434ec7d3 /src/main/java/moe/ymc/acron/MinecraftServerHolder.java
downloadacron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.gz
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.tar.bz2
acron-85045e1e4a15e0a5657d189e83dd202a2c37f2b0.zip
First Commit
Signed-off-by: Trumeet <yuuta@yuuta.moe>
Diffstat (limited to 'src/main/java/moe/ymc/acron/MinecraftServerHolder.java')
-rw-r--r--src/main/java/moe/ymc/acron/MinecraftServerHolder.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/moe/ymc/acron/MinecraftServerHolder.java b/src/main/java/moe/ymc/acron/MinecraftServerHolder.java
new file mode 100644
index 0000000..f522884
--- /dev/null
+++ b/src/main/java/moe/ymc/acron/MinecraftServerHolder.java
@@ -0,0 +1,28 @@
+package moe.ymc.acron;
+
+import net.minecraft.server.dedicated.MinecraftDedicatedServer;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.jetbrains.annotations.NotNull;
+
+public class MinecraftServerHolder {
+ private static final Logger LOGGER = LogManager.getLogger();
+ public static MinecraftDedicatedServer server;
+
+ public static void setServer(@NotNull MinecraftDedicatedServer server) {
+ if (MinecraftServerHolder.server != null) {
+ throw new IllegalStateException();
+ }
+ LOGGER.debug("Got MinecraftDedicatedServer on thread {}.",
+ Thread.currentThread().getName());
+ MinecraftServerHolder.server = server;
+ }
+
+ public static @NotNull MinecraftDedicatedServer getServer() {
+ if (server == null) {
+ throw new IllegalStateException(String.format("[%s] getServer() called before a server is ready.",
+ Thread.currentThread().getName()));
+ }
+ return server;
+ }
+}