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

41 lines
1.5 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;
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;
2022-05-04 17:16:42 +08:00
@Command(label = "godmode", usage = "godmode [on|off|toggle]",
description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode")
2022-04-21 06:48:24 +08:00
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-05-04 17:16:42 +08:00
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return;
2022-04-21 06:48:24 +08:00
}
2022-04-24 11:40:10 +08:00
2022-05-04 17:16:42 +08:00
boolean enabled = !targetPlayer.inGodmode();
2022-04-24 11:40:10 +08:00
if (args.size() == 1) {
2022-05-04 17:16:42 +08:00
switch (args.get(0).toLowerCase()) {
case "on":
enabled = true;
break;
case "off":
enabled = false;
break;
case "toggle":
break; // Already toggled
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status);
2022-04-24 11:40:10 +08:00
}
}
2022-05-04 17:16:42 +08:00
targetPlayer.setGodmode(enabled);
2022-05-05 13:03:08 +08:00
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status.replace("{status}", (enabled ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname()));
2022-04-21 06:48:24 +08:00
}
}