Grasscutter/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java

46 lines
1.6 KiB
Java
Raw Normal View History

2022-04-21 06:48:24 +08:00
package emu.grasscutter.command.commands;
2022-04-24 11:40:10 +08:00
import emu.grasscutter.Grasscutter;
2022-04-21 06:48:24 +08:00
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.Player;
2022-04-21 06:48:24 +08:00
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
public void execute(Player sender, List<String> args) {
2022-04-21 06:48:24 +08:00
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
return; // TODO: toggle player's godmode statue from console or other players
}
2022-04-24 11:40:10 +08:00
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();
}
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
2022-04-24 11:40:10 +08:00
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() + " .");
2022-04-21 06:48:24 +08:00
}
}