Getting server IP now works

This commit is contained in:
DoctorMacc 2020-10-06 14:11:27 -04:00
parent be07a47f9f
commit 6ccde86057

View file

@ -30,6 +30,8 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.util.registry.Registry;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.GeyserLogger; import org.geysermc.connector.GeyserLogger;
@ -38,6 +40,7 @@ import org.geysermc.connector.command.CommandManager;
import org.geysermc.connector.common.PlatformType; import org.geysermc.connector.common.PlatformType;
import org.geysermc.connector.configuration.GeyserConfiguration; import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.dump.BootstrapDumpInfo; import org.geysermc.connector.dump.BootstrapDumpInfo;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough; import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
import org.geysermc.connector.ping.IGeyserPingPassthrough; import org.geysermc.connector.ping.IGeyserPingPassthrough;
import org.geysermc.connector.utils.FileUtils; import org.geysermc.connector.utils.FileUtils;
@ -85,30 +88,31 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
this.geyserConfig.setAutoconfiguredRemote(true); // Required to do this so we can get the proper IP and port if needed
ServerLifecycleEvents.SERVER_STARTING.register((server) -> { if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true);
String ip = server.getServerIp(); String ip = server.getServerIp();
int port = server.getServerPort(); int port = server.getServerPort();
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) { if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
this.geyserConfig.getRemote().setAddress(ip); this.geyserConfig.getRemote().setAddress(ip);
} }
this.geyserConfig.getRemote().setPort(port); this.geyserConfig.getRemote().setPort(port);
}); }
}
if (geyserConfig.getBedrock().isCloneRemotePort()) { if (geyserConfig.getBedrock().isCloneRemotePort()) {
geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort()); geyserConfig.getBedrock().setPort(geyserConfig.getRemote().getPort());
} }
this.connector = GeyserConnector.start(PlatformType.ANDROID, this); this.connector = GeyserConnector.start(PlatformType.ANDROID, this);
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
this.geyserCommandManager = new GeyserFabricCommandManager(connector);
});
// Register onDisable so players are properly kicked // Register onDisable so players are properly kicked
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable()); ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
this.geyserCommandManager = new GeyserFabricCommandManager(connector);
} }
@Override @Override