diff options
Diffstat (limited to 'spark-forge')
3 files changed, 28 insertions, 11 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 66fd3ab..7b32f5b 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -54,11 +54,13 @@ import java.util.stream.Stream; public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements SuggestionProvider<ISuggestionProvider> { public static void register(ForgeSparkMod mod, FMLClientSetupEvent event) { - Minecraft minecraft = event.getMinecraftSupplier().get(); + ForgeClientSparkPlugin plugin = new ForgeClientSparkPlugin(mod, event.getMinecraftSupplier().get()); + plugin.enable(); - ForgeClientSparkPlugin plugin = new ForgeClientSparkPlugin(mod, minecraft); + // register listeners MinecraftForge.EVENT_BUS.register(plugin); + // ensure commands are registered plugin.scheduler.scheduleWithFixedDelay(plugin::checkCommandRegistered, 10, 10, TimeUnit.SECONDS); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index 3433e3b..42309c1 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -58,18 +58,17 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< public static void register(ForgeSparkMod mod, RegisterCommandsEvent event) { ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, ServerLifecycleHooks::getCurrentServer); + plugin.enable(); + + // register listeners MinecraftForge.EVENT_BUS.register(plugin); + // register commands & permissions CommandDispatcher<CommandSource> dispatcher = event.getDispatcher(); registerCommands(dispatcher, plugin, plugin, "spark"); PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command"); } - @SubscribeEvent - public void onDisable(FMLServerStoppingEvent event) { - this.platform.disable(); - } - private final Supplier<MinecraftServer> server; public ForgeServerSparkPlugin(ForgeSparkMod mod, Supplier<MinecraftServer> server) { @@ -77,6 +76,11 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< this.server = server; } + @SubscribeEvent + public void onDisable(FMLServerStoppingEvent event) { + disable(); + } + @Override public int run(CommandContext<CommandSource> context) throws CommandSyntaxException { String[] args = processArgs(context); 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 920ca24..17bc3e1 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 @@ -20,7 +20,6 @@ package me.lucko.spark.forge.plugin; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; @@ -65,13 +64,25 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { protected ForgeSparkPlugin(ForgeSparkMod mod) { this.mod = mod; - this.scheduler = Executors.newSingleThreadScheduledExecutor( - new ThreadFactoryBuilder().setNameFormat("spark-forge-async-worker").build() - ); + this.scheduler = Executors.newSingleThreadScheduledExecutor(r -> { + Thread thread = Executors.defaultThreadFactory().newThread(r); + thread.setName("spark-forge-async-worker"); + thread.setDaemon(true); + return thread; + }); this.platform = new SparkPlatform(this); this.platform.enable(); } + public void enable() { + this.platform.enable(); + } + + public void disable() { + this.platform.disable(); + this.scheduler.shutdown(); + } + public abstract boolean hasPermission(ICommandSource sender, String permission); @Override |