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 { stages {
stage ('Build') { stage ('Build') {
steps { steps {
sh './gradlew clean build' sh './gradlew clean build --refresh-dependencies'
} }
post { post {
success { success {

View file

@ -97,9 +97,27 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger); 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) -> { ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
// Required to do this so we can get the proper IP and port if needed
this.server = server; 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")) { if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true); this.geyserConfig.setAutoconfiguredRemote(true);
String ip = server.getServerIp(); String ip = server.getServerIp();
@ -131,16 +149,13 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
!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;
} }
} }