Implemented getip command

This commit is contained in:
Tim Visée 2015-11-01 18:54:03 +01:00
parent c11ca35774
commit 14eb8e28cf
2 changed files with 54 additions and 0 deletions

View File

@ -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<String>() {{
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(),

View File

@ -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;
}
}