diff options
author | Keuin <[email protected]> | 2022-09-17 15:59:40 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-09-17 15:59:40 +0800 |
commit | 3e8fae576d7afccb29f5a35d07df970bafdecd36 (patch) | |
tree | 41fdeb6c19bb3daef7ca7054a9bbb84fed0cd8b6 /src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java | |
parent | ea3658cd57899398d885d86be9f74798b8c5ef39 (diff) |
stashed updatesmaster-auto-backup
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java b/src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java new file mode 100644 index 0000000..dc1ff52 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/singleton/MinecraftServerInstance.java @@ -0,0 +1,25 @@ +package com.keuin.kbackupfabric.singleton; + +import net.minecraft.server.MinecraftServer; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Holds {@link MinecraftServer} instance. + */ +public class MinecraftServerInstance { + private static AtomicReference<MinecraftServer> instance = new AtomicReference<>(); + + public static @NotNull MinecraftServer getInstance() { + return Objects.requireNonNull(instance.get()); + } + + public static void setInstance(@NotNull MinecraftServer instance) { + Objects.requireNonNull(instance); + if (!MinecraftServerInstance.instance.compareAndSet(null, instance)) { + throw new IllegalStateException("instance already exists"); + } + } +} |