Fixed TransferCommand

This commit is contained in:
Jonathan Williams 2014-10-27 04:34:35 -07:00
parent 0ee9619d3e
commit e926fc1f10
5 changed files with 13 additions and 28 deletions

View File

@ -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<String> _connectingPlayers = new HashSet<String>();
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)

View File

@ -36,5 +36,4 @@ public class TransferCommand extends ServerCommand
Portal.getInstance().SendPlayerToServer(player, transfer.getServerName());
}
}
}

View File

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

View File

@ -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)

View File

@ -16,7 +16,7 @@ public class ServerCommandManager
public final String SERVER_COMMANDS_CHANNEL = "commands.server";
private JedisPool _jedisPool;
private Map<String, Class<? extends ServerCommand>> commandTypes;
private Map<String, Class<? extends ServerCommand>> _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<String, Class<? extends ServerCommand>>();
this._commandTypes = new HashMap<String, Class<? extends ServerCommand>>();
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<? extends ServerCommand> commandType)
public void registerCommandType(String commandName, Class<? extends ServerCommand> commandType)
{
String commandName = commandType.toString();
if (!commandTypes.containsKey(commandName))
if (!_commandTypes.containsKey(commandName))
{
commandTypes.put(commandName, commandType);
_commandTypes.put(commandName, commandType);
}
}