From cc2c2c3254d2ef9fa49993a01d4c2e1a60236ec8 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Thu, 7 Aug 2014 14:51:50 -0700 Subject: [PATCH] Keep a list of online party members in memory --- .../gmail/nossr50/datatypes/party/Party.java | 20 +++++++++---------- .../nossr50/datatypes/player/McMMOPlayer.java | 12 +++++++++++ .../nossr50/listeners/PlayerListener.java | 4 ++++ .../com/gmail/nossr50/party/PartyManager.java | 5 +++++ 4 files changed, 31 insertions(+), 10 deletions(-) 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); } /**