UUID support for parties

This commit is contained in:
TfT_02 2014-07-12 19:44:47 +02:00
parent d62c68a490
commit 2dd8e719c8
14 changed files with 264 additions and 79 deletions

View File

@ -1,14 +1,17 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyLeader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
@ -79,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(player.getName(), partyName); party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName);
} }
PartyManager.addToParty(UserManager.getPlayer(player), party); PartyManager.addToParty(UserManager.getPlayer(player), party);
@ -105,7 +108,7 @@ public final class PartyAPI {
* @return the leader of the party * @return the leader of the party
*/ */
public static String getPartyLeader(String partyName) { public static String getPartyLeader(String partyName) {
return PartyManager.getPartyLeader(partyName); return PartyManager.getPartyLeaderName(partyName);
} }
/** /**
@ -114,10 +117,11 @@ public final class PartyAPI {
* This function is designed for API usage. * This function is designed for API usage.
* *
* @param partyName The name of the party to set the leader of * @param partyName The name of the party to set the leader of
* @param player The player to set as leader * @param playerName The playerName to set as leader
*/ */
public static void setPartyLeader(String partyName, String player) { @Deprecated
PartyManager.setPartyLeader(player, PartyManager.getParty(partyName)); public static void setPartyLeader(String partyName, String playerName) {
PartyManager.setPartyLeader(mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId(), PartyManager.getParty(partyName));
} }
/** /**
@ -132,8 +136,8 @@ 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 (String memberName : PartyManager.getAllMembers(player)) { for (UUID memberUniqueId : PartyManager.getAllMembers(player).keySet()) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName); OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId);
members.add(member); members.add(member);
} }
return members; return members;
@ -147,7 +151,20 @@ public final class PartyAPI {
* @param player The player to check * @param player The player to check
* @return all the player names in the player's party * @return all the player names in the player's party
*/ */
@Deprecated
public static LinkedHashSet<String> getMembers(Player player) { public static LinkedHashSet<String> getMembers(Player player) {
return (LinkedHashSet<String>) PartyManager.getAllMembers(player).values();
}
/**
* Get a list of all player names and uuids in this player's party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return all the player names and uuids in the player's party
*/
public static LinkedHashMap<UUID, String> getMembersMap(Player player) {
return PartyManager.getAllMembers(player); return PartyManager.getAllMembers(player);
} }

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.commands.party; package com.gmail.nossr50.commands.party;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
@ -18,13 +20,14 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
case 2: case 2:
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer((Player) sender).getParty();
String targetName = CommandUtils.getMatchedPlayerName(args[1]); String targetName = CommandUtils.getMatchedPlayerName(args[1]);
OfflinePlayer target = mcMMO.p.getServer().getOfflinePlayer(targetName);
if (!playerParty.getMembers().contains(targetName)) { if (!playerParty.hasMember(target.getUniqueId())) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return true; return true;
} }
PartyManager.setPartyLeader(targetName, playerParty); PartyManager.setPartyLeader(target.getUniqueId(), playerParty);
return true; return true;
default: default:

View File

@ -134,7 +134,7 @@ public class PartyCommand implements TabExecutor {
} }
// Party leader commands // Party leader commands
if (!mcMMOPlayer.getParty().getLeader().equalsIgnoreCase(player.getName())) { if (!mcMMOPlayer.getParty().getLeader().getUniqueId().equals(player.getUniqueId())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner")); sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true; return true;
} }

View File

@ -22,7 +22,7 @@ public class PartyKickCommand implements CommandExecutor {
Party playerParty = UserManager.getPlayer((Player) sender).getParty(); Party playerParty = UserManager.getPlayer((Player) sender).getParty();
String targetName = CommandUtils.getMatchedPlayerName(args[1]); String targetName = CommandUtils.getMatchedPlayerName(args[1]);
if (!playerParty.getMembers().contains(targetName)) { if (!playerParty.hasMember(targetName)) {
sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName)); sender.sendMessage(LocaleLoader.getString("Party.NotInYourParty", targetName));
return true; return true;
} }

