mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-12-01 17:36:46 +01:00
Keep a list of online party members in memory
This commit is contained in:
parent
153bdc73f8
commit
cc2c2c3254
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -367,6 +367,10 @@ public class PlayerListener implements Listener {
|
||||
mcMMOPlayer.getProfile().scheduleAsyncSave();
|
||||
UserManager.remove(player);
|
||||
ScoreboardManager.teardownPlayer(player);
|
||||
|
||||
if (mcMMOPlayer.inParty()) {
|
||||
mcMMOPlayer.logoutParty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user