Improved party lookup for server transfers.

Always transfer party if leader transfers servers.
This commit is contained in:
Jonathan Williams 2015-03-13 00:10:29 -07:00
parent e776a9f886
commit 28f73704e5

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.party.commands.PartyCommand;
import mineplex.core.party.redis.RedisPartyData;
import mineplex.core.party.redis.RedisPartyHandler;
@ -29,7 +30,7 @@ public class PartyManager extends MiniPlugin
private Portal _portal;
private String _serverName;
public HashSet<Party> _parties = new HashSet<Party>();
public NautHashMap<String, Party> _partyLeaderMap = new NautHashMap<String, Party>();
public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager)
{
@ -64,7 +65,7 @@ public class PartyManager extends MiniPlugin
{
Party party = new Party(this);
party.JoinParty(player);
_parties.add(party);
_partyLeaderMap.put(player.getName(), party);
return party;
}
@ -76,51 +77,31 @@ public class PartyManager extends MiniPlugin
public void addParty(Party party)
{
for (Party parties : _parties)
{
if (parties.GetLeader().equalsIgnoreCase(party.GetLeader()))
{
parties.resetWaitingTime();
return;
}
}
_parties.add(party);
if (_partyLeaderMap.containsKey(party.GetLeader()))
_partyLeaderMap.get(party.GetLeader()).resetWaitingTime();
else
_partyLeaderMap.put(party.GetLeader(), party);
}
@EventHandler
public void serverTransfer(ServerTransferEvent event)
{
for (Party party : _parties)
Party party = _partyLeaderMap.get(event.getPlayer().getName());
if (party != null)
{
if (party.GetLeader().equals(event.getPlayer().getName()))
party.switchedServer();
RedisPartyData data = new RedisPartyData(party, _serverName);
data.setTargetServers(event.getServer());
data.publish();
for (Player player : party.GetPlayersOnline())
{
party.switchedServer();
boolean destLobby = event.getServer().equalsIgnoreCase("lobby");
RedisPartyData data = new RedisPartyData(party, destLobby ? _serverName : null);
if (!destLobby)
if (player != event.getPlayer())
{
data.setTargetServers(event.getServer());
_portal.sendPlayerToServer(player, event.getServer(), false);
}
data.publish();
if (!destLobby)
{
for (Player player : party.GetPlayersOnline())
{
if (player != event.getPlayer())
{
_portal.sendPlayerToServer(player, event.getServer(), false);
}
}
}
break;
}
}
}
@ -130,7 +111,7 @@ public class PartyManager extends MiniPlugin
{
try
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.PlayerJoin(event.getPlayer());
}
@ -144,7 +125,7 @@ public class PartyManager extends MiniPlugin
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.PlayerQuit(event.getPlayer());
}
@ -158,7 +139,7 @@ public class PartyManager extends MiniPlugin
ExpireParties();
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.ExpireInvitees();
party.UpdateScoreboard();
@ -167,7 +148,7 @@ public class PartyManager extends MiniPlugin
public void ExpireParties()
{
Iterator<Party> partyIterator = _parties.iterator();
Iterator<Party> partyIterator = _partyLeaderMap.values().iterator();
while (partyIterator.hasNext())
{
@ -184,7 +165,7 @@ public class PartyManager extends MiniPlugin
public Party GetParty(Player player)
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
if (party.GetPlayers().contains(player.getName()))
{