Skip to content

Commit

Permalink
Don't crash when switching local worlds (#123)
Browse files Browse the repository at this point in the history
* Don't crash on server/world switch

* prettier
  • Loading branch information
onebeastchris authored May 1, 2024
1 parent bf91d26 commit 3548ae5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/main/java/org/geysermc/floodgate/FabricMod.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand All @@ -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();
});
}
}
}

0 comments on commit 3548ae5

Please sign in to comment.