Ensure proper Geyser starting/disabling when Geyser is used on a client (#4621)

* Ensure proper Geyser starting/disabling when Geyser is used on a client

* also set correct remote port

* only use direct connection on server, not client, actually override remote port
This commit is contained in:
chris 2024-05-02 00:29:33 +02:00 committed by GitHub
parent 9cb9a1450e
commit 1291b89e64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 9 deletions

View file

@ -58,6 +58,7 @@ import org.geysermc.geyser.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketAddress;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
@ -127,7 +128,9 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
// We want to do this late in the server startup process to allow other mods
// To do their job injecting, then connect into *that*
this.geyserInjector = new GeyserModInjector(server, this.platform);
this.geyserInjector.initializeLocalChannel(this);
if (isServer()) {
this.geyserInjector.initializeLocalChannel(this);
}
// Start command building
// Set just "geyser" as the help command
@ -242,7 +245,19 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
@Override
public int getServerPort() {
return ((GeyserServerPortGetter) server).geyser$getServerPort();
if (isServer()) {
return ((GeyserServerPortGetter) server).geyser$getServerPort();
} else {
// Set in the IntegratedServerMixin
return geyserConfig.getRemote().port();
}
}
public abstract boolean isServer();
@Override
public @Nullable SocketAddress getSocketAddress() {
return this.geyserInjector.getServerSocketAddress();
}
@Override

View file

@ -54,8 +54,10 @@ public class IntegratedServerMixin implements GeyserServerPortGetter {
private void onOpenToLan(GameType gameType, boolean cheatsAllowed, int port, CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValueZ()) {
// If the LAN is opened, starts Geyser.
GeyserModBootstrap.getInstance().setServer((MinecraftServer) (Object) this);
GeyserModBootstrap.getInstance().onGeyserEnable();
GeyserModBootstrap instance = GeyserModBootstrap.getInstance();
instance.setServer((MinecraftServer) (Object) this);
instance.getGeyserConfig().getRemote().setPort(port);
instance.onGeyserEnable();
// Ensure player locale has been loaded, in case it's different from Java system language
GeyserLocale.loadGeyserLocale(this.minecraft.options.languageCode);
// Give indication that Geyser is loaded