diff options
author | Luck <git@lucko.me> | 2021-05-23 11:52:46 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2021-05-23 11:52:46 +0100 |
commit | 69c8401d85b66c544b376ea714befc882f1397cd (patch) | |
tree | 4a75fcfd1e7fc2bd443f1ebce09b9485fadad6af /spark-common/src/main/java/me | |
parent | a20d365bdac8ebd1b3b1aea10fa31688641d90ac (diff) | |
download | spark-69c8401d85b66c544b376ea714befc882f1397cd.tar.gz spark-69c8401d85b66c544b376ea714befc882f1397cd.tar.bz2 spark-69c8401d85b66c544b376ea714befc882f1397cd.zip |
Fix bug where platform would enable twice on Fabric/Forge (#116)
Diffstat (limited to 'spark-common/src/main/java/me')
-rw-r--r-- | spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java | 14 |
1 files changed, 9 insertions, 5 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() { |