mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Added a command to manipulate health
This commit is contained in:
parent
654cc6bb19
commit
a6f9e649ff
2 changed files with 77 additions and 0 deletions
|
@ -17,6 +17,7 @@ import brainwine.gameserver.command.commands.EntityCommand;
|
||||||
import brainwine.gameserver.command.commands.ExportCommand;
|
import brainwine.gameserver.command.commands.ExportCommand;
|
||||||
import brainwine.gameserver.command.commands.GenerateZoneCommand;
|
import brainwine.gameserver.command.commands.GenerateZoneCommand;
|
||||||
import brainwine.gameserver.command.commands.GiveCommand;
|
import brainwine.gameserver.command.commands.GiveCommand;
|
||||||
|
import brainwine.gameserver.command.commands.HealthCommand;
|
||||||
import brainwine.gameserver.command.commands.HelpCommand;
|
import brainwine.gameserver.command.commands.HelpCommand;
|
||||||
import brainwine.gameserver.command.commands.ImportCommand;
|
import brainwine.gameserver.command.commands.ImportCommand;
|
||||||
import brainwine.gameserver.command.commands.KickCommand;
|
import brainwine.gameserver.command.commands.KickCommand;
|
||||||
|
@ -71,6 +72,7 @@ public class CommandManager {
|
||||||
registerCommand(new PositionCommand());
|
registerCommand(new PositionCommand());
|
||||||
registerCommand(new RickrollCommand());
|
registerCommand(new RickrollCommand());
|
||||||
registerCommand(new EntityCommand());
|
registerCommand(new EntityCommand());
|
||||||
|
registerCommand(new HealthCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void executeCommand(CommandExecutor executor, String commandLine) {
|
public static void executeCommand(CommandExecutor executor, String commandLine) {
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
package brainwine.gameserver.command.commands;
|
||||||
|
|
||||||
|
import static brainwine.gameserver.entity.player.NotificationType.ALERT;
|
||||||
|
|
||||||
|
import brainwine.gameserver.GameServer;
|
||||||
|
import brainwine.gameserver.command.Command;
|
||||||
|
import brainwine.gameserver.command.CommandExecutor;
|
||||||
|
import brainwine.gameserver.entity.player.Player;
|
||||||
|
|
||||||
|
public class HealthCommand extends Command {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(CommandExecutor executor, String[] args) {
|
||||||
|
Player target = null;
|
||||||
|
|
||||||
|
if(args.length < 2) {
|
||||||
|
if(args.length == 0 || !(executor instanceof Player)) {
|
||||||
|
executor.notify(String.format("Usage: %s", getUsage(executor)), ALERT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
target = (Player)executor;
|
||||||
|
} else {
|
||||||
|
target = GameServer.getInstance().getPlayerManager().getPlayer(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(target == null) {
|
||||||
|
executor.notify("This player does not exist.", ALERT);
|
||||||
|
return;
|
||||||
|
} else if(!target.isOnline()) {
|
||||||
|
executor.notify("This player is offline.", ALERT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
float health = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
health = Float.parseFloat(args[0]);
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
executor.notify("Health must be a valid number.", ALERT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setHealth(health);
|
||||||
|
target.alert(String.format("Your health has been set to %s", target.getHealth()));
|
||||||
|
|
||||||
|
if(target != executor) {
|
||||||
|
executor.notify(String.format("Set %s's health to %s", target.getName(), target.getHealth()), ALERT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "health";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getAliases() {
|
||||||
|
return new String[] { "hp" };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return "Sets a player's health.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsage(CommandExecutor executor) {
|
||||||
|
return String.format("/health <amount> %s", executor instanceof Player ? "[player]" : "<player>");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canExecute(CommandExecutor executor) {
|
||||||
|
return executor.isAdmin();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue