3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-10-08 10:50:11 +02:00

Fix reloading Geyser

Dieser Commit ist enthalten in:
DoctorMacc 2020-10-11 23:15:22 -04:00
Ursprung 856ce6b588
Commit c426c335d7
2 geänderte Dateien mit 48 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -9,7 +9,7 @@ pipeline {
stages { stages {
stage ('Build') { stage ('Build') {
steps { steps {
sh './gradlew clean build' sh './gradlew clean build --refresh-dependencies'
} }
post { post {
success { success {

Datei anzeigen

@ -97,50 +97,65 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
ServerLifecycleEvents.SERVER_STARTED.register((server) -> { if (server == null) {
// Required to do this so we can get the proper IP and port if needed // Server has yet to start
this.server = server; // Set as an event so we can get the proper IP and port if needed
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) { ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
this.geyserConfig.setAutoconfiguredRemote(true); this.server = server;
String ip = server.getServerIp(); startGeyser();
int port = server.getServerPort(); });
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
this.geyserConfig.getRemote().setAddress(ip); // Register onDisable so players are properly kicked
} ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
this.geyserConfig.getRemote().setPort(port); } else {
// Server has started and this is a reload
startGeyser();
}
}
/**
* Initialize core Geyser.
* A function, as it needs to be called in different places depending on if Geyser is being reloaded or not.
*/
public void startGeyser() {
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true);
String ip = server.getServerIp();
int port = server.getServerPort();
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
this.geyserConfig.getRemote().setAddress(ip);
} }
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.FABRIC, this); this.connector = GeyserConnector.start(PlatformType.FABRIC, this);
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector); this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
this.geyserCommandManager = new GeyserFabricCommandManager(connector); this.geyserCommandManager = new GeyserFabricCommandManager(connector);
// Start command building // Start command building
// Set just "geyser" as the help command // Set just "geyser" as the help command
LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser") LiteralArgumentBuilder<ServerCommandSource> builder = net.minecraft.server.command.CommandManager.literal("geyser")
.executes(new GeyserFabricCommandExecutor(connector, "help", !playerCommands.contains("help"))); .executes(new GeyserFabricCommandExecutor(connector, "help", !playerCommands.contains("help")));
for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) { for (Map.Entry<String, GeyserCommand> command : connector.getCommandManager().getCommands().entrySet()) {
// Register all subcommands as valid // Register all subcommands as valid
builder.then(net.minecraft.server.command.CommandManager.literal( builder.then(net.minecraft.server.command.CommandManager.literal(
command.getKey()).executes(new GeyserFabricCommandExecutor(connector, command.getKey(), command.getKey()).executes(new GeyserFabricCommandExecutor(connector, command.getKey(),
!playerCommands.contains(command.getKey())))); !playerCommands.contains(command.getKey()))));
} }
server.getCommandManager().getDispatcher().register(builder); server.getCommandManager().getDispatcher().register(builder);
});
// Register onDisable so players are properly kicked
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
} }
@Override @Override
public void onDisable() { public void onDisable() {
if (connector != null) { if (connector != null) {
connector.shutdown(); connector.shutdown();
connector = null;
} }
} }