PermissionCommand.java 2.21 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 = "permission <add|remove> <permission>", permission = "permission", description = "commands.permission.description", 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) {
Secretboy's avatar
Secretboy committed
20
            CommandHandler.sendMessage(sender, translate(sender, "commands.permission.usage"));
KingRainbow44's avatar
KingRainbow44 committed
21
22
23
            return;
        }

4Benj_'s avatar
4Benj_ committed
24
25
26
27
28
        if(!Grasscutter.getPermissionHandler().EnablePermissionCommand()) {
            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:
Secretboy's avatar
Secretboy committed
40
                CommandHandler.sendMessage(sender, translate(sender, "commands.permission.usage"));
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
}