Merge pull request #57 in MIN/mineplex from clans_custom_gear to clans-beta

* commit '7047bbf8f69c36c535f0bb63812218b0b62c1afd':
  Fix asynchronous race conditions in ServerData.
This commit is contained in:
Ty Sayers 2015-08-29 21:07:03 -05:00
commit e7255bbb53
7 changed files with 35 additions and 27 deletions

View File

@ -683,7 +683,6 @@ public class ServerManager extends MiniPlugin
{
for (ServerGroup serverGroup : mineplex.serverdata.servers.ServerManager.getServerRepository(region).getServerGroups(null))
{
System.out.println("ADDING SERVER GROUP: " + serverGroup.getName());
addServerGroup(serverGroup);
if (!serverGroup.getServerNpcName().isEmpty())

View File

@ -4,6 +4,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.shop.item.IButton;
import mineplex.game.clans.core.ClanDeleteCommand;
import mineplex.game.clans.core.ClanLoadCommand;
@ -25,7 +27,7 @@ public class ClanMoveServerButton implements IButton
}
@Override
public void onClick(Player player, ClickType clickType)
public void onClick(final Player player, ClickType clickType)
{
_repository.moveClanServer(_clan.getClanId(), _serverName, new Callback<Boolean>()
{
@ -40,7 +42,9 @@ public class ClanMoveServerButton implements IButton
deleteCommand.publish();
loadCommand.publish();
System.out.println("Successfully finished moving clan to new home server!");
player.closeInventory();
UtilPlayer.message(player, F.main("Clans", "You have successfully transferred your clan!"));
System.out.println("Successfully finished moving clan '" + _clan.getClanName() + "' to new home server!");
}
else
{

View File

@ -31,7 +31,7 @@ public class ClanMoveServerPage extends ShopPageBase<ServerManager, ClanMoveServ
{
super(plugin, shop, clientManager, donationManager, "Clans Server Change", player, 27);
_repository = repository;
_repository = repository;
_clan = clan;
_accountId = clientManager.getAccountId(player);

View File

@ -28,7 +28,7 @@ public class ClanMoveServerShop extends ShopBase<ServerManager>
_repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName());
_clan = clan;
}
@Override
protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> buildPagesFor(Player player)
{

View File

@ -50,12 +50,10 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
{
if (data != null)
{
System.out.println("Found clan: " + data.getClanName() + " - " + data.getHomeServer());
buildClanPage(data);
}
else
{
System.out.println("NO CLAN FOUND!");
buildNoClanPage();
}
}
@ -98,8 +96,8 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
String title = C.cRed + C.Bold + "Join Home Server!";
String description = C.cGold + "Join your home server, " + C.cAqua + clan.getHomeServer() + C.cGold + "!";
String serverDesc = C.cGold + "Server Status: " + serverStatus + C.cGold + "!";
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", description, serverDesc, " "}, 0, true, true);
addButton(4, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer()), getPlayer()));
ShopItem shopItem = new ShopItem(Material.EMERALD_BLOCK, title, new String[] {" ", description, serverDesc, " "}, 0, true, true);
addButton(13, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer()), getPlayer()));
}
private void buildJoinServer(int slot, ServerInfo server)
@ -107,8 +105,10 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
String title = C.cRed + C.Bold + "Join Clans Server!";
String desc1 = C.cGold + "Name: " + C.cAqua + server.Name;
String desc2 = C.cGold + "Players: " + C.cAqua + server.CurrentPlayers + "/" + server.MaxPlayers;
String desc3 = C.Bold + C.cRed + "Note: " + ChatColor.RESET + C.cGray + "Creating a clan on this";
String desc4 = C.cGray + "server will set your home server!";
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", desc1, desc2, " "}, 0, true, true);
ShopItem shopItem = new ShopItem(Material.GOLD_BLOCK, title, new String[] {" ", desc1, desc2, " ", desc3, desc4}, 0, true, true);
addButton(slot, shopItem, new JoinServerButton(this, getPlugin(), server, getPlayer()));
}
@ -137,7 +137,7 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
}
};
addButton(13, shopItem, button);
addButton(26, shopItem, button);
}
private ServerInfo getServerInfo(String serverName)

View File

@ -30,6 +30,7 @@ public class Utility
// Public static jedis pool for interacting with central default jedis repo.
private static JedisPool _masterPool;
private static JedisPool _slavePool;
private static final Object _poolLock = new Object();
/**
* @param object - the (non-null) object to serialize
@ -137,24 +138,28 @@ public class Utility
* @return a newly instantiated {@link JedisPool} connected to the provided {@link ConnectionData} repository.
*/
public static JedisPool generatePool(ConnectionData connData)
{
String key = getConnKey(connData);
JedisPool pool = _pools.get(key);
if (pool == null)
{
synchronized(_poolLock)
{
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxWaitMillis(1000);
jedisPoolConfig.setMinIdle(5);
jedisPoolConfig.setTestOnBorrow(true);
String key = getConnKey(connData);
JedisPool pool = _pools.get(key);
if (pool == null)
{
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxWaitMillis(1000);
jedisPoolConfig.setMinIdle(5);
jedisPoolConfig.setTestOnBorrow(true);
jedisPoolConfig.setMaxTotal(20);
jedisPoolConfig.setBlockWhenExhausted(true);
jedisPoolConfig.setMaxTotal(20);
jedisPoolConfig.setBlockWhenExhausted(true);
pool = new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
_pools.put(key, pool);
pool = new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
_pools.put(key, pool);
}
return pool;
}
return pool;
}
/**

View File

@ -84,12 +84,12 @@ public class ServerCommandManager
{
public void run()
{
String commandType = serverCommand.getClass().getSimpleName();
String serializedCommand = Utility.serialize(serverCommand);
Jedis jedis = _writePool.getResource();
try
{
String commandType = serverCommand.getClass().getSimpleName();
String serializedCommand = Utility.serialize(serverCommand);
jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand);
}
catch (JedisConnectionException exception)