help command changes to ensure root command does require the help command permission

This commit is contained in:
onebeastchris 2024-04-15 15:23:52 +02:00
parent f2611376c3
commit 9aa6553901
2 changed files with 10 additions and 8 deletions

View File

@ -66,7 +66,14 @@ public class HelpCommand extends GeyserCommand {
// but it's fine because the help command can be executed by non-bedrock players and by the console.
manager.command(manager.commandBuilder(rootCommand)
.apply(meta()) // shouldn't be necessary - just for consistency
.handler(this::execute));
.handler((commandContext -> {
GeyserCommandSource source = commandContext.sender();
if (!source.hasPermission(this.permission())) {
source.sendLocaleString("geyser.command.permission_fail");
return;
}
this.execute(commandContext);
})));
}
@Override
@ -74,11 +81,6 @@ public class HelpCommand extends GeyserCommand {
GeyserCommandSource source = context.sender();
boolean bedrockPlayer = source.connection() != null;
if (!source.hasPermission("geyser.command.help")) {
source.sendLocaleString("geyser.command.permission_fail");
return;
}
// todo: pagination
int page = 1;
int maxPage = 1;

View File

@ -111,7 +111,7 @@ public abstract class GeyserExtensionCommand extends GeyserCommand {
@Override
public Builder<T> permission(@NonNull String permission) {
this.permission = Objects.requireNonNull(permission, "command permission");
if (!permission.contains(".")) {
if (!permission.contains(".") && !permission.isBlank()) {
String newPermission = extension.description().id() + "." + permission;
GeyserImpl.getInstance().getLogger().error("Extension " + extension.name() + " tried to register an invalid permission (" + permission + ")." +
"Changing it to " + newPermission + "!");
@ -124,7 +124,7 @@ public abstract class GeyserExtensionCommand extends GeyserCommand {
public Builder<T> permission(@NonNull String permission, @NonNull TriState defaultValue) {
this.permission = Objects.requireNonNull(permission, "command permission");
this.permissionDefault = Objects.requireNonNull(defaultValue, "command permission defaultValue");
if (!permission.contains(".")) {
if (!permission.contains(".") && !permission.isBlank()) {
String newPermission = extension.description().id() + "." + permission;
GeyserImpl.getInstance().getLogger().error("Extension " + extension.name() + " tried to register an invalid permission (" + permission + ")." +
"Changing it to " + newPermission + "!");