View File

@ -36,7 +36,7 @@ public class PartyRenameCommand implements CommandExecutor {
return true; return true;
} }
String leaderName = playerParty.getLeader(); String leaderName = playerParty.getLeader().getPlayerName();
for (Player member : playerParty.getOnlineMembers()) { for (Player member : playerParty.getOnlineMembers()) {
if (!PartyManager.handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) { if (!PartyManager.handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) {

View File

@ -44,7 +44,7 @@ public class PartyAllianceInviteCommand implements CommandExecutor {
return true; return true;
} }
if (!mcMMOTarget.getParty().getLeader().equalsIgnoreCase(targetName)) { if (!mcMMOTarget.getParty().getLeader().getUniqueId().equals(target.getUniqueId())) {
player.sendMessage(LocaleLoader.getString("Party.Target.NotOwner", targetName)); player.sendMessage(LocaleLoader.getString("Party.Target.NotOwner", targetName));
return true; return true;
} }

View File

@ -8,5 +8,6 @@ public enum UpgradeType {
DROP_SQL_PARTY_NAMES, DROP_SQL_PARTY_NAMES,
DROP_SPOUT, DROP_SPOUT,
ADD_ALCHEMY, ADD_ALCHEMY,
ADD_UUIDS; ADD_UUIDS,
ADD_UUIDS_PARTY;
} }

View File

@ -2,8 +2,10 @@ package com.gmail.nossr50.datatypes.party;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -20,9 +22,10 @@ import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
public class Party { public class Party {
private final LinkedHashSet<String> members = new LinkedHashSet<String>(); private final LinkedHashMap<UUID, String> members = new LinkedHashMap<UUID, String>();
private final List<Player> onlineMembers = new ArrayList<Player>();
private String leader; private PartyLeader leader;
private String name; private String name;
private String password; private String password;
private boolean locked; private boolean locked;
@ -43,14 +46,14 @@ public class Party {
this.name = name; this.name = name;
} }
public Party(String leader, String name) { public Party(PartyLeader leader, String name) {
this.leader = leader; this.leader = leader;
this.name = name; this.name = name;
this.locked = true; this.locked = true;
this.level = 0; this.level = 0;
} }
public Party(String leader, String name, String password) { public Party(PartyLeader leader, String name, String password) {
this.leader = leader; this.leader = leader;
this.name = name; this.name = name;
this.password = password; this.password = password;
@ -58,7 +61,7 @@ public class Party {
this.level = 0; this.level = 0;
} }
public Party(String leader, String name, String password, boolean locked) { public Party(PartyLeader leader, String name, String password, boolean locked) {
this.leader = leader; this.leader = leader;
this.name = name; this.name = name;
this.password = password; this.password = password;
@ -66,21 +69,11 @@ public class Party {
this.level = 0; this.level = 0;
} }
public LinkedHashSet<String> getMembers() { public LinkedHashMap<UUID, String> getMembers() {
return members; return members;
} }
public List<Player> getOnlineMembers() { public List<Player> getOnlineMembers() {
List<Player> onlineMembers = new ArrayList<Player>();
for (String memberName : members) {
Player member = mcMMO.p.getServer().getPlayerExact(memberName);
if (member != null) {
onlineMembers.add(member);
}
}
return onlineMembers; return onlineMembers;
} }
@ -97,11 +90,19 @@ public class Party {
return onlinePlayerNames; return onlinePlayerNames;
} }
public boolean addOnlineMember(Player player) {
return onlineMembers.add(player);
}
public boolean removeOnlineMember(Player player) {
return onlineMembers.remove(player);
}
public String getName() { public String getName() {
return name; return name;
} }
public String getLeader() { public PartyLeader getLeader() {
return leader; return leader;
} }
@ -133,7 +134,7 @@ public class Party {
this.name = name; this.name = name;
} }
public void setLeader(String leader) { public void setLeader(PartyLeader leader) {
this.leader = leader; this.leader = leader;
} }
@ -220,7 +221,8 @@ public class Party {
} }
if (!Config.getInstance().getPartyInformAllMembers()) { if (!Config.getInstance().getPartyInformAllMembers()) {
Player leader = mcMMO.p.getServer().getPlayer(this.leader); Player leader = mcMMO.p.getServer().getPlayer(this.leader.getUniqueId());
if (leader != null) { if (leader != null) {
leader.sendMessage(LocaleLoader.getString("Party.LevelUp", levelsGained, getLevel())); leader.sendMessage(LocaleLoader.getString("Party.LevelUp", levelsGained, getLevel()));
@ -303,13 +305,24 @@ public class Party {
} }
} }
public boolean hasMember(String memberName) {
return this.getMembers().keySet().contains(memberName);
}
public boolean hasMember(UUID uuid) {
return this.getMembers().values().contains(uuid);
}
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 (String memberName : this.getMembers()) { for (Entry<UUID, String> memberEntry : this.getMembers().entrySet()) {
Player member = mcMMO.p.getServer().getPlayerExact(memberName); UUID uuid = memberEntry.getKey();
String memberName = memberEntry.getValue();
if (this.getLeader().equalsIgnoreCase(memberName)) { Player member = mcMMO.p.getServer().getPlayer(uuid);
if (this.getLeader().getUniqueId().equals(uuid)) {
memberList.append(ChatColor.GOLD); memberList.append(ChatColor.GOLD);
if (member == null) { if (member == null) {

View File

@ -0,0 +1,21 @@
package com.gmail.nossr50.datatypes.party;
import java.util.UUID;
public class PartyLeader {
private UUID uuid;
private String playerName;
public PartyLeader(UUID uuid, String playerName) {
this.uuid = uuid;
this.playerName = playerName;
}
public UUID getUniqueId() {
return uuid;
}
public String getPlayerName() {
return playerName;
}
}

View File

@ -98,9 +98,13 @@ public class McMMOPlayer {
this.player = player; this.player = player;
playerMetadata = new FixedMetadataValue(mcMMO.p, playerName); playerMetadata = new FixedMetadataValue(mcMMO.p, playerName);
this.profile = profile; this.profile = profile;
party = PartyManager.getPlayerParty(playerName); party = PartyManager.getPlayerParty(playerName, uuid);
ptpRecord = new PartyTeleportRecord(); ptpRecord = new PartyTeleportRecord();
if (inParty()) {
loginParty();
}
if (profile.getUniqueId() == null) { if (profile.getUniqueId() == null) {
profile.setUniqueId(uuid); profile.setUniqueId(uuid);
} }
@ -577,6 +581,14 @@ public class McMMOPlayer {
allianceInvite = null; allianceInvite = null;
} }
public void loginParty() {
party.addOnlineMember(this.getPlayer());
}
public void logoutParty() {
party.removeOnlineMember(this.getPlayer());
}
public int getItemShareModifier() { public int getItemShareModifier() {
if (itemShareModifier < 10) { if (itemShareModifier < 10) {
setItemShareModifier(10); setItemShareModifier(10);

View File

@ -367,6 +367,10 @@ public class PlayerListener implements Listener {
mcMMOPlayer.getProfile().scheduleAsyncSave(); mcMMOPlayer.getProfile().scheduleAsyncSave();
UserManager.remove(player); UserManager.remove(player);
ScoreboardManager.teardownPlayer(player); ScoreboardManager.teardownPlayer(player);
if (mcMMOPlayer.inParty()) {
mcMMOPlayer.logoutParty();
}
} }
/** /**

View File

@ -2,8 +2,10 @@ package com.gmail.nossr50.party;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -13,10 +15,13 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.chat.ChatMode; import com.gmail.nossr50.datatypes.chat.ChatMode;
import com.gmail.nossr50.datatypes.database.UpgradeType;
import com.gmail.nossr50.datatypes.party.ItemShareType; import com.gmail.nossr50.datatypes.party.ItemShareType;
import com.gmail.nossr50.datatypes.party.Party; import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.party.PartyLeader;
import com.gmail.nossr50.datatypes.party.ShareMode; import com.gmail.nossr50.datatypes.party.ShareMode;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent; import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason; import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
@ -132,10 +137,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 LinkedHashSet<String> getAllMembers(Player player) { public static LinkedHashMap<UUID, String> getAllMembers(Player player) {
Party party = getParty(player); Party party = getParty(player);
return party == null ? new LinkedHashSet<String>() : party.getMembers(); return party == null ? new LinkedHashMap<UUID, String>() : party.getMembers();
} }
/** /**
@ -184,9 +189,33 @@ public final class PartyManager {
* @param playerName The members name * @param playerName The members name
* @return the existing party, null otherwise * @return the existing party, null otherwise
*/ */
@Deprecated
public static Party getPlayerParty(String playerName) { public static Party getPlayerParty(String playerName) {
for (Party party : parties) { for (Party party : parties) {
if (party.getMembers().contains(playerName)) { if (party.getMembers().keySet().contains(playerName)) {
return party;
}
}
return null;
}
/**
* Retrieve a party by a members uuid
*
* @param uuid The members uuid
* @return the existing party, null otherwise
*/
public static Party getPlayerParty(String playerName, UUID uuid) {
for (Party party : parties) {
LinkedHashMap<UUID, String> members = party.getMembers();
if (members.keySet().contains(uuid) || members.values().contains(playerName)) {
// Name changes
if (members.get(uuid) == null || !members.get(uuid).equals(playerName)) {
members.put(uuid, playerName);
}
return party; return party;
} }
} }
@ -222,18 +251,22 @@ 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) {
LinkedHashSet<String> 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()) {
party.getOnlineMembers().remove(player.getPlayer());
}
if (members.isEmpty()) { if (members.isEmpty()) {
parties.remove(party); parties.remove(party);
} }
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().equalsIgnoreCase(playerName)) { if (party.getLeader().getUniqueId().equals(player.getUniqueId())) {
setPartyLeader(members.iterator().next(), party); setPartyLeader(members.keySet().iterator().next(), party);
} }
informPartyMembersQuit(party, playerName); informPartyMembersQuit(party, playerName);
@ -277,9 +310,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(playerName, 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));
@ -408,11 +440,13 @@ public final class PartyManager {
* @param party The party * @param party The party
*/ */
public static void addToParty(McMMOPlayer mcMMOPlayer, Party party) { public static void addToParty(McMMOPlayer mcMMOPlayer, Party party) {
String playerName = mcMMOPlayer.getPlayer().getName(); Player player = mcMMOPlayer.getPlayer();
String playerName = player.getName();
informPartyMembersJoin(party, playerName); informPartyMembersJoin(party, playerName);
mcMMOPlayer.setParty(party); mcMMOPlayer.setParty(party);
party.getMembers().add(playerName); party.getMembers().put(player.getUniqueId(), player.getName());
party.getOnlineMembers().add(player);
} }
/** /**
@ -421,36 +455,37 @@ public final class PartyManager {
* @param partyName The party name * @param partyName The party name
* @return the leader of the party * @return the leader of the party
*/ */
public static String getPartyLeader(String partyName) { public static String getPartyLeaderName(String partyName) {
Party party = getParty(partyName); Party party = getParty(partyName);
return party == null ? null : party.getLeader(); return party == null ? null : party.getLeader().getPlayerName();
} }
/** /**
* Set the leader of a party. * Set the leader of a party.
* *
* @param playerName The name of the player to set as leader * @param uuid The uuid of the player to set as leader
* @param party The party * @param party The party
*/ */
public static void setPartyLeader(String playerName, Party party) { public static void setPartyLeader(UUID uuid, Party party) {
String leaderName = party.getLeader(); OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(uuid);
UUID leaderUniqueId = party.getLeader().getUniqueId();
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
String memberName = member.getName(); UUID memberUniqueId = member.getUniqueId();
if (memberName.equalsIgnoreCase(playerName)) { if (memberUniqueId.equals(player.getUniqueId())) {
member.sendMessage(LocaleLoader.getString("Party.Owner.Player")); member.sendMessage(LocaleLoader.getString("Party.Owner.Player"));
} }
else if (memberName.equalsIgnoreCase(leaderName)) { else if (memberUniqueId.equals(leaderUniqueId)) {
member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader")); member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader"));
} }
else { else {
member.sendMessage(LocaleLoader.getString("Party.Owner.New", playerName)); member.sendMessage(LocaleLoader.getString("Party.Owner.New", player.getName()));
} }
} }
party.setLeader(playerName); party.setLeader(new PartyLeader(player.getUniqueId(), player.getName()));
} }
/** /**
@ -461,7 +496,7 @@ public final class PartyManager {
public static boolean canInvite(McMMOPlayer mcMMOPlayer) { public static boolean canInvite(McMMOPlayer mcMMOPlayer) {
Party party = mcMMOPlayer.getParty(); Party party = mcMMOPlayer.getParty();
return !party.isLocked() || party.getLeader().equalsIgnoreCase(mcMMOPlayer.getPlayer().getName()); return !party.isLocked() || party.getLeader().getUniqueId().equals(mcMMOPlayer.getPlayer().getUniqueId());
} }
/** /**
@ -472,6 +507,11 @@ public final class PartyManager {
return; return;
} }
if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS_PARTY)) {
loadAndUpgradeParties();
return;
}
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile); YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
ArrayList<Party> hasAlly = new ArrayList<Party>(); ArrayList<Party> hasAlly = new ArrayList<Party>();
@ -479,7 +519,8 @@ public final class PartyManager {
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) { for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
Party party = new Party(partyName); Party party = new Party(partyName);
party.setLeader(partiesFile.getString(partyName + ".Leader")); String[] leaderSplit = partiesFile.getString(partyName + ".Leader").split("[|]");
party.setLeader(new PartyLeader(UUID.fromString(leaderSplit[0]), leaderSplit[1]));
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"));
@ -496,18 +537,19 @@ 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> memberNames = partiesFile.getStringList(partyName + ".Members"); LinkedHashMap<UUID, String> members = party.getMembers();
LinkedHashSet<String> members = party.getMembers();
for (String memberName : memberNames) { for (String memberEntry : partiesFile.getStringList(partyName + ".Members")) {
members.add(memberName); String[] memberSplit = memberEntry.split("[|]");
members.put(UUID.fromString(memberSplit[0]), memberSplit[1]);
} }
parties.add(party); parties.add(party);
} }
mcMMO.p.debug("Loaded (" + parties.size() + ") Parties...");
for (Party party : hasAlly) { for (Party party : hasAlly) {
party.setAlly(getParty(partiesFile.getString(party.getName() + ".Ally"))); party.setAlly(PartyManager.getParty(partiesFile.getString(party.getName() + ".Ally")));
} }
} }
@ -527,8 +569,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();
partiesFile.set(partyName + ".Leader", party.getLeader()); partiesFile.set(partyName + ".Leader", leader.getUniqueId().toString() + "|" + leader.getPlayerName());
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());
@ -541,15 +584,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 (String member : party.getMembers()) { for (Entry<UUID, String> memberEntry : party.getMembers().entrySet()) {
if (!memberNames.contains(member)) { String memberUniqueId = memberEntry.getKey() == null ? "" : memberEntry.getKey().toString();
memberNames.add(member); String memberName = memberEntry.getValue();
if (!members.contains(memberName)) {
members.add(memberUniqueId + "|" + memberName);
} }
} }
partiesFile.set(partyName + ".Members", memberNames); partiesFile.set(partyName + ".Members", members);
} }
try { try {
@ -560,6 +606,73 @@ public final class PartyManager {
} }
} }
private static void loadAndUpgradeParties() {
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
if (!partyFile.renameTo(new File(mcMMO.getFlatFileDirectory() + "parties.yml.converted"))) {
mcMMO.p.getLogger().severe("Could not rename parties.yml to parties.yml.converted!");
return;
}
ArrayList<Party> hasAlly = new ArrayList<Party>();
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
Party party = new Party(partyName);
String leaderName = partiesFile.getString(partyName + ".Leader");
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(leaderName, false);
if (!profile.isLoaded()) {
mcMMO.p.getLogger().warning("Could not find UUID in database for party leader " + leaderName + " in party " + partyName);
continue;
}
UUID leaderUniqueId = profile.getUniqueId();
party.setLeader(new PartyLeader(leaderUniqueId, leaderName));
party.setPassword(partiesFile.getString(partyName + ".Password"));
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
party.setLevel(partiesFile.getInt(partyName + ".Level"));
party.setXp(partiesFile.getInt(partyName + ".Xp"));
if (partiesFile.getString(partyName + ".Ally") != null) {
hasAlly.add(party);
}
party.setXpShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE")));
party.setItemShareMode(ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE")));
for (ItemShareType itemShareType : ItemShareType.values()) {
party.setSharingDrops(itemShareType, partiesFile.getBoolean(partyName + ".ItemShareType." + itemShareType.toString(), true));
}
LinkedHashMap<UUID, String> members = party.getMembers();
for (String memberName : partiesFile.getStringList(partyName + ".Members")) {
PlayerProfile memberProfile = mcMMO.getDatabaseManager().loadPlayerProfile(memberName, false);
if (!memberProfile.isLoaded()) {
mcMMO.p.getLogger().warning("Could not find UUID in database for party member " + memberName + " in party " + partyName);
continue;
}
UUID memberUniqueId = memberProfile.getUniqueId();
members.put(memberUniqueId, memberName);
}
parties.add(party);
}
mcMMO.p.debug("Loaded (" + parties.size() + ") Parties...");
for (Party party : hasAlly) {
party.setAlly(PartyManager.getParty(partiesFile.getString(party.getName() + ".Ally")));
}
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS_PARTY);
}
/** /**
* Handle party change event. * Handle party change event.
* *

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -19,21 +20,21 @@ public class PartyAutoKickTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
HashMap<OfflinePlayer, Party> toRemove = new HashMap<OfflinePlayer, Party>(); HashMap<OfflinePlayer, Party> toRemove = new HashMap<OfflinePlayer, Party>();
List<String> processedPlayers = new ArrayList<String>(); List<UUID> processedPlayers = new ArrayList<UUID>();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
for (Party party : PartyManager.getParties()) { for (Party party : PartyManager.getParties()) {
for (String memberName : party.getMembers()) { for (UUID memberUniqueId : party.getMembers().keySet()) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName); OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId);
boolean isProcessed = processedPlayers.contains(memberName); boolean isProcessed = processedPlayers.contains(memberUniqueId);
if ((!member.isOnline() && (currentTime - member.getLastPlayed() > KICK_TIME)) || isProcessed) { if ((!member.isOnline() && (currentTime - member.getLastPlayed() > KICK_TIME)) || isProcessed) {
toRemove.put(member, party); toRemove.put(member, party);
} }
if (!isProcessed) { if (!isProcessed) {
processedPlayers.add(memberName); processedPlayers.add(memberUniqueId);
} }
} }
} }

View File

@ -31,7 +31,7 @@ public class PartyChatTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader())) { if (Config.getInstance().getPartyChatColorLeaderName() && senderName.equalsIgnoreCase(party.getLeader().getPlayerName())) {
message = message.replaceFirst(Pattern.quote(displayName), ChatColor.GOLD + Matcher.quoteReplacement(displayName) + ChatColor.RESET); message = message.replaceFirst(Pattern.quote(displayName), ChatColor.GOLD + Matcher.quoteReplacement(displayName) + ChatColor.RESET);
} }