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

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

import java.util.List;

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

14
@Command(label = "permission", usage = "(add|remove) <permission>", permission = "permission", targetRequirement = TargetRequirement.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
15
16
17
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 (args.size() != 2) {
20
            sendUsageMessage(sender);
KingRainbow44's avatar
KingRainbow44 committed
21
22
23
            return;
        }

github-actions's avatar
github-actions committed
24
        if (!Grasscutter.getPermissionHandler().EnablePermissionCommand()) {
4Benj_'s avatar
4Benj_ committed
25
26
27
28
            CommandHandler.sendTranslatedMessage(sender, "commands.generic.permission_error");
            return;
        }

KingRainbow44's avatar
KingRainbow44 committed
29
        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) {
Secretboy's avatar
Secretboy committed
34
            CommandHandler.sendMessage(sender, translate(sender, "commands.permission.account_error"));
KingRainbow44's avatar
KingRainbow44 committed
35
36
37
38
39
            return;
        }

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

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