mirror of https://github.com/GeyserMC/Geyser.git
Bootstrap consistency: register commands after PreInitEvent, before PostInitEvent
This commit is contained in:
parent
26f53d2254
commit
065abb0550
|
@ -172,20 +172,24 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
|||
}
|
||||
|
||||
private void postStartup() {
|
||||
var sourceConverter = new CommandSourceConverter<>(
|
||||
CommandSender.class,
|
||||
id -> getProxy().getPlayer(id),
|
||||
() -> getProxy().getConsole()
|
||||
);
|
||||
CommandManager<GeyserCommandSource> cloud = new BungeeCommandManager<>(
|
||||
this,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
BungeeCommandSource::new,
|
||||
sourceConverter::convert
|
||||
);
|
||||
this.commandRegistry = new CommandRegistry(geyser, cloud);
|
||||
|
||||
GeyserImpl.start();
|
||||
|
||||
this.geyserInjector = new GeyserBungeeInjector(this);
|
||||
this.geyserInjector.initializeLocalChannel(this);
|
||||
|
||||
var sourceConverter = new CommandSourceConverter<>(CommandSender.class, id -> getProxy().getPlayer(id), () -> getProxy().getConsole());
|
||||
CommandManager<GeyserCommandSource> cloud = new BungeeCommandManager<>(
|
||||
this,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
BungeeCommandSource::new,
|
||||
sourceConverter::convert
|
||||
);
|
||||
this.commandRegistry = new CommandRegistry(geyser, cloud);
|
||||
|
||||
if (geyserConfig.isLegacyPingPassthrough()) {
|
||||
this.geyserBungeePingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||
} else {
|
||||
|
|
|
@ -134,7 +134,7 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
|||
CommandSourceStack.class,
|
||||
id -> server.getPlayerList().getPlayer(id),
|
||||
Player::createCommandSourceStack,
|
||||
() -> server.createCommandSourceStack() // note: method reference here will cause NPE
|
||||
() -> server.createCommandSourceStack() // NPE if method reference is used, since server is not available yet
|
||||
);
|
||||
CommandManager<GeyserCommandSource> cloud = new FabricServerCommandManager<>(
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
|
|
|
@ -218,11 +218,14 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
|
|||
logger.get().setLevel(geyserConfig.isDebugMode() ? Level.DEBUG : Level.INFO);
|
||||
|
||||
geyser = GeyserImpl.load(PlatformType.STANDALONE, this);
|
||||
GeyserImpl.start();
|
||||
|
||||
// fire GeyserDefineCommandsEvent after PreInitEvent, before PostInitEvent, for consistency with other bootstraps
|
||||
GeyserStandaloneCommandManager cloud = new GeyserStandaloneCommandManager(geyser);
|
||||
commandRegistry = new CommandRegistry(geyser, cloud);
|
||||
cloud.gatherPermissions();
|
||||
|
||||
GeyserImpl.start();
|
||||
|
||||
cloud.gatherPermissions(); // event must be fired after CommandRegistry has subscribed its listener
|
||||
|
||||
if (gui != null) {
|
||||
gui.enableCommands(geyser.getScheduledThread(), commandRegistry);
|
||||
|
|
|
@ -75,7 +75,6 @@ public class GeyserStandaloneCommandManager extends CommandManager<GeyserCommand
|
|||
* Fire a {@link GeyserRegisterPermissionsEvent} to determine any additions or removals to the base list of
|
||||
* permissions. This should be called after any event listeners have been registered, such as that of {@link CommandRegistry}.
|
||||
*/
|
||||
// todo: doesn't seem like CommandRegistry has a listener anymore? should it? i forget.
|
||||
public void gatherPermissions() {
|
||||
geyser.getEventBus().fire((GeyserRegisterPermissionsEvent) (permission, def) -> {
|
||||
if (def == TriState.TRUE) {
|
||||
|
|
|
@ -130,21 +130,25 @@ public class GeyserVelocityPlugin implements GeyserBootstrap {
|
|||
}
|
||||
|
||||
private void postStartup() {
|
||||
GeyserImpl.start();
|
||||
|
||||
this.geyserInjector = new GeyserVelocityInjector(proxyServer);
|
||||
// Will be initialized after the proxy has been bound
|
||||
|
||||
var sourceConverter = new CommandSourceConverter<>(CommandSource.class, id -> proxyServer.getPlayer(id).orElse(null), proxyServer::getConsoleCommandSource);
|
||||
var sourceConverter = new CommandSourceConverter<>(
|
||||
CommandSource.class,
|
||||
id -> proxyServer.getPlayer(id).orElse(null),
|
||||
proxyServer::getConsoleCommandSource
|
||||
);
|
||||
CommandManager<GeyserCommandSource> cloud = new VelocityCommandManager<>(
|
||||
container,
|
||||
proxyServer,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
VelocityCommandSource::new,
|
||||
sourceConverter::convert
|
||||
container,
|
||||
proxyServer,
|
||||
CommandExecutionCoordinator.simpleCoordinator(),
|
||||
VelocityCommandSource::new,
|
||||
sourceConverter::convert
|
||||
);
|
||||
this.commandRegistry = new CommandRegistry(geyser, cloud);
|
||||
|
||||
GeyserImpl.start();
|
||||
|
||||
// Will be initialized after the proxy has been bound
|
||||
this.geyserInjector = new GeyserVelocityInjector(proxyServer);
|
||||
|
||||
if (geyserConfig.isLegacyPingPassthrough()) {
|
||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||
} else {
|
||||
|
|
|
@ -120,7 +120,7 @@ public class CommandRegistry {
|
|||
registerExtensionCommand(entry.getKey(), new HelpCommand(this.geyser, "help", "geyser.commands.exthelp.desc", "geyser.command.exthelp." + id, id, entry.getValue()));
|
||||
}
|
||||
|
||||
// wait for the right moment to register permissions
|
||||
// wait for the right moment (depends on the platform) to register permissions
|
||||
geyser.eventBus().subscribe(new GeyserEventRegistrar(this), GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue