GodModeCommand.java 1.63 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
10
11
12
13
14

import java.util.List;

@Command(label = "godmode", usage = "godmode [playerId]",
        description = "Prevents you from taking damage", permission = "player.godmode")
public final class GodModeCommand implements CommandHandler {

    @Override
15
    public void execute(Player sender, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
16
17
18
19
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
            return; // TODO: toggle player's godmode statue from console or other players
        }
xtaodada's avatar
xtaodada committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

        int target;
        if (args.size() == 1) {
            try {
                target = Integer.parseInt(args.get(0));
                if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                    target = sender.getUid();
                }
            } catch (NumberFormatException e) {
                CommandHandler.sendMessage(sender, "Invalid player id.");
                return;
            }
        } else {
            target = sender.getUid();
        }
35
        Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
xtaodada's avatar
xtaodada committed
36
37
38
39
40
41
42
43
        if (targetPlayer == null) {
            CommandHandler.sendMessage(sender, "Player not found.");
            return;
        }

        targetPlayer.setGodmode(!targetPlayer.inGodmode());
        sender.dropMessage("Godmode is now " + (targetPlayer.inGodmode() ? "enabled" : "disabled") +
                "for " + targetPlayer.getNickname() + " .");
KingRainbow44's avatar
KingRainbow44 committed
44
45
    }
}