mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Added an admin command (#1)
This commit is contained in:
parent
d8099a9643
commit
3bb2917ec1
3 changed files with 58 additions and 4 deletions
|
@ -9,6 +9,7 @@ import java.util.Set;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import brainwine.gameserver.command.commands.AdminCommand;
|
||||
import brainwine.gameserver.command.commands.BroadcastCommand;
|
||||
import brainwine.gameserver.command.commands.HelpCommand;
|
||||
import brainwine.gameserver.command.commands.KickCommand;
|
||||
|
@ -50,6 +51,7 @@ public class CommandManager {
|
|||
registerCommand(new BroadcastCommand());
|
||||
registerCommand(new PlayerIdCommand());
|
||||
registerCommand(new ZoneIdCommand());
|
||||
registerCommand(new AdminCommand());
|
||||
registerCommand(new HelpCommand());
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package brainwine.gameserver.command.commands;
|
||||
|
||||
import brainwine.gameserver.GameServer;
|
||||
import brainwine.gameserver.command.Command;
|
||||
import brainwine.gameserver.command.CommandExecutor;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
|
||||
public class AdminCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandExecutor executor, String[] args) {
|
||||
if(args.length == 0) {
|
||||
executor.sendMessage(String.format("Usage: %s", getUsage()));
|
||||
return;
|
||||
}
|
||||
|
||||
Player target = GameServer.getInstance().getPlayerManager().getPlayer(args[0]);
|
||||
|
||||
if(target == null) {
|
||||
executor.sendMessage("This player does not exist.");
|
||||
return;
|
||||
} else if(target == executor) {
|
||||
executor.sendMessage("You cannot change your own administrator status.");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean admin = args.length == 1 ? true : Boolean.parseBoolean(args[1]);
|
||||
target.setAdmin(admin));
|
||||
target.kick(admin ? "You have been given the administrator role! Please restart your game to see its full effects." : "Your administrator privileges have been revoked.");
|
||||
executor.sendMessage(String.format("Changed administrator status of player %s to %s", target.getName(), admin));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "admin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Changes a players administrator status.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "/admin <player> [true|false]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresAdmin() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -48,14 +48,14 @@ public abstract class Entity {
|
|||
return name;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
return health <= 0;
|
||||
}
|
||||
|
||||
public void setHealth(float health) {
|
||||
this.health = health;
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue