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

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
Melledy's avatar
Melledy committed
5
import emu.grasscutter.game.player.Player;
KingRainbow44's avatar
KingRainbow44 committed
6
7
8

import java.util.List;

9
10
import static emu.grasscutter.utils.Language.translate;

11
@Command(label = "godmode", usage = "godmode [on|off|toggle]", permission = "player.godmode", permissionTargeted = "player.godmode.others", description = "commands.godmode.description")
KingRainbow44's avatar
KingRainbow44 committed
12
13
14
public final class GodModeCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
15
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
16
        if (targetPlayer == null) {
Secretboy's avatar
Secretboy committed
17
            CommandHandler.sendMessage(sender, translate(sender, "commands.execution.need_target"));
AnimeGitB's avatar
AnimeGitB committed
18
            return;
KingRainbow44's avatar
KingRainbow44 committed
19
        }
xtaodada's avatar
xtaodada committed
20

AnimeGitB's avatar
AnimeGitB committed
21
        boolean enabled = !targetPlayer.inGodmode();
xtaodada's avatar
xtaodada committed
22
        if (args.size() == 1) {
AnimeGitB's avatar
AnimeGitB committed
23
24
25
26
27
28
29
30
31
32
            switch (args.get(0).toLowerCase()) {
                case "on":
                    enabled = true;
                    break;
                case "off":
                    enabled = false;
                    break;
                case "toggle":
                    break;  // Already toggled
                default:
33
                    break;
xtaodada's avatar
xtaodada committed
34
35
36
            }
        }

AnimeGitB's avatar
AnimeGitB committed
37
        targetPlayer.setGodmode(enabled);
Secretboy's avatar
Secretboy committed
38
        CommandHandler.sendMessage(sender, translate(sender, "commands.godmode.success", (enabled ? translate(sender, "commands.status.enabled") : translate(sender, "commands.status.disabled")), targetPlayer.getNickname()));
KingRainbow44's avatar
KingRainbow44 committed
39
40
    }
}