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

Luke Hubmayer-Werner's avatar
Luke Hubmayer-Werner committed
13
@Command(label = "permission", usage = "permission <add|remove> <permission>", 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 (args.size() != 2) {
Secretboy's avatar
Secretboy committed
19
            CommandHandler.sendMessage(sender, translate(sender, "commands.permission.usage"));
KingRainbow44's avatar
KingRainbow44 committed
20
21
22
23
            return;
        }

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

AnimeGitB's avatar
AnimeGitB committed
26
        Account account = targetPlayer.getAccount();
KingRainbow44's avatar
KingRainbow44 committed
27
        if (account == null) {
Secretboy's avatar
Secretboy committed
28
            CommandHandler.sendMessage(sender, translate(sender, "commands.permission.account_error"));
KingRainbow44's avatar
KingRainbow44 committed
29
30
31
32
33
            return;
        }

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

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