From 4883a207972fde0a31e0e0506f5aee1be89eab2b Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sun, 25 Oct 2020 16:22:50 -0400 Subject: [PATCH] Add load complete message and don't null the server if reloading --- .../geysermc/platform/fabric/GeyserFabricMod.java | 11 ++++++++--- .../fabric/command/GeyserFabricCommandExecutor.java | 4 ++++ .../fabric/mixin/client/IntegratedServerMixin.java | 12 ++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/GeyserFabricMod.java b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/GeyserFabricMod.java index dd5154267..8767df018 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/GeyserFabricMod.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/GeyserFabricMod.java @@ -26,7 +26,7 @@ package org.geysermc.platform.fabric; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import net.fabricmc.api.DedicatedServerModInitializer; +import lombok.Setter; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -55,12 +55,14 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; import java.util.*; -import java.util.function.Function; public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { private static GeyserFabricMod instance; + @Setter + private boolean reloading; + private GeyserConnector connector; private Path dataFolder; private List playerCommands; @@ -111,6 +113,7 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { } else { // Server has started and this is a reload startGeyser(this.server); + reloading = false; } } @@ -162,7 +165,9 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { connector.shutdown(); connector = null; } - this.server = null; + if (!reloading) { + this.server = null; + } } @Override diff --git a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/command/GeyserFabricCommandExecutor.java b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/command/GeyserFabricCommandExecutor.java index 1064af3a9..706ef9502 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/command/GeyserFabricCommandExecutor.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/command/GeyserFabricCommandExecutor.java @@ -31,6 +31,7 @@ import net.minecraft.server.command.ServerCommandSource; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.GeyserCommand; import org.geysermc.connector.utils.LanguageUtils; +import org.geysermc.platform.fabric.GeyserFabricMod; public class GeyserFabricCommandExecutor implements Command { @@ -55,6 +56,9 @@ public class GeyserFabricCommandExecutor implements Command sender.sendMessage(LanguageUtils.getLocaleStringLog("geyser.bootstrap.command.permission_fail")); return 0; } + if (this.commandName.equals("reload")) { + GeyserFabricMod.getInstance().setReloading(true); + } getCommand(commandName).execute(sender, new String[0]); return 0; } diff --git a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/mixin/client/IntegratedServerMixin.java b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/mixin/client/IntegratedServerMixin.java index a84f71110..5415a9d3a 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/mixin/client/IntegratedServerMixin.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/platform/fabric/mixin/client/IntegratedServerMixin.java @@ -27,11 +27,16 @@ package org.geysermc.platform.fabric.mixin.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; import net.minecraft.server.MinecraftServer; import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.text.LiteralText; import net.minecraft.world.GameMode; +import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.platform.fabric.GeyserFabricMod; import org.geysermc.platform.fabric.GeyserServerPortGetter; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -44,11 +49,18 @@ public class IntegratedServerMixin implements GeyserServerPortGetter { @Shadow private int lanPort; + @Shadow @Final private MinecraftClient client; + @Inject(method = "openToLan", at = @At("RETURN")) private void onOpenToLan(GameMode gameMode, boolean cheatsAllowed, int port, CallbackInfoReturnable cir) { if (cir.getReturnValueZ()) { // If the LAN is opened, starts Geyser. GeyserFabricMod.getInstance().startGeyser((MinecraftServer) (Object) this); + // Ensure player locale has been loaded, in case it's different from Java system language + LanguageUtils.loadGeyserLocale(this.client.options.language); + // Give indication that Geyser is loaded + this.client.player.sendMessage(new LiteralText(LanguageUtils.getPlayerLocaleString("geyser.core.start", + this.client.options.language, "localhost", String.valueOf(this.lanPort))), false); } }