From b38ff5d1b4ac55bfcc09dfd28bb4c3d11ffefef8 Mon Sep 17 00:00:00 2001 From: Tux Date: Wed, 20 Aug 2014 21:31:02 -0400 Subject: [PATCH] Add /pproxy command to request the proxy where a player is connected. --- .../minecraft/redisbungee/RedisBungee.java | 1 + .../minecraft/redisbungee/RedisBungeeAPI.java | 11 ++++++ .../redisbungee/RedisBungeeCommands.java | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index 2d6ded8..4b84293 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -270,6 +270,7 @@ public final class RedisBungee extends Plugin { getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.SendToAll(this)); getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerId(this)); getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.ServerIds()); + getProxy().getPluginManager().registerCommand(this, new RedisBungeeCommands.PlayerProxyCommand(this)); api = new RedisBungeeAPI(this); getProxy().getPluginManager().registerListener(this, new RedisBungeeListener(this)); getProxy().getPluginManager().registerListener(this, dataManager); diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java index 545ac6a..864a1a5 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java @@ -134,6 +134,17 @@ public class RedisBungeeAPI { return plugin.getDataManager().getIp(player); } + /** + * Get the RedisBungee proxy ID this player is connected to. + * + * @param player the player to fetch the IP for + * @return the proxy the player is connected to, or null if they are offline + * @since 0.3.3 + */ + public final String getProxy(@NonNull UUID player) { + return plugin.getDataManager().getProxy(player); + } + /** * Sends a proxy command to all proxies. * diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java index 5c28521..0838fe1 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java @@ -200,6 +200,42 @@ class RedisBungeeCommands { } } + public static class PlayerProxyCommand extends Command { + private final RedisBungee plugin; + + PlayerProxyCommand(RedisBungee plugin) { + super("pproxy", "redisbungee.command.pproxy"); + this.plugin = plugin; + } + + @Override + public void execute(final CommandSender sender, final String[] args) { + plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { + @Override + public void run() { + if (args.length > 0) { + UUID uuid = plugin.getUuidTranslator().getTranslatedUuid(args[0], true); + if (uuid == null) { + sender.sendMessage(PLAYER_NOT_FOUND); + return; + } + String proxy = RedisBungee.getApi().getProxy(uuid); + if (proxy != null) { + TextComponent message = new TextComponent(); + message.setColor(ChatColor.GREEN); + message.setText(args[0] + " is connected to " + proxy + "."); + sender.sendMessage(message); + } else { + sender.sendMessage(PLAYER_NOT_FOUND); + } + } else { + sender.sendMessage(NO_PLAYER_SPECIFIED); + } + } + }); + } + } + public static class SendToAll extends Command { private final RedisBungee plugin;