mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Only initialize commands once on Geyser-Standalone
This commit is contained in:
parent
30aa88e2f0
commit
cc94227b6e
3 changed files with 20 additions and 18 deletions
|
|
@ -223,14 +223,15 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
|
|||
|
||||
geyser = GeyserImpl.load(PlatformType.STANDALONE, this);
|
||||
|
||||
if (!geyser.isReloading()) {
|
||||
// fire GeyserDefineCommandsEvent after PreInitEvent, before PostInitEvent, for consistency with other bootstraps
|
||||
StandaloneCloudCommandManager cloud = new StandaloneCloudCommandManager(geyser);
|
||||
commandRegistry = new CommandRegistry(geyser, cloud);
|
||||
cloud.fireRegisterPermissionsEvent(); // event must be fired after CommandRegistry has subscribed its listener
|
||||
}
|
||||
|
||||
GeyserImpl.start();
|
||||
|
||||
cloud.gatherPermissions(); // event must be fired after CommandRegistry has subscribed its listener
|
||||
|
||||
if (gui != null) {
|
||||
gui.enableCommands(geyser.getScheduledThread(), commandRegistry);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import org.geysermc.geyser.Constants;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.command.Command;
|
||||
import org.geysermc.geyser.api.event.EventRegistrar;
|
||||
import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCommandsEvent;
|
||||
import org.geysermc.geyser.api.event.lifecycle.GeyserRegisterPermissionsEvent;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
|
|
@ -48,7 +49,6 @@ import org.geysermc.geyser.command.defaults.SettingsCommand;
|
|||
import org.geysermc.geyser.command.defaults.StatisticsCommand;
|
||||
import org.geysermc.geyser.command.defaults.StopCommand;
|
||||
import org.geysermc.geyser.command.defaults.VersionCommand;
|
||||
import org.geysermc.geyser.event.GeyserEventRegistrar;
|
||||
import org.geysermc.geyser.event.type.GeyserDefineCommandsEventImpl;
|
||||
import org.geysermc.geyser.extension.command.GeyserExtensionCommand;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
|
@ -59,7 +59,16 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandRegistry {
|
||||
/**
|
||||
* Registers all built-in and extension commands to the given Cloud CommandManager.
|
||||
* <p>
|
||||
* Fires {@link GeyserDefineCommandsEvent} upon construction.
|
||||
* <p>
|
||||
* Subscribes to {@link GeyserRegisterPermissionsEvent} upon construction.
|
||||
* A new instance of this class (that registers the same permissions) shouldn't be created until the previous
|
||||
* instance is unsubscribed from the event.
|
||||
*/
|
||||
public class CommandRegistry implements EventRegistrar {
|
||||
|
||||
private final GeyserImpl geyser;
|
||||
private final CommandManager<GeyserCommandSource> cloud;
|
||||
|
|
@ -143,7 +152,7 @@ public class CommandRegistry {
|
|||
}
|
||||
|
||||
// wait for the right moment (depends on the platform) to register permissions
|
||||
geyser.eventBus().subscribe(new GeyserEventRegistrar(this), GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions);
|
||||
geyser.eventBus().subscribe(this, GeyserRegisterPermissionsEvent.class, this::onRegisterPermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ import org.geysermc.geyser.util.FileUtils;
|
|||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.execution.ExecutionCoordinator;
|
||||
import org.incendo.cloud.internal.CommandRegistrationHandler;
|
||||
import org.incendo.cloud.meta.CommandMeta;
|
||||
import org.incendo.cloud.meta.SimpleCommandMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -84,7 +82,7 @@ public class StandaloneCloudCommandManager extends CommandManager<GeyserCommandS
|
|||
* 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}.
|
||||
*/
|
||||
public void gatherPermissions() {
|
||||
public void fireRegisterPermissionsEvent() {
|
||||
geyser.getEventBus().fire((GeyserRegisterPermissionsEvent) (permission, def) -> {
|
||||
if (permission.isBlank()) {
|
||||
return;
|
||||
|
|
@ -114,13 +112,7 @@ public class StandaloneCloudCommandManager extends CommandManager<GeyserCommandS
|
|||
// undefined - try the next checker to see if it has a defined value
|
||||
}
|
||||
// fallback to our list of default permissions
|
||||
// note that a PermissionChecker may in fact override any values set here by return FALSE
|
||||
// note that a PermissionChecker may in fact override any values set here by returning FALSE
|
||||
return basePermissions.contains(permission);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CommandMeta createDefaultCommandMeta() {
|
||||
return SimpleCommandMeta.empty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue