Unverified Commit 32289e2d authored by jie65535's avatar jie65535 Committed by GitHub
Browse files

Add permission clear and list commands (#1715)

* Add permission clear and list commands

* Add Account clear permission
parent 656cb79b
...@@ -11,12 +11,17 @@ import java.util.List; ...@@ -11,12 +11,17 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "permission", usage = "(add|remove) <permission>", permission = "permission", targetRequirement = TargetRequirement.PLAYER) @Command(label = "permission", usage = {
"add <permission>",
"remove <permission>",
"clear",
"list"
}, permission = "permission", targetRequirement = TargetRequirement.PLAYER)
public final class PermissionCommand implements CommandHandler { public final class PermissionCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() != 2) { if (args.isEmpty() || args.size() > 2) {
sendUsageMessage(sender); sendUsageMessage(sender);
return; return;
} }
...@@ -27,7 +32,10 @@ public final class PermissionCommand implements CommandHandler { ...@@ -27,7 +32,10 @@ public final class PermissionCommand implements CommandHandler {
} }
String action = args.get(0); String action = args.get(0);
String permission = args.get(1); String permission = "";
if (args.size() > 1) {
permission = args.get(1);
}
Account account = targetPlayer.getAccount(); Account account = targetPlayer.getAccount();
if (account == null) { if (account == null) {
...@@ -40,7 +48,9 @@ public final class PermissionCommand implements CommandHandler { ...@@ -40,7 +48,9 @@ public final class PermissionCommand implements CommandHandler {
sendUsageMessage(sender); sendUsageMessage(sender);
break; break;
case "add": case "add":
if (account.addPermission(permission)) { if (permission.isEmpty()) {
sendUsageMessage(sender);
} else if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, translate(sender, "commands.permission.add")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.add"));
} else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.has_error")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.has_error"));
break; break;
...@@ -49,6 +59,13 @@ public final class PermissionCommand implements CommandHandler { ...@@ -49,6 +59,13 @@ public final class PermissionCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.permission.remove")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.remove"));
} else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.not_have_error")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.not_have_error"));
break; 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(); account.save();
......
...@@ -210,6 +210,10 @@ public class Account { ...@@ -210,6 +210,10 @@ public class Account {
return this.permissions.remove(permission); return this.permissions.remove(permission);
} }
public void clearPermission() {
this.permissions.clear();
}
// TODO make unique // TODO make unique
public String generateLoginToken() { public String generateLoginToken() {
this.token = Utils.bytesToHex(Crypto.createSessionKey(32)); this.token = Utils.bytesToHex(Crypto.createSessionKey(32));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment