PermissionCommand.java 2.03 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
3
4
5
6
package emu.grasscutter.command.commands;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.Account;
Melledy's avatar
Melledy committed
7
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
8
9
10

import java.util.List;

11
12
import static emu.grasscutter.utils.Language.translate;

AnimeGitB's avatar
AnimeGitB committed
13
@Command(label = "permission", usage = "permission <add|remove> <permission>",
KingRainbow44's avatar
KingRainbow44 committed
14
15
16
17
        description = "Grants or removes a permission for a user", permission = "*")
public final class PermissionCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
18
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
19
        if (targetPlayer == null) {
20
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
AnimeGitB's avatar
AnimeGitB committed
21
22
23
24
            return;
        }
        
        if (args.size() != 2) {
25
            CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
KingRainbow44's avatar
KingRainbow44 committed
26
27
28
29
            return;
        }

        String action = args.get(0);
AnimeGitB's avatar
AnimeGitB committed
30
        String permission = args.get(1);
KingRainbow44's avatar
KingRainbow44 committed
31

AnimeGitB's avatar
AnimeGitB committed
32
        Account account = targetPlayer.getAccount();
KingRainbow44's avatar
KingRainbow44 committed
33
        if (account == null) {
34
            CommandHandler.sendMessage(sender, translate("commands.permission.account_error"));
KingRainbow44's avatar
KingRainbow44 committed
35
36
37
38
39
            return;
        }

        switch (action) {
            default:
40
                CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
KingRainbow44's avatar
KingRainbow44 committed
41
42
43
                break;
            case "add":
                if (account.addPermission(permission)) {
44
45
                    CommandHandler.sendMessage(sender, translate("commands.permission.add"));
                } else CommandHandler.sendMessage(sender, translate("commands.permission.has_error"));
KingRainbow44's avatar
KingRainbow44 committed
46
47
48
                break;
            case "remove":
                if (account.removePermission(permission)) {
49
50
                    CommandHandler.sendMessage(sender, translate("commands.permission.remove"));
                } else CommandHandler.sendMessage(sender, translate("commands.permission.not_have_error"));
KingRainbow44's avatar
KingRainbow44 committed
51
52
53
54
55
                break;
        }

        account.save();
    }
Jaida Wu's avatar
Jaida Wu committed
56
}