Improve command registration timing on Velocity/BungeeCord (#5013)

This commit is contained in:
Konicai 2024-09-01 15:34:53 -04:00 committed by GitHub
parent 8935b34365
commit 1ab3f1f2e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 28 deletions

View file

@ -111,6 +111,21 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
if (geyser == null) {
return; // Config did not load properly!
}
// After Geyser initialize for parity with other platforms.
var sourceConverter = new CommandSourceConverter<>(
CommandSender.class,
id -> getProxy().getPlayer(id),
() -> getProxy().getConsole(),
BungeeCommandSource::new
);
CommandManager<GeyserCommandSource> cloud = new BungeeCommandManager<>(
this,
ExecutionCoordinator.simpleCoordinator(),
sourceConverter
);
this.commandRegistry = new CommandRegistry(geyser, cloud, false); // applying root permission would be a breaking change because we can't register permission defaults
// Big hack - Bungee does not provide us an event to listen to, so schedule a repeating
// task that waits for a field to be filled which is set after the plugin enable
// process is complete
@ -150,19 +165,6 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
}
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
} else {
var sourceConverter = new CommandSourceConverter<>(
CommandSender.class,
id -> getProxy().getPlayer(id),
() -> getProxy().getConsole(),
BungeeCommandSource::new
);
CommandManager<GeyserCommandSource> cloud = new BungeeCommandManager<>(
this,
ExecutionCoordinator.simpleCoordinator(),
sourceConverter
);
this.commandRegistry = new CommandRegistry(geyser, cloud, false); // applying root permission would be a breaking change because we can't register permission defaults
}
// Force-disable query if enabled, or else Geyser won't enable

View file

@ -82,6 +82,7 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
);
GeyserNeoForgeCommandRegistry registry = new GeyserNeoForgeCommandRegistry(getGeyser(), cloud);
this.setCommandRegistry(registry);
// An auxiliary listener for registering undefined permissions belonging to commands. See javadocs for more info.
NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, registry::onPermissionGatherForUndefined);
}

View file

@ -181,7 +181,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
return;
}
// Create command manager early so we can add Geyser extension commands
// Register commands after Geyser initialization, but before the server starts.
var sourceConverter = new CommandSourceConverter<>(
CommandSender.class,
Bukkit::getPlayer,

View file

@ -109,6 +109,22 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
this.geyser = GeyserImpl.load(PlatformType.VELOCITY, this);
this.geyserInjector = new GeyserVelocityInjector(proxyServer);
// We need to register commands here, rather than in onGeyserEnable which is invoked during the appropriate ListenerBoundEvent.
// Reason: players can connect after a listener is bound, and a player join locks registration to the cloud CommandManager.
var sourceConverter = new CommandSourceConverter<>(
CommandSource.class,
id -> proxyServer.getPlayer(id).orElse(null),
proxyServer::getConsoleCommandSource,
VelocityCommandSource::new
);
CommandManager<GeyserCommandSource> cloud = new VelocityCommandManager<>(
container,
proxyServer,
ExecutionCoordinator.simpleCoordinator(),
sourceConverter
);
this.commandRegistry = new CommandRegistry(geyser, cloud, false); // applying root permission would be a breaking change because we can't register permission defaults
}
@Override
@ -123,20 +139,6 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
}
this.geyserLogger.setDebug(geyserConfig.isDebugMode());
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
} else {
var sourceConverter = new CommandSourceConverter<>(
CommandSource.class,
id -> proxyServer.getPlayer(id).orElse(null),
proxyServer::getConsoleCommandSource,
VelocityCommandSource::new
);
CommandManager<GeyserCommandSource> cloud = new VelocityCommandManager<>(
container,
proxyServer,
ExecutionCoordinator.simpleCoordinator(),
sourceConverter
);
this.commandRegistry = new CommandRegistry(geyser, cloud, false); // applying root permission would be a breaking change because we can't register permission defaults
}
GeyserImpl.start();