diff options
Diffstat (limited to 'spark-sponge8/src')
-rw-r--r-- | spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java | 30 |
1 files changed, 17 insertions, 13 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 68e47e3..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,10 +70,10 @@ 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; - private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); @Inject public Sponge8SparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory) { @@ -80,14 +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 = 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"); + } + }); } @@ -98,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(); } @@ -141,7 +146,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public void executeSync(Runnable task) { - this.syncExecutor.execute(task); + this.syncExecutor.get().execute(task); } @Override @@ -159,7 +164,7 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); + return this.gameThreadDumper.get(); } @Override @@ -204,7 +209,6 @@ public class Sponge8SparkPlugin implements SparkPlugin { @Override public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) { - this.plugin.threadDumper.ensureSetup(); this.plugin.platform.executeCommand(new Sponge8CommandSender(cause), arguments.input().split(" ")); return CommandResult.success(); } |