diff options
-rw-r--r-- | spark-forge1122/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java | 14 | ||||
-rw-r--r-- | spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java | 16 |
2 files changed, 15 insertions, 15 deletions
diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java index 2c19659..ed8e9eb 100644 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java +++ b/spark-forge1122/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java @@ -29,6 +29,7 @@ import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; +import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; import net.minecraftforge.fml.relauncher.Side; import java.nio.file.Path; @@ -42,6 +43,7 @@ import java.nio.file.Path; public class ForgeSparkMod { private Path configDirectory; + private ForgeServerSparkPlugin activeServerPlugin; public String getVersion() { return ForgeSparkMod.class.getAnnotation(Mod.class).version(); @@ -53,7 +55,7 @@ public class ForgeSparkMod { } @EventHandler - public void init(FMLInitializationEvent e) { + public void clientInit(FMLInitializationEvent e) { if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { ForgeClientSparkPlugin.register(this); } @@ -61,7 +63,15 @@ public class ForgeSparkMod { @EventHandler public void serverInit(FMLServerStartingEvent e) { - ForgeServerSparkPlugin.register(this, e); + this.activeServerPlugin = ForgeServerSparkPlugin.register(this, e); + } + + @EventHandler + public void serverStop(FMLServerStoppingEvent e) { + if (this.activeServerPlugin != null) { + this.activeServerPlugin.disable(); + this.activeServerPlugin = null; + } } public Path getConfigDirectory() { diff --git a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index 4cf1711..a4a8434 100644 --- a/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge1122/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -20,7 +20,6 @@ package me.lucko.spark.forge.plugin; - import me.lucko.spark.common.platform.PlatformInfo; import me.lucko.spark.common.sampler.tick.TickHook; import me.lucko.spark.common.sampler.tick.TickReporter; @@ -33,10 +32,7 @@ import me.lucko.spark.forge.ForgeTickReporter; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.server.permission.DefaultPermissionLevel; import net.minecraftforge.server.permission.PermissionAPI; @@ -45,16 +41,15 @@ import java.util.stream.Stream; public class ForgeServerSparkPlugin extends ForgeSparkPlugin { - public static void register(ForgeSparkMod mod, FMLServerStartingEvent event) { + public static ForgeServerSparkPlugin register(ForgeSparkMod mod, FMLServerStartingEvent event) { ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, event.getServer()); plugin.enable(); - // register listeners - MinecraftForge.EVENT_BUS.register(plugin); - // register commands & permissions event.registerServerCommand(plugin); PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command"); + + return plugin; } private final MinecraftServer server; @@ -64,11 +59,6 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin { this.server = server; } - @SubscribeEvent - public void onDisable(FMLServerStoppingEvent event) { - disable(); - } - @Override public boolean hasPermission(ICommandSender sender, String permission) { if (sender instanceof EntityPlayer) { |