diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java index 7f5a0df4c..c2d0d9b76 100644 --- a/src/main/java/com/gmail/nossr50/api/PartyAPI.java +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -82,7 +82,7 @@ public final class PartyAPI { Party party = PartyManager.getParty(partyName); if (party == null) { - party = new Party(new PartyLeader(player.getName(), player.getUniqueId()), partyName); + party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName); } PartyManager.addToParty(UserManager.getPlayer(player), party); @@ -136,7 +136,7 @@ public final class PartyAPI { public static List getOnlineAndOfflineMembers(Player player) { List members = new ArrayList(); - for (UUID memberUniqueId : PartyManager.getAllMembers(player).values()) { + for (UUID memberUniqueId : PartyManager.getAllMembers(player).keySet()) { OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId); members.add(member); } @@ -153,7 +153,7 @@ public final class PartyAPI { */ @Deprecated public static LinkedHashSet getMembers(Player player) { - return (LinkedHashSet) PartyManager.getAllMembers(player).keySet(); + return (LinkedHashSet) PartyManager.getAllMembers(player).values(); } /** @@ -164,7 +164,7 @@ public final class PartyAPI { * @param player The player to check * @return all the player names and uuids in the player's party */ - public static LinkedHashMap getMembersMap(Player player) { + public static LinkedHashMap getMembersMap(Player player) { return PartyManager.getAllMembers(player); } 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 4dd9f0532..55575f353 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -22,8 +22,7 @@ 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 LinkedHashMap members = new LinkedHashMap(); private final List onlineMembers = new ArrayList(); private PartyLeader leader; @@ -70,7 +69,7 @@ public class Party { this.level = 0; } - public LinkedHashMap getMembers() { + public LinkedHashMap getMembers() { return members; } @@ -317,9 +316,9 @@ public class Party { public String createMembersList(String playerName, List nearMembers) { StringBuilder memberList = new StringBuilder(); - for (Entry memberEntry : this.getMembers().entrySet()) { - String memberName = memberEntry.getKey(); - UUID uuid = memberEntry.getValue(); + for (Entry memberEntry : this.getMembers().entrySet()) { + UUID uuid = memberEntry.getKey(); + String memberName = memberEntry.getValue(); Player member = mcMMO.p.getServer().getPlayer(uuid); diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/PartyLeader.java b/src/main/java/com/gmail/nossr50/datatypes/party/PartyLeader.java index b39f900d2..3292b3723 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/PartyLeader.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/PartyLeader.java @@ -3,19 +3,19 @@ package com.gmail.nossr50.datatypes.party; import java.util.UUID; public class PartyLeader { - private String playerName; private UUID uuid; + private String playerName; - public PartyLeader(String playerName, UUID uuid) { - this.playerName = playerName; + public PartyLeader(UUID uuid, String playerName) { this.uuid = uuid; - } - - public String getPlayerName() { - return playerName; + this.playerName = playerName; } public UUID getUniqueId() { return uuid; } + + public String getPlayerName() { + return playerName; + } } diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index 9eea7bd44..d65b875d6 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -135,10 +135,10 @@ public final class PartyManager { * @param player The player to check * @return all the players in the player's party */ - public static LinkedHashMap getAllMembers(Player player) { + public static LinkedHashMap getAllMembers(Player player) { Party party = getParty(player); - return party == null ? new LinkedHashMap() : party.getMembers(); + return party == null ? new LinkedHashMap() : party.getMembers(); } /** @@ -206,12 +206,12 @@ public final class PartyManager { */ public static Party getPlayerParty(String playerName, UUID uuid) { for (Party party : parties) { - LinkedHashMap members = party.getMembers(); - if (members.keySet().contains(playerName) || members.values().contains(uuid)) { + LinkedHashMap members = party.getMembers(); + if (members.keySet().contains(uuid) || members.values().contains(playerName)) { // Name changes - if (!members.get(playerName).equals(uuid)) { - members.put(playerName, uuid); + if (members.get(uuid) == null || !members.get(uuid).equals(playerName)) { + members.put(uuid, playerName); } return party; @@ -249,10 +249,10 @@ public final class PartyManager { * @param party The party */ public static void removeFromParty(OfflinePlayer player, Party party) { - LinkedHashMap members = party.getMembers(); + LinkedHashMap members = party.getMembers(); String playerName = player.getName(); - members.remove(playerName); + members.remove(player.getUniqueId()); if (player.isOnline()) { party.getOnlineMembers().remove(player.getPlayer()); @@ -264,7 +264,7 @@ public final class PartyManager { else { // If the leaving player was the party leader, appoint a new leader from the party members if (party.getLeader().getUniqueId().equals(player.getUniqueId())) { - setPartyLeader(members.values().iterator().next(), party); + setPartyLeader(members.keySet().iterator().next(), party); } informPartyMembersQuit(party, playerName); @@ -308,9 +308,8 @@ public final class PartyManager { */ public static void createParty(McMMOPlayer mcMMOPlayer, String partyName, String password) { Player player = mcMMOPlayer.getPlayer(); - String playerName = player.getName(); - Party party = new Party(new PartyLeader(playerName, player.getUniqueId()), partyName.replace(".", ""), password); + Party party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName.replace(".", ""), password); if (password != null) { player.sendMessage(LocaleLoader.getString("Party.Password.Set", password)); @@ -444,7 +443,7 @@ public final class PartyManager { informPartyMembersJoin(party, playerName); mcMMOPlayer.setParty(party); - party.getMembers().put(player.getName(), player.getUniqueId()); + party.getMembers().put(player.getUniqueId(), player.getName()); party.getOnlineMembers().add(player); } @@ -484,7 +483,7 @@ public final class PartyManager { } } - party.setLeader(new PartyLeader(player.getName(), player.getUniqueId())); + party.setLeader(new PartyLeader(player.getUniqueId(), player.getName())); } /** @@ -514,12 +513,7 @@ public final class PartyManager { Party party = new Party(partyName); String[] leaderSplit = partiesFile.getString(partyName + ".Leader").split("[|]"); - UUID leaderUniqueId = null; - if (leaderSplit.length == 2) { - leaderUniqueId = UUID.fromString(leaderSplit[1]); - } - party.setLeader(new PartyLeader(leaderSplit[0], leaderUniqueId)); - + party.setLeader(new PartyLeader(UUID.fromString(leaderSplit[0]), leaderSplit[1])); party.setPassword(partiesFile.getString(partyName + ".Password")); party.setLocked(partiesFile.getBoolean(partyName + ".Locked")); party.setLevel(partiesFile.getInt(partyName + ".Level")); @@ -536,18 +530,11 @@ public final class PartyManager { party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true)); } - List memberEntries = partiesFile.getStringList(partyName + ".Members"); - LinkedHashMap members = party.getMembers(); + LinkedHashMap members = party.getMembers(); - for (String memberEntry : memberEntries) { + for (String memberEntry : partiesFile.getStringList(partyName + ".Members")) { String[] memberSplit = memberEntry.split("[|]"); - - if (memberSplit.length != 2) { - members.put(memberSplit[0], null); - continue; - } - - members.put(memberSplit[0], UUID.fromString(memberSplit[1])); + members.put(UUID.fromString(memberSplit[0]), memberSplit[1]); } parties.add(party); @@ -575,9 +562,9 @@ public final class PartyManager { mcMMO.p.debug("Saving Parties... (" + parties.size() + ")"); for (Party party : parties) { String partyName = party.getName(); + PartyLeader leader = party.getLeader(); - String partyLeader = party.getLeader().getPlayerName() + "|" + party.getLeader().getUniqueId().toString(); - partiesFile.set(partyName + ".Leader", partyLeader); + partiesFile.set(partyName + ".Leader", leader.getUniqueId().toString() + "|" + leader.getPlayerName()); partiesFile.set(partyName + ".Password", party.getPassword()); partiesFile.set(partyName + ".Locked", party.isLocked()); partiesFile.set(partyName + ".Level", party.getLevel()); @@ -590,17 +577,18 @@ public final class PartyManager { partiesFile.set(partyName + ".ItemShareType." + itemShareType.toString(), party.sharingDrops(itemShareType)); } - List memberNames = new ArrayList(); + List members = new ArrayList(); - for (Entry memberEntry : party.getMembers().entrySet()) { - String memberName = memberEntry.getKey(); - String memberUniqueId = memberEntry.getValue() == null ? "" : memberEntry.getValue().toString(); - if (!memberNames.contains(memberName)) { - memberNames.add(memberName + "|" + memberUniqueId); + for (Entry memberEntry : party.getMembers().entrySet()) { + String memberUniqueId = memberEntry.getKey() == null ? "" : memberEntry.getKey().toString(); + String memberName = memberEntry.getValue(); + + if (!members.contains(memberName)) { + members.add(memberUniqueId + "|" + memberName); } } - partiesFile.set(partyName + ".Members", memberNames); + partiesFile.set(partyName + ".Members", members); } try { diff --git a/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java b/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java index dba44efb3..a6db5a918 100644 --- a/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/party/PartyAutoKickTask.java @@ -25,7 +25,7 @@ public class PartyAutoKickTask extends BukkitRunnable { long currentTime = System.currentTimeMillis(); for (Party party : PartyManager.getParties()) { - for (UUID memberUniqueId : party.getMembers().values()) { + for (UUID memberUniqueId : party.getMembers().keySet()) { OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId); boolean isProcessed = processedPlayers.contains(memberUniqueId);