mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Use LinkedHashMap<UUID, String> instead
This commit is contained in:
parent
e8b54cd537
commit
5b5763dccf
@ -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<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
|
||||
List<OfflinePlayer> members = new ArrayList<OfflinePlayer>();
|
||||
|
||||
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<String> getMembers(Player player) {
|
||||
return (LinkedHashSet<String>) PartyManager.getAllMembers(player).keySet();
|
||||
return (LinkedHashSet<String>) 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<String, UUID> getMembersMap(Player player) {
|
||||
public static LinkedHashMap<UUID, String> getMembersMap(Player player) {
|
||||
return PartyManager.getAllMembers(player);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,7 @@ 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 LinkedHashMap<UUID, String> members = new LinkedHashMap<UUID, String>();
|
||||
private final List<Player> onlineMembers = new ArrayList<Player>();
|
||||
|
||||
private PartyLeader leader;
|
||||
@ -70,7 +69,7 @@ public class Party {
|
||||
this.level = 0;
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, UUID> getMembers() {
|
||||
public LinkedHashMap<UUID, String> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
@ -317,9 +316,9 @@ public class Party {
|
||||
public String createMembersList(String playerName, List<Player> nearMembers) {
|
||||
StringBuilder memberList = new StringBuilder();
|
||||
|
||||
for (Entry<String, UUID> memberEntry : this.getMembers().entrySet()) {
|
||||
String memberName = memberEntry.getKey();
|
||||
UUID uuid = memberEntry.getValue();
|
||||
for (Entry<UUID, String> memberEntry : this.getMembers().entrySet()) {
|
||||
UUID uuid = memberEntry.getKey();
|
||||
String memberName = memberEntry.getValue();
|
||||
|
||||
Player member = mcMMO.p.getServer().getPlayer(uuid);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<String, UUID> getAllMembers(Player player) {
|
||||
public static LinkedHashMap<UUID, String> getAllMembers(Player player) {
|
||||
Party party = getParty(player);
|
||||
|
||||
return party == null ? new LinkedHashMap<String, UUID>() : party.getMembers();
|
||||
return party == null ? new LinkedHashMap<UUID, String>() : party.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,12 +206,12 @@ public final class PartyManager {
|
||||
*/
|
||||
public static Party getPlayerParty(String playerName, UUID uuid) {
|
||||
for (Party party : parties) {
|
||||
LinkedHashMap<String, UUID> members = party.getMembers();
|
||||
if (members.keySet().contains(playerName) || members.values().contains(uuid)) {
|
||||
LinkedHashMap<UUID, String> 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<String, UUID> members = party.getMembers();
|
||||
LinkedHashMap<UUID, String> 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<String> memberEntries = partiesFile.getStringList(partyName + ".Members");
|
||||
LinkedHashMap<String, UUID> members = party.getMembers();
|
||||
LinkedHashMap<UUID, String> 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<String> memberNames = new ArrayList<String>();
|
||||
List<String> members = new ArrayList<String>();
|
||||
|
||||
for (Entry<String, UUID> 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<UUID, String> 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 {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user