UnBanCommand.java 1.18 KB
Newer Older
Yazawazi's avatar
Yazawazi committed
1
2
3
4
5
6
7
8
9
10
11
package emu.grasscutter.command.commands;

import java.util.List;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player;

@Command(
    label = "unban",
12
    usage = "unban <@player>",
Yazawazi's avatar
Yazawazi committed
13
    description = "commands.unban.description",
14
15
    permission = "server.ban",
    targetRequirement = Command.TargetRequirement.PLAYER
Yazawazi's avatar
Yazawazi committed
16
17
18
)
public final class UnBanCommand implements CommandHandler {

19
20
    private boolean unBanAccount(Player targetPlayer) {
        Account account = targetPlayer.getAccount();
Yazawazi's avatar
Yazawazi committed
21
22

        if (account == null) {
23
            return false;
Yazawazi's avatar
Yazawazi committed
24
25
26
27
28
29
30
31
32
33
34
35
36
        }

        account.setBanReason(null);
        account.setBanEndTime(0);
        account.setBanStartTime(0);
        account.setBanned(false);
        account.save();

        return true;
    }

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
37
38
        if (unBanAccount(targetPlayer)) {
            CommandHandler.sendTranslatedMessage(sender, "commands.unban.success");
Yazawazi's avatar
Yazawazi committed
39
        } else {
40
            CommandHandler.sendTranslatedMessage(sender, "commands.unban.failure");
Yazawazi's avatar
Yazawazi committed
41
42
43
        }
    }
}