Fix reloading Geyser

This commit is contained in:
DoctorMacc 2020-10-11 23:15:22 -04:00
parent 856ce6b588
commit c426c335d7
2 changed files with 48 additions and 33 deletions

View file

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

View file

@ -97,9 +97,27 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
if (server == null) {
// Server has yet to start
// Set as an event so we can get the proper IP and port if needed
ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
// Required to do this so we can get the proper IP and port if needed
this.server = server;
startGeyser();
});
// Register onDisable so players are properly kicked
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
} 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();
@ -131,16 +149,13 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
!playerCommands.contains(command.getKey()))));
}
server.getCommandManager().getDispatcher().register(builder);
});
// Register onDisable so players are properly kicked
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
}
@Override
public void onDisable() {
if (connector != null) {
connector.shutdown();
connector = null;
}
}