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