diff options
4 files changed, 9 insertions, 8 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index 099ad2d..a4ae848 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -54,6 +54,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; @@ -89,8 +90,7 @@ public class SparkPlatform { private final TickStatistics tickStatistics; private Map<String, GarbageCollectorStatistics> startupGcStatistics = ImmutableMap.of(); private long serverNormalOperationStartTime; - - private SparkApi api; + private final AtomicBoolean enabled = new AtomicBoolean(false); public SparkPlatform(SparkPlugin plugin) { this.plugin = plugin; @@ -119,6 +119,10 @@ public class SparkPlatform { } public void enable() { + if (this.enabled.compareAndSet(false, true)) { + throw new RuntimeException("Platform has already been enabled!"); + } + if (this.tickHook != null) { this.tickHook.addCallback(this.tickStatistics); this.tickHook.start(); @@ -135,9 +139,9 @@ public class SparkPlatform { this.serverNormalOperationStartTime = System.currentTimeMillis(); }); - this.api = new SparkApi(this); - this.plugin.registerApi(this.api); - SparkApi.register(this.api); + SparkApi api = new SparkApi(this); + this.plugin.registerApi(api); + SparkApi.register(api); } public void disable() { diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java index 59610b1..4b48d6a 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java @@ -55,7 +55,6 @@ public abstract class FabricSparkPlugin implements SparkPlugin { return thread; }); this.platform = new SparkPlatform(this); - this.platform.enable(); } public void enable() { diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index 35e6d7b..083a350 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java @@ -74,7 +74,6 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { return thread; }); this.platform = new SparkPlatform(this); - this.platform.enable(); } public void enable() { diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java index 936e0b9..d052d72 100644 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java +++ b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/Forge1122SparkPlugin.java @@ -55,7 +55,6 @@ public abstract class Forge1122SparkPlugin implements SparkPlugin, ICommand { return thread; }); this.platform = new SparkPlatform(this); - this.platform.enable(); } public void enable() { |