aboutsummaryrefslogtreecommitdiff
path: root/spark-sponge8/src
diff options
context:
space:
mode:
authorembeddedt <42941056+embeddedt@users.noreply.github.com>2022-07-30 16:26:48 -0400
committerembeddedt <42941056+embeddedt@users.noreply.github.com>2022-07-30 16:26:48 -0400
commit6387e79e06b7c0f72067a3769f534f10ad71014c (patch)
tree6fbc903b38f948543667ee493758f7a3c1357ff0 /spark-sponge8/src
parentd82a06eefbd98606edc43a8470c850a2ea3b1b9f (diff)
parent768bf7a338da8e5daaebc9580ff3b289092c28ee (diff)
downloadspark-6387e79e06b7c0f72067a3769f534f10ad71014c.tar.gz
spark-6387e79e06b7c0f72067a3769f534f10ad71014c.tar.bz2
spark-6387e79e06b7c0f72067a3769f534f10ad71014c.zip
Merge remote-tracking branch 'lucko/master' into forge-1.7.10
Diffstat (limited to 'spark-sponge8/src')
-rw-r--r--spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java30
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();
}