blob: dc1ff52aba1a3b26dd6a34700105a0717b7a5da1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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");
}
}
}
|