Keep a list of online party members in memory

This commit is contained in:
TfT_02 2014-08-07 14:51:50 -07:00 committed by TfT_02
parent 153bdc73f8
commit cc2c2c3254
4 changed files with 31 additions and 10 deletions

View File

@ -22,7 +22,9 @@ import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
public class Party { public class Party {
//TODO use LinkedHashSet<PartyMember> and get rid of PartyLeader object
private final LinkedHashMap<String, UUID> members = new LinkedHashMap<String, UUID>(); private final LinkedHashMap<String, UUID> members = new LinkedHashMap<String, UUID>();
private final List<Player> onlineMembers = new ArrayList<Player>();
private PartyLeader leader; private PartyLeader leader;
private String name; private String name;
@ -73,16 +75,6 @@ public class Party {
} }
public List<Player> getOnlineMembers() { public List<Player> getOnlineMembers() {
List<Player> onlineMembers = new ArrayList<Player>();
for (UUID uuid : members.values()) {
Player member = mcMMO.p.getServer().getPlayer(uuid);
if (member != null) {
onlineMembers.add(member);
}
}
return onlineMembers; return onlineMembers;
} }
@ -99,6 +91,14 @@ public class Party {
return onlinePlayerNames; return onlinePlayerNames;
} }
public boolean addOnlineMember(Player player) {
return onlineMembers.add(player);
}
public boolean removeOnlineMember(Player player) {
return onlineMembers.remove(player);
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -101,6 +101,10 @@ public class McMMOPlayer {
party = PartyManager.getPlayerParty(playerName, uuid); party = PartyManager.getPlayerParty(playerName, uuid);
ptpRecord = new PartyTeleportRecord(); ptpRecord = new PartyTeleportRecord();
if (inParty()) {
loginParty();
}
if (profile.getUniqueId() == null) { if (profile.getUniqueId() == null) {
profile.setUniqueId(uuid); profile.setUniqueId(uuid);
} }
@ -577,6 +581,14 @@ public class McMMOPlayer {
allianceInvite = null; allianceInvite = null;
} }
public void loginParty() {
party.addOnlineMember(this.getPlayer());
}
public void logoutParty() {
party.removeOnlineMember(this.getPlayer());
}
public int getItemShareModifier() { public int getItemShareModifier() {
if (itemShareModifier < 10) { if (itemShareModifier < 10) {
setItemShareModifier(10); setItemShareModifier(10);

View File

@ -367,6 +367,10 @@ public class PlayerListener implements Listener {
mcMMOPlayer.getProfile().scheduleAsyncSave(); mcMMOPlayer.getProfile().scheduleAsyncSave();
UserManager.remove(player); UserManager.remove(player);
ScoreboardManager.teardownPlayer(player); ScoreboardManager.teardownPlayer(player);
if (mcMMOPlayer.inParty()) {
mcMMOPlayer.logoutParty();
}
} }
/** /**

View File

@ -254,6 +254,10 @@ public final class PartyManager {
members.remove(playerName); members.remove(playerName);
if (player.isOnline()) {
party.getOnlineMembers().remove(player.getPlayer());
}
if (members.isEmpty()) { if (members.isEmpty()) {
parties.remove(party); parties.remove(party);
} }
@ -441,6 +445,7 @@ public final class PartyManager {
informPartyMembersJoin(party, playerName); informPartyMembersJoin(party, playerName);
mcMMOPlayer.setParty(party); mcMMOPlayer.setParty(party);
party.getMembers().put(player.getName(), player.getUniqueId()); party.getMembers().put(player.getName(), player.getUniqueId());
party.getOnlineMembers().add(player);
} }
/** /**