diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java index bb5c9e718..038c0b65e 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -22,7 +22,9 @@ import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Misc; public class Party { + //TODO use LinkedHashSet and get rid of PartyLeader object private final LinkedHashMap members = new LinkedHashMap(); + private final List onlineMembers = new ArrayList(); private PartyLeader leader; private String name; @@ -73,16 +75,6 @@ public class Party { } public List getOnlineMembers() { - List onlineMembers = new ArrayList(); - - 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; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index fa5913615..a818d7665 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -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); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 0e7356af5..95a6e4039 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -367,6 +367,10 @@ public class PlayerListener implements Listener { mcMMOPlayer.getProfile().scheduleAsyncSave(); UserManager.remove(player); ScoreboardManager.teardownPlayer(player); + + if (mcMMOPlayer.inParty()) { + mcMMOPlayer.logoutParty(); + } } /** diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index ae365b71f..9eea7bd44 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -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); } /**