From b11984cb0304d8caec02acfb110aec0f5bc02a41 Mon Sep 17 00:00:00 2001 From: kuroppoi <68156848+kuroppoi@users.noreply.github.com> Date: Sun, 30 May 2021 23:03:21 +0200 Subject: [PATCH] Added a position command --- .../gameserver/command/CommandManager.java | 2 + .../command/commands/PositionCommand.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 gameserver/src/main/java/brainwine/gameserver/command/commands/PositionCommand.java diff --git a/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java b/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java index 89b1fb7..b76d216 100644 --- a/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java +++ b/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java @@ -18,6 +18,7 @@ import brainwine.gameserver.command.commands.GiveCommand; import brainwine.gameserver.command.commands.HelpCommand; import brainwine.gameserver.command.commands.KickCommand; import brainwine.gameserver.command.commands.PlayerIdCommand; +import brainwine.gameserver.command.commands.PositionCommand; import brainwine.gameserver.command.commands.RegisterCommand; import brainwine.gameserver.command.commands.SayCommand; import brainwine.gameserver.command.commands.SeedCommand; @@ -61,6 +62,7 @@ public class CommandManager { registerCommand(new GiveCommand()); registerCommand(new GenerateZoneCommand()); registerCommand(new SeedCommand()); + registerCommand(new PositionCommand()); } public static void executeCommand(CommandExecutor executor, String commandLine) { diff --git a/gameserver/src/main/java/brainwine/gameserver/command/commands/PositionCommand.java b/gameserver/src/main/java/brainwine/gameserver/command/commands/PositionCommand.java new file mode 100644 index 0000000..1ddede5 --- /dev/null +++ b/gameserver/src/main/java/brainwine/gameserver/command/commands/PositionCommand.java @@ -0,0 +1,41 @@ +package brainwine.gameserver.command.commands; + +import static brainwine.gameserver.entity.player.NotificationType.SYSTEM; + +import brainwine.gameserver.command.Command; +import brainwine.gameserver.command.CommandExecutor; +import brainwine.gameserver.entity.player.Player; + +public class PositionCommand extends Command { + + @Override + public void execute(CommandExecutor executor, String[] args) { + Player player = (Player)executor; + player.notify(String.format("X: %s Y: %s", (int)player.getX(), (int)player.getY() + 1), SYSTEM); + } + + @Override + public String getName() { + return "pos"; + } + + @Override + public String[] getAliases() { + return new String[] { "position", "feet", "coords", "location" }; + } + + @Override + public String getDescription() { + return "Displays the coordinates of the block you are standing on."; + } + + @Override + public String getUsage(CommandExecutor executor) { + return "/pos"; + } + + @Override + public boolean canExecute(CommandExecutor executor) { + return executor instanceof Player && executor.isAdmin(); + } +}