From e926fc1f10ccab8aaef3ff6a32ce28ffa988996c Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 27 Oct 2014 04:34:35 -0700 Subject: [PATCH] Fixed TransferCommand --- .../src/mineplex/core/portal/Portal.java | 13 +--------- .../mineplex/core/portal/TransferCommand.java | 1 - .../serverdata/RedisServerRepository.java | 1 - .../serverdata/ServerCommandListener.java | 2 +- .../serverdata/ServerCommandManager.java | 24 +++++++++---------- 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java index 0da30b552..28496a9b4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/Portal.java @@ -3,27 +3,19 @@ package mineplex.core.portal; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.Collection; import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilPlayer; import mineplex.core.portal.Commands.*; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; import mineplex.serverdata.Region; import mineplex.serverdata.ServerCommandManager; import mineplex.serverdata.ServerManager; @@ -38,8 +30,6 @@ public class Portal extends MiniPlugin private HashSet _connectingPlayers = new HashSet(); private Region _region; - private boolean _retrieve = true; - private String _serverName; public Portal(JavaPlugin plugin, String serverName) { @@ -47,13 +37,12 @@ public class Portal extends MiniPlugin instance = this; - this._serverName = serverName; this._region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; Bukkit.getMessenger().registerOutgoingPluginChannel(GetPlugin(), "BungeeCord"); // Register the server command type for future use - ServerCommandManager.getInstance().registerCommandType(TransferCommand.class); + ServerCommandManager.getInstance().registerCommandType(TransferCommand.class.getSimpleName(), TransferCommand.class); } public void SendAllPlayers(String serverName) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java index 1c1a70ada..928dd8819 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/portal/TransferCommand.java @@ -36,5 +36,4 @@ public class TransferCommand extends ServerCommand Portal.getInstance().SendPlayerToServer(player, transfer.getServerName()); } } - } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 7e7ffa669..841705967 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -2,7 +2,6 @@ package mineplex.serverdata; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandListener.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandListener.java index e763feba5..946ecc80d 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandListener.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandListener.java @@ -17,7 +17,7 @@ public class ServerCommandListener extends JedisPubSub { try { - String commandType = message.split(":")[1]; + String commandType = channelName.split(":")[1]; ServerCommandManager.getInstance().handleCommand(commandType, message); } catch (Exception exception) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java index 9f3542113..8bc85c3e0 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerCommandManager.java @@ -16,7 +16,7 @@ public class ServerCommandManager public final String SERVER_COMMANDS_CHANNEL = "commands.server"; private JedisPool _jedisPool; - private Map> commandTypes; + private Map> _commandTypes; /** * Private class constructor to prevent non-singleton instances. @@ -25,7 +25,7 @@ public class ServerCommandManager { this._jedisPool = new JedisPool(new JedisPoolConfig(), ServerManager.DEFAULT_REDIS_HOST, ServerManager.DEFAULT_REDIS_PORT); - this.commandTypes = new HashMap>(); + this._commandTypes = new HashMap>(); initialize(); } @@ -71,7 +71,7 @@ public class ServerCommandManager try { - String commandType = serverCommand.getClass().toString(); + String commandType = serverCommand.getClass().getSimpleName(); String serializedCommand = Utility.serialize(serverCommand); jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand); } @@ -92,15 +92,15 @@ public class ServerCommandManager */ public void handleCommand(String commandType, String serializedCommand) { - if (commandTypes.containsKey(commandType)) + if (_commandTypes.containsKey(commandType)) { - ServerCommand serverCommand = Utility.deserialize(serializedCommand, commandTypes.get(commandType)); + ServerCommand serverCommand = Utility.deserialize(serializedCommand, _commandTypes.get(commandType)); - if (serverCommand.isTargetServer("THIS SERVER NAME HERE")) // TODO: Find server name ref - { + //if (serverCommand.isTargetServer("THIS SERVER NAME HERE")) // TODO: Find server name ref + //{ // TODO: Run synchronously? serverCommand.run(); // Run the server command - } + //} } } @@ -108,13 +108,11 @@ public class ServerCommandManager * Register a new type of {@link ServerCommand}. * @param commandType - the {@link ServerCommand} type to register. */ - public void registerCommandType(Class commandType) + public void registerCommandType(String commandName, Class commandType) { - String commandName = commandType.toString(); - - if (!commandTypes.containsKey(commandName)) + if (!_commandTypes.containsKey(commandName)) { - commandTypes.put(commandName, commandType); + _commandTypes.put(commandName, commandType); } }