PermissionCommand.java 2.08 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;

方块君's avatar
方块君 committed
13
@Command(label = "permission", usage = "permission <add|remove> <permission>", permission = "*", description = "commands.permission.description")
KingRainbow44's avatar
KingRainbow44 committed
14
15
16
public final class PermissionCommand implements CommandHandler {

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

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

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

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

        account.save();
    }
Secretboy's avatar
Secretboy committed
55
}