fix bot command register
This commit is contained in:
+1
-1
@@ -70,7 +70,7 @@ public class FakePlayerCompatConfig implements IConfigModule {
|
||||
|
||||
@Override
|
||||
public void onLoaded(CommentedFileConfig configInstance, @Nullable Set<Exception> exs) {
|
||||
if (commandPlayer) {
|
||||
if (commandPlayer && command == null) {
|
||||
command = new BotCommand("player");
|
||||
command.register();
|
||||
}
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class FakeplayerConfig implements IConfigModule {
|
||||
|
||||
@Override
|
||||
public void onLoaded(CommentedFileConfig configInstance, @Nullable Set<Exception> exs) {
|
||||
if (enable) {
|
||||
if (enable && command == null) {
|
||||
command = new BotCommand("bot");
|
||||
command.register();
|
||||
}
|
||||
|
||||
@@ -27,10 +27,11 @@ import org.leavesmc.leaves.command.bot.subcommands.*;
|
||||
import static org.leavesmc.leaves.command.CommandUtils.registerPermissions;
|
||||
|
||||
public class BotCommand extends RootNode {
|
||||
private static final String PERM_BASE = "bukkit.command.bot";
|
||||
private static final String PERM_BASE_BOT = "bukkit.command.bot";
|
||||
private static final String PERM_BASE_PLAYER = "bukkit.command.player";
|
||||
|
||||
public BotCommand(String key) {
|
||||
super(key, PERM_BASE);
|
||||
super(key, getPermBase(key));
|
||||
this.children(
|
||||
ListCommand::new,
|
||||
ConfigCommand::new,
|
||||
@@ -44,15 +45,26 @@ public class BotCommand extends RootNode {
|
||||
|
||||
@Override
|
||||
protected ArgumentBuilder<CommandSourceStack, ?> compile() {
|
||||
registerPermissions(PERM_BASE, this.children);
|
||||
registerPermissions(getPermBase(this.getName()), this.children);
|
||||
return super.compile();
|
||||
}
|
||||
|
||||
public static boolean hasPermission(@NotNull CommandSender sender) {
|
||||
return sender.hasPermission(PERM_BASE);
|
||||
return sender.hasPermission(PERM_BASE_BOT) || sender.hasPermission(PERM_BASE_PLAYER);
|
||||
}
|
||||
|
||||
public static boolean hasPermission(@NotNull CommandSender sender, String subcommand) {
|
||||
return sender.hasPermission(PERM_BASE) || sender.hasPermission(PERM_BASE + "." + subcommand);
|
||||
return sender.hasPermission(PERM_BASE_BOT) || sender.hasPermission(PERM_BASE_BOT + "." + subcommand)
|
||||
|| sender.hasPermission(PERM_BASE_PLAYER) || sender.hasPermission(PERM_BASE_PLAYER + "." + subcommand);
|
||||
}
|
||||
|
||||
public static String getPermBase(String key) {
|
||||
if (key.equals("bot")) {
|
||||
return PERM_BASE_BOT;
|
||||
}
|
||||
if (key.equals("player")) {
|
||||
return PERM_BASE_PLAYER;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid key: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user