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:
commit
e7255bbb53
@ -683,7 +683,6 @@ public class ServerManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
for (ServerGroup serverGroup : mineplex.serverdata.servers.ServerManager.getServerRepository(region).getServerGroups(null))
|
for (ServerGroup serverGroup : mineplex.serverdata.servers.ServerManager.getServerRepository(region).getServerGroups(null))
|
||||||
{
|
{
|
||||||
System.out.println("ADDING SERVER GROUP: " + serverGroup.getName());
|
|
||||||
addServerGroup(serverGroup);
|
addServerGroup(serverGroup);
|
||||||
|
|
||||||
if (!serverGroup.getServerNpcName().isEmpty())
|
if (!serverGroup.getServerNpcName().isEmpty())
|
||||||
|
@ -4,6 +4,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import mineplex.core.common.util.Callback;
|
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.core.shop.item.IButton;
|
||||||
import mineplex.game.clans.core.ClanDeleteCommand;
|
import mineplex.game.clans.core.ClanDeleteCommand;
|
||||||
import mineplex.game.clans.core.ClanLoadCommand;
|
import mineplex.game.clans.core.ClanLoadCommand;
|
||||||
@ -25,7 +27,7 @@ public class ClanMoveServerButton implements IButton
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(Player player, ClickType clickType)
|
public void onClick(final Player player, ClickType clickType)
|
||||||
{
|
{
|
||||||
_repository.moveClanServer(_clan.getClanId(), _serverName, new Callback<Boolean>()
|
_repository.moveClanServer(_clan.getClanId(), _serverName, new Callback<Boolean>()
|
||||||
{
|
{
|
||||||
@ -40,7 +42,9 @@ public class ClanMoveServerButton implements IButton
|
|||||||
deleteCommand.publish();
|
deleteCommand.publish();
|
||||||
loadCommand.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
|
else
|
||||||
{
|
{
|
||||||
|
@ -31,7 +31,7 @@ public class ClanMoveServerPage extends ShopPageBase<ServerManager, ClanMoveServ
|
|||||||
{
|
{
|
||||||
super(plugin, shop, clientManager, donationManager, "Clans Server Change", player, 27);
|
super(plugin, shop, clientManager, donationManager, "Clans Server Change", player, 27);
|
||||||
|
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_clan = clan;
|
_clan = clan;
|
||||||
_accountId = clientManager.getAccountId(player);
|
_accountId = clientManager.getAccountId(player);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class ClanMoveServerShop extends ShopBase<ServerManager>
|
|||||||
_repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName());
|
_repository = new ClanRepository(plugin.getPlugin(), plugin.getStatusManager().getCurrentServerName());
|
||||||
_clan = clan;
|
_clan = clan;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> buildPagesFor(Player player)
|
protected ShopPageBase<ServerManager, ? extends ShopBase<ServerManager>> buildPagesFor(Player player)
|
||||||
{
|
{
|
||||||
|
@ -50,12 +50,10 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
|
|||||||
{
|
{
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
System.out.println("Found clan: " + data.getClanName() + " - " + data.getHomeServer());
|
|
||||||
buildClanPage(data);
|
buildClanPage(data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
System.out.println("NO CLAN FOUND!");
|
|
||||||
buildNoClanPage();
|
buildNoClanPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,8 +96,8 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
|
|||||||
String title = C.cRed + C.Bold + "Join Home Server!";
|
String title = C.cRed + C.Bold + "Join Home Server!";
|
||||||
String description = C.cGold + "Join your home server, " + C.cAqua + clan.getHomeServer() + C.cGold + "!";
|
String description = C.cGold + "Join your home server, " + C.cAqua + clan.getHomeServer() + C.cGold + "!";
|
||||||
String serverDesc = C.cGold + "Server Status: " + serverStatus + 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);
|
ShopItem shopItem = new ShopItem(Material.EMERALD_BLOCK, title, new String[] {" ", description, serverDesc, " "}, 0, true, true);
|
||||||
addButton(4, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer()), getPlayer()));
|
addButton(13, shopItem, new JoinServerButton(this, getPlugin(), getServerInfo(clan.getHomeServer()), getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildJoinServer(int slot, ServerInfo server)
|
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 title = C.cRed + C.Bold + "Join Clans Server!";
|
||||||
String desc1 = C.cGold + "Name: " + C.cAqua + server.Name;
|
String desc1 = C.cGold + "Name: " + C.cAqua + server.Name;
|
||||||
String desc2 = C.cGold + "Players: " + C.cAqua + server.CurrentPlayers + "/" + server.MaxPlayers;
|
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()));
|
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)
|
private ServerInfo getServerInfo(String serverName)
|
||||||
|
@ -30,6 +30,7 @@ public class Utility
|
|||||||
// Public static jedis pool for interacting with central default jedis repo.
|
// Public static jedis pool for interacting with central default jedis repo.
|
||||||
private static JedisPool _masterPool;
|
private static JedisPool _masterPool;
|
||||||
private static JedisPool _slavePool;
|
private static JedisPool _slavePool;
|
||||||
|
private static final Object _poolLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param object - the (non-null) object to serialize
|
* @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.
|
* @return a newly instantiated {@link JedisPool} connected to the provided {@link ConnectionData} repository.
|
||||||
*/
|
*/
|
||||||
public static JedisPool generatePool(ConnectionData connData)
|
public static JedisPool generatePool(ConnectionData connData)
|
||||||
{
|
{
|
||||||
String key = getConnKey(connData);
|
synchronized(_poolLock)
|
||||||
JedisPool pool = _pools.get(key);
|
|
||||||
if (pool == null)
|
|
||||||
{
|
{
|
||||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
String key = getConnKey(connData);
|
||||||
jedisPoolConfig.setMaxWaitMillis(1000);
|
JedisPool pool = _pools.get(key);
|
||||||
jedisPoolConfig.setMinIdle(5);
|
|
||||||
jedisPoolConfig.setTestOnBorrow(true);
|
if (pool == null)
|
||||||
|
{
|
||||||
|
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||||
|
jedisPoolConfig.setMaxWaitMillis(1000);
|
||||||
|
jedisPoolConfig.setMinIdle(5);
|
||||||
|
jedisPoolConfig.setTestOnBorrow(true);
|
||||||
|
|
||||||
jedisPoolConfig.setMaxTotal(20);
|
jedisPoolConfig.setMaxTotal(20);
|
||||||
jedisPoolConfig.setBlockWhenExhausted(true);
|
jedisPoolConfig.setBlockWhenExhausted(true);
|
||||||
|
|
||||||
pool = new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
pool = new JedisPool(jedisPoolConfig, connData.getHost(), connData.getPort());
|
||||||
_pools.put(key, pool);
|
_pools.put(key, pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,12 +84,12 @@ public class ServerCommandManager
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
String commandType = serverCommand.getClass().getSimpleName();
|
||||||
|
String serializedCommand = Utility.serialize(serverCommand);
|
||||||
Jedis jedis = _writePool.getResource();
|
Jedis jedis = _writePool.getResource();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String commandType = serverCommand.getClass().getSimpleName();
|
|
||||||
String serializedCommand = Utility.serialize(serverCommand);
|
|
||||||
jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand);
|
jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand);
|
||||||
}
|
}
|
||||||
catch (JedisConnectionException exception)
|
catch (JedisConnectionException exception)
|
||||||
|
Loading…
Reference in New Issue
Block a user