From 14eb8e28cf928d18b85340f8be84f2c49ae874be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Vis=C3=A9e?= Date: Sun, 1 Nov 2015 18:54:03 +0100 Subject: [PATCH] Implemented getip command --- .../xephi/authme/command/CommandManager.java | 13 ++++++ .../executable/authme/GetIpCommand.java | 41 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java diff --git a/src/main/java/fr/xephi/authme/command/CommandManager.java b/src/main/java/fr/xephi/authme/command/CommandManager.java index 6a061b93..0040b677 100644 --- a/src/main/java/fr/xephi/authme/command/CommandManager.java +++ b/src/main/java/fr/xephi/authme/command/CommandManager.java @@ -225,6 +225,19 @@ public class CommandManager { setEmailCommand.addArgument(new CommandArgumentDescription("player", "Player name", false)); setEmailCommand.addArgument(new CommandArgumentDescription("email", "Player email", false)); + // Register the getip command + CommandDescription getIpCommand = new CommandDescription( + new GetIpCommand(), + new ArrayList() {{ + add("getip"); + add("ip"); + }}, + "Get player's IP", + "Get the IP address of the specified online player.", + authMeCommand); + getIpCommand.setCommandPermissions("authme.admin.getip", CommandPermissions.DefaultPermission.OP_ONLY); + getIpCommand.addArgument(new CommandArgumentDescription("player", "Online player name", false)); + // Register the spawn command CommandDescription spawnCommand = new CommandDescription( new SpawnCommand(), diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java new file mode 100644 index 00000000..d67b7d63 --- /dev/null +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetIpCommand.java @@ -0,0 +1,41 @@ +package fr.xephi.authme.command.executable.authme; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.command.CommandParts; +import fr.xephi.authme.command.ExecutableCommand; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class GetIpCommand extends ExecutableCommand { + + /** + * Execute the command. + * + * @param sender The command sender. + * @param commandReference The command reference. + * @param commandArguments The command arguments. + * + * @return True if the command was executed successfully, false otherwise. + */ + @Override + public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + // AuthMe plugin instance + final AuthMe plugin = AuthMe.getInstance(); + + // Get the player query + String playerName = sender.getName(); + if(commandArguments.getCount() >= 1) + playerName = commandArguments.get(0); + + @SuppressWarnings("deprecation") + Player player = Bukkit.getPlayer(playerName); + if (player == null) { + sender.sendMessage("This player is not actually online"); + return true; + } + sender.sendMessage(player.getName() + "'s actual IP is : " + player.getAddress().getAddress().getHostAddress() + ":" + player.getAddress().getPort()); + sender.sendMessage(player.getName() + "'s real IP is : " + plugin.getIP(player)); + return true; + } +}