From 32289e2d8084829f4b478c4ae721d6a700253772 Mon Sep 17 00:00:00 2001 From: jie65535 Date: Sat, 27 Aug 2022 19:46:27 +0800 Subject: [PATCH] Add permission clear and list commands (#1715) * Add permission clear and list commands * Add Account clear permission --- .../command/commands/PermissionCommand.java | 25 ++++++++++++++++--- .../java/emu/grasscutter/game/Account.java | 4 +++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java index bc59df140..f3e074599 100644 --- a/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java @@ -11,12 +11,17 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "permission", usage = "(add|remove) ", permission = "permission", targetRequirement = TargetRequirement.PLAYER) +@Command(label = "permission", usage = { + "add ", + "remove ", + "clear", + "list" +}, permission = "permission", targetRequirement = TargetRequirement.PLAYER) public final class PermissionCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - if (args.size() != 2) { + if (args.isEmpty() || args.size() > 2) { sendUsageMessage(sender); return; } @@ -27,7 +32,10 @@ public final class PermissionCommand implements CommandHandler { } String action = args.get(0); - String permission = args.get(1); + String permission = ""; + if (args.size() > 1) { + permission = args.get(1); + } Account account = targetPlayer.getAccount(); if (account == null) { @@ -40,7 +48,9 @@ public final class PermissionCommand implements CommandHandler { sendUsageMessage(sender); break; case "add": - if (account.addPermission(permission)) { + if (permission.isEmpty()) { + sendUsageMessage(sender); + } else if (account.addPermission(permission)) { CommandHandler.sendMessage(sender, translate(sender, "commands.permission.add")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.has_error")); break; @@ -49,6 +59,13 @@ public final class PermissionCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(sender, "commands.permission.remove")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.not_have_error")); break; + case "clear": + account.clearPermission(); + CommandHandler.sendMessage(sender, translate(sender, "commands.permission.remove")); + break; + case "list": + CommandHandler.sendMessage(sender, String.join("\n", account.getPermissions())); + break; } account.save(); diff --git a/src/main/java/emu/grasscutter/game/Account.java b/src/main/java/emu/grasscutter/game/Account.java index bdbb94cb1..21633b4b7 100644 --- a/src/main/java/emu/grasscutter/game/Account.java +++ b/src/main/java/emu/grasscutter/game/Account.java @@ -210,6 +210,10 @@ public class Account { return this.permissions.remove(permission); } + public void clearPermission() { + this.permissions.clear(); + } + // TODO make unique public String generateLoginToken() { this.token = Utils.bytesToHex(Crypto.createSessionKey(32));