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