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;
|
2022-04-27 12:24:25 +08:00
|
|
|
import emu.grasscutter.game.player.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
|
2022-05-04 14:32:09 +08:00
|
|
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
2022-04-21 06:48:24 +08:00
|
|
|
if (sender == null) {
|
2022-05-03 14:23:25 +08:00
|
|
|
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
2022-04-21 06:48:24 +08:00
|
|
|
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) {
|
2022-05-03 14:23:25 +08:00
|
|
|
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
|
2022-04-24 11:40:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target = sender.getUid();
|
|
|
|
}
|
|
|
|
if (targetPlayer == null) {
|
2022-05-03 14:23:25 +08:00
|
|
|
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
2022-04-24 11:40:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
targetPlayer.setGodmode(!targetPlayer.inGodmode());
|
2022-05-04 11:17:31 +08:00
|
|
|
sender.dropMessage(Grasscutter.getLanguage().Godmode_status.replace("{status}", (targetPlayer.inGodmode() ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname()));
|
2022-04-21 06:48:24 +08:00
|
|
|
}
|
|
|
|
}
|