diff options
author | Luck <git@lucko.me> | 2022-07-17 12:27:04 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2022-07-17 12:27:04 +0100 |
commit | 36ac0700f6eaab4404b7dbca8537af8a6ac681a7 (patch) | |
tree | 06b1ce2369e8e36e0b852b59fa4924f716d2def0 /spark-sponge8 | |
parent | 319aae27ad290338a5558ac53517e144254a86ce (diff) | |
download | spark-36ac0700f6eaab4404b7dbca8537af8a6ac681a7.tar.gz spark-36ac0700f6eaab4404b7dbca8537af8a6ac681a7.tar.bz2 spark-36ac0700f6eaab4404b7dbca8537af8a6ac681a7.zip |
Fix sponge8 enable
Diffstat (limited to 'spark-sponge8')
-rw-r--r-- | spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java index 70e73b9..83b2ec2 100644 --- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java +++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java @@ -20,6 +20,7 @@ package me.lucko.spark.sponge; +import com.google.common.base.Suppliers; import com.google.inject.Inject; import me.lucko.spark.common.SparkPlatform; @@ -56,6 +57,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -68,7 +70,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { private final Game game; private final Path configDirectory; private final ExecutorService asyncExecutor; - private final ExecutorService syncExecutor; + private final Supplier<ExecutorService> syncExecutor; private final ThreadDumper.GameThread gameThreadDumper = new ThreadDumper.GameThread(); private SparkPlatform platform; @@ -80,16 +82,15 @@ public class Sponge8SparkPlugin implements SparkPlugin { this.game = game; this.configDirectory = configDirectory; this.asyncExecutor = game.asyncScheduler().executor(pluginContainer); - - if (game.isServerAvailable()) { - this.syncExecutor = game.server().scheduler().executor(pluginContainer); - } else if (game.isClientAvailable()) { - this.syncExecutor = game.client().scheduler().executor(pluginContainer); - } else { - throw new IllegalStateException("Server and client both unavailable"); - } - - this.syncExecutor.execute(() -> this.gameThreadDumper.setThread(Thread.currentThread())); + this.syncExecutor = Suppliers.memoize(() -> { + if (this.game.isServerAvailable()) { + return this.game.server().scheduler().executor(this.pluginContainer); + } else if (this.game.isClientAvailable()) { + return this.game.client().scheduler().executor(this.pluginContainer); + } else { + throw new IllegalStateException("Server and client both unavailable"); + } + }); } @@ -100,6 +101,8 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Listener public void onEnable(StartedEngineEvent<Server> event) { + executeSync(() -> this.gameThreadDumper.setThread(Thread.currentThread())); + this.platform = new SparkPlatform(this); this.platform.enable(); } @@ -143,7 +146,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public void executeSync(Runnable task) { - this.syncExecutor.execute(task); + this.syncExecutor.get().execute(task); } @Override |