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;
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 List<Player> onlineMembers = new ArrayList<Player>();
private PartyLeader leader;
private String name;
@ -73,16 +75,6 @@ public class Party {
}
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;
}
@ -99,6 +91,14 @@ public class Party {
return onlinePlayerNames;
}
public boolean addOnlineMember(Player player) {
return onlineMembers.add(player);
}
public boolean removeOnlineMember(Player player) {
return onlineMembers.remove(player);
}
public String getName() {
return name;
}

View File

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

View File

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

View File

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