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

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

import java.util.List;

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

AnimeGitB's avatar
AnimeGitB committed
12
13
@Command(label = "godmode", usage = "godmode [on|off|toggle]",
        description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode")
KingRainbow44's avatar
KingRainbow44 committed
14
15
16
public final class GodModeCommand 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 (targetPlayer == null) {
19
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
AnimeGitB's avatar
AnimeGitB committed
20
            return;
KingRainbow44's avatar
KingRainbow44 committed
21
        }
xtaodada's avatar
xtaodada committed
22

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

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