Fix bugs related to multiple server UI and clan server transferring.

This commit is contained in:
Ty Sayers 2015-08-29 17:31:54 -07:00
parent 227a077dba
commit 5df7a5e0c9
16 changed files with 171 additions and 50 deletions

View File

@ -186,6 +186,9 @@
<fileset dir="../Mineplex.Core.Common/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Game.Clans.Core/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Game.ClassCombat/bin">
<include name="**/*.class"/>
</fileset>

View File

@ -4,19 +4,19 @@ import mineplex.game.clans.core.repository.tokens.SimpleClanToken;
import mineplex.serverdata.commands.ServerCommand;
public class ClanServerChangeCommand extends ServerCommand
public class ClanDeleteCommand extends ServerCommand
{
private String _clanName;
public String getClanName() { return _clanName; }
public ClanServerChangeCommand(String serverName, String clanName)
public ClanDeleteCommand(String serverName, String clanName)
{
super(serverName);
_clanName = clanName;
}
public ClanServerChangeCommand(SimpleClanToken clan)
public ClanDeleteCommand(SimpleClanToken clan)
{
this(clan.getHomeServer(), clan.getClanName());
}

View File

@ -0,0 +1,23 @@
package mineplex.game.clans.core;
import mineplex.serverdata.commands.ServerCommand;
public class ClanLoadCommand extends ServerCommand
{
private String _clanName;
public String getClanName() { return _clanName; }
public ClanLoadCommand(String serverName, String clanName)
{
super(serverName);
_clanName = clanName;
}
@Override
public void run()
{
// Utilitizes a callback functionality to seperate dependencies
}
}

View File

@ -41,11 +41,11 @@ public class ClanRepository extends RepositoryBase
private static String CREATE_CLAN_TERRITORY_TABLE = "CREATE TABLE IF NOT EXISTS clanTerritory (id INT NOT NULL AUTO_INCREMENT, clanId INT, serverId INT NOT NULL, chunk VARCHAR(100), safe BIT(1), PRIMARY KEY (id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId, serverId));";
private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BIT(1), PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
private static String RETRIEVE_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.dateCreated, c.lastOnline FROM clans AS c WHERE lower(c.name) = ?;";
private static String RETRIEVE_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline FROM clans AS c WHERE lower(c.name) = ?;";
private static String RETRIEVE_PLAYER_CLAN_INFO = "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = ?;";
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.kills, c.murder, c.deaths, c.warWins, c.warLosses, c.generator, c.generatorStock, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverId = ?;";
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverId = ?;";
private static String RETRIEVE_CLAN_MEMBERS = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE lower(c.name) = ?;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverId = ?;";
private static String RETRIEVE_CLAN_ENEMY_INFO = "SELECT c.name, cOther.name, clanScore, otherClanScore, clanKills, otherClanKills, timeFormed FROM clanEnemies AS ce INNER JOIN clans AS c ON c.id = ce.clanId INNER JOIN clans as cOther ON cOther.id = ce.otherClanId WHERE c.serverId = ?;";
@ -164,8 +164,10 @@ public class ClanRepository extends RepositoryBase
}
public void retrieveClan(String clanName, final Callback<ClanToken> callback)
public ClanToken retrieveClan(String clanName)
{
final ClanToken clan = new ClanToken();
executeQuery(RETRIEVE_CLAN_INFO, new ResultSetCallable()
{
@Override
@ -173,25 +175,49 @@ public class ClanRepository extends RepositoryBase
{
if (resultSet.next())
{
ClanToken token = new ClanToken();
token.Id = resultSet.getInt(1);
token.Name = resultSet.getString(2);
token.Description = resultSet.getString(3);
token.Home = resultSet.getString(4);
token.Admin = resultSet.getBoolean(5);
token.Energy = resultSet.getInt(6);
token.Kills = resultSet.getInt(7);
token.Murder = resultSet.getInt(8);
token.Deaths = resultSet.getInt(9);
token.WarWins = resultSet.getInt(10);
token.WarLosses = resultSet.getInt(11);
token.DateCreated = resultSet.getTimestamp(12);
token.LastOnline = resultSet.getTimestamp(13);
callback.run(token);
if (resultSet.next())
{
clan.Id = resultSet.getInt(1);
clan.Name = resultSet.getString(2);
clan.Description = resultSet.getString(3);
clan.Home = resultSet.getString(4);
clan.Admin = resultSet.getBoolean(5);
clan.Energy = resultSet.getInt(6);
clan.Kills = resultSet.getInt(7);
clan.Murder = resultSet.getInt(8);
clan.Deaths = resultSet.getInt(9);
clan.WarWins = resultSet.getInt(10);
clan.WarLosses = resultSet.getInt(11);
clan.Generator = resultSet.getString(12);
clan.GeneratorStock = resultSet.getInt(13);
clan.DateCreated = resultSet.getTimestamp(14);
clan.LastOnline = resultSet.getTimestamp(15);
}
}
}
}, new ColumnVarChar("name", 100, clanName.toLowerCase()));
executeQuery(RETRIEVE_CLAN_MEMBERS, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
String clanName = resultSet.getString(1);
ClanMemberToken memberToken = new ClanMemberToken();
memberToken.Name = resultSet.getString(2);
memberToken.PlayerUUID = UUID.fromString(resultSet.getString(3));
memberToken.ClanRole = resultSet.getString(4);
clan.Members.add(memberToken);
}
}
}, new ColumnVarChar("name", 100, clanName.toLowerCase()));
return clan;
}
public void clanExists(String clanName, final Callback<Boolean> callback)
@ -228,7 +254,7 @@ public class ClanRepository extends RepositoryBase
}
}, new ColumnInt("accountId", accountId));
}
public Collection<ClanToken> retrieveClans()
{
System.out.println("Beginning to load clans from database...");
@ -240,7 +266,7 @@ public class ClanRepository extends RepositoryBase
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
{
ClanToken token = new ClanToken();
token.Id = resultSet.getInt(1);
token.Name = resultSet.getString(2);

View File

@ -684,9 +684,17 @@ public class ClansDataAccessLayer
_manager.log("Safe Zone at [" + claim.Chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
}
public void retrieveClan(String clanName, Callback<ClanToken> callback)
public void retrieveClan(final String clanName, final Callback<ClanToken> callback)
{
_repository.retrieveClan(clanName, callback);
runAsync(new Runnable()
{
@Override
public void run()
{
ClanToken clan = _repository.retrieveClan(clanName);
callback.run(clan);
}
});
}
public void clanExists(String clanName, Callback<Boolean> callback)

View File

@ -58,7 +58,7 @@ public class ClansDisplay extends MiniPlugin
//Update Territory
client.setTerritory(UtilWorld.chunkToStr(player.getLocation().getChunk()));
//AutoClaim
if (client.isAutoClaim())
Clans.getClanAdmin().claim(player);

View File

@ -64,14 +64,16 @@ import mineplex.game.clans.clans.commands.ServerTimeCommand;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager;
import mineplex.game.clans.clans.murder.MurderManager;
import mineplex.game.clans.clans.redis.ClanServerChangeHandler;
import mineplex.game.clans.clans.redis.ClanDeleteCommandHandler;
import mineplex.game.clans.clans.redis.ClanLoadCommandHandler;
import mineplex.game.clans.clans.regions.ClansRegions;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager;
import mineplex.game.clans.clans.war.WarManager;
import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.core.ClanServerChangeCommand;
import mineplex.game.clans.core.ClanDeleteCommand;
import mineplex.game.clans.core.ClanLoadCommand;
import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.core.repository.tokens.ClanMemberToken;
import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken;
@ -226,7 +228,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress);
// Register redis based server commands
ServerCommandManager.getInstance().registerCommandType(ClanServerChangeCommand.class, new ClanServerChangeHandler());
ServerCommandManager.getInstance().registerCommandType(ClanDeleteCommand.class, new ClanDeleteCommandHandler());
ServerCommandManager.getInstance().registerCommandType(ClanLoadCommand.class, new ClanLoadCommandHandler());
StatsManager statsManager = new StatsManager(plugin, _clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, _clientManager, donationManager);
@ -237,14 +240,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
{
ClanInfo clan = new ClanInfo(this, token);
_clanMap.put(token.Name, clan);
for (ClanMemberToken memberToken : token.Members)
_clanMemberMap.put(memberToken.Name, clan);
for (ClanTerritoryToken territoryToken : token.Territories)
_claimMap.put(territoryToken.Chunk, new ClanTerritory(territoryToken));
loadClan(token);
}
//RedisDataRepository(ConnectionData writeConn, ConnectionData readConn, Region region, Class<T> elementType, String elementLabel)
@ -265,6 +261,18 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
addCommand(new MapCommand(this));
}
public void loadClan(ClanToken clanToken)
{
ClanInfo clan = new ClanInfo(this, clanToken);
_clanMap.put(clanToken.Name, clan);
for (ClanMemberToken memberToken : clanToken.Members)
_clanMemberMap.put(memberToken.Name, clan);
for (ClanTerritoryToken territoryToken : clanToken.Territories)
_claimMap.put(territoryToken.Chunk, new ClanTerritory(territoryToken));
}
public DisguiseManager getDisguiseManager()
{
return _disguiseManager;

View File

@ -3,18 +3,18 @@ package mineplex.game.clans.clans.redis;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.core.ClanServerChangeCommand;
import mineplex.game.clans.core.ClanDeleteCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class ClanServerChangeHandler implements CommandCallback
public class ClanDeleteCommandHandler implements CommandCallback
{
public void run(ServerCommand command)
{
if (command instanceof ClanServerChangeCommand)
if (command instanceof ClanDeleteCommand)
{
ClanServerChangeCommand serverCommand = (ClanServerChangeCommand) command;
ClanDeleteCommand serverCommand = (ClanDeleteCommand) command;
String clanName = serverCommand.getClanName();
ClanInfo clanInfo = ClansManager.getInstance().getClan(clanName);

View File

@ -0,0 +1,41 @@
package mineplex.game.clans.clans.redis;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.core.ClanDeleteCommand;
import mineplex.game.clans.core.ClanLoadCommand;
import mineplex.game.clans.core.repository.tokens.ClanToken;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class ClanLoadCommandHandler implements CommandCallback
{
public void run(ServerCommand command)
{
if (command instanceof ClanLoadCommand)
{
ClanLoadCommand serverCommand = (ClanLoadCommand) command;
final String clanName = serverCommand.getClanName();
ClansManager.getInstance().getClanDataAccess().retrieveClan(clanName, new Callback<ClanToken>()
{
@Override
public void run(ClanToken clan)
{
if (clan != null)
{
ClansManager.getInstance().loadClan(clan); // Load the clan data locally
System.out.println("Successfully finished loading and transferring clan '" + clanName + "'!");
}
else
{
System.out.println("ERROR: UNABLE TO LOAD CLAN " + clanName + " DURING REMOTE CLAN LOAD COMMAND!");
}
}
});
}
}
}

View File

@ -38,7 +38,7 @@ import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory;
import mineplex.serverdata.servers.ServerManager;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutSetSlot;
import net.minecraft.util.com.google.common.collect.Sets;
import net.minecraft.util.com.google.common.collect.Sets;
import org.bukkit.Bukkit;
import org.bukkit.Location;

View File

@ -683,6 +683,7 @@ 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

@ -32,7 +32,7 @@ public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> implements
buildPage();
}
@Override
@Override
protected void buildPage()
{
List<ServerInfo> serverList = new ArrayList<ServerInfo>(getPlugin().getServerList(_serverGroup));

View File

@ -31,12 +31,12 @@ public class ServerNpcShop extends ShopBase<ServerManager>
{
return new ServerTypePage(getPlugin(), this, getClientManager(), getDonationManager(), player, _serverGroup);
}
else
else
{
return new ServerNpcPage(getPlugin(), this, getClientManager(), getDonationManager(), _serverGroup.getServerNpcName(), player, _serverGroup.getPrefix());
}
}
}
@Override
protected boolean canOpenShop(Player player)

View File

@ -5,7 +5,8 @@ import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.util.Callback;
import mineplex.core.shop.item.IButton;
import mineplex.game.clans.core.ClanServerChangeCommand;
import mineplex.game.clans.core.ClanDeleteCommand;
import mineplex.game.clans.core.ClanLoadCommand;
import mineplex.game.clans.core.repository.ClanRepository;
import mineplex.game.clans.core.repository.tokens.SimpleClanToken;
@ -33,8 +34,12 @@ public class ClanMoveServerButton implements IButton
{
if (success)
{
ClanServerChangeCommand changeCommand = new ClanServerChangeCommand(_clan);
changeCommand.publish();
ClanDeleteCommand deleteCommand = new ClanDeleteCommand(_clan);
ClanLoadCommand loadCommand = new ClanLoadCommand(_serverName, _clan.getClanName());
deleteCommand.publish();
loadCommand.publish();
System.out.println("Successfully finished moving clan to new home server!");
}
else

View File

@ -75,7 +75,7 @@ public class ClansServerPage extends ShopPageBase<ServerManager, ClansServerShop
private void buildNoClanPage()
{
Collection<ServerInfo> servers = getPlugin().getServerList("Clans");
int currentSlot = 9;
for (ServerInfo server : servers)
{

View File

@ -311,6 +311,12 @@ public class RedisServerRepository implements ServerRepository
{
Map<String, String> data = response.get();
if (data.entrySet().size() == 0)
{
System.out.println("Encountered empty map! Skipping...");
continue;
}
try
{
ServerGroup serverGroup = new ServerGroup(data, serverStatuses);