diff --git a/src/main/java/org/geysermc/floodgate/FabricMod.java b/src/main/java/org/geysermc/floodgate/FabricMod.java index a2da132..090ee15 100644 --- a/src/main/java/org/geysermc/floodgate/FabricMod.java +++ b/src/main/java/org/geysermc/floodgate/FabricMod.java @@ -1,5 +1,7 @@ package org.geysermc.floodgate; +import net.fabricmc.api.EnvType; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import org.geysermc.floodgate.inject.fabric.FabricInjector; import com.google.inject.Guice; import com.google.inject.Injector; @@ -10,6 +12,9 @@ import org.geysermc.floodgate.module.*; public class FabricMod implements ModInitializer { + + private boolean started; + @Override public void onInitialize() { FabricInjector.setInstance(new FabricInjector()); @@ -30,19 +35,28 @@ public void onInitialize() { // This can probably be Guice-i-fied but that is beyond me MinecraftServerHolder.set(server); - platform.enable( - new FabricAddonModule(), - new FabricListenerModule(), - new PluginMessageModule() - ); + if (!started) { + platform.enable( + new FabricAddonModule(), + new FabricListenerModule(), + new PluginMessageModule() + ); + started = true; + } long endCtm = System.currentTimeMillis(); injector.getInstance(FloodgateLogger.class) .translatedInfo("floodgate.core.finish", endCtm - ctm); }); - ServerLifecycleEvents.SERVER_STOPPING.register((server) -> { - platform.disable(); - }); + if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { + ClientLifecycleEvents.CLIENT_STOPPING.register(($) -> { + platform.disable(); + }); + } else { + ServerLifecycleEvents.SERVER_STOPPING.register((server) -> { + platform.disable(); + }); + } } }