Fixed bug where players were able to join the same party multiple times

This change should automagically fix broken parties which have multiple
instances of the same player in it.

This will not fix bugged players who have joined multiple parties.
This commit is contained in:
TfT_02 2013-04-13 00:41:27 +02:00
parent faecb9a439
commit 682c2631f0
6 changed files with 57 additions and 31 deletions

View File

@ -14,6 +14,7 @@ Version 1.4.06-dev
+ Added new API method to McMMOPlayerLevelUpEvent to set levels gained
+ Added new permission node for /ptp; mcmmo.commands.ptp.send (enabled by default)
+ Added configurable cooldown and warmup times when using /ptp
= Fixed bug where players were able to join the same party multiple times
= Fixed displaying partial names when trying to use /ptp
= Fixed wolves from Call of the Wild only having 8 health
= Fixed bug where /party chat was not working

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.api;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.player.UserManager;
@ -127,7 +129,26 @@ public final class PartyAPI {
* @param player The player to check
* @return all the players in the player's party
*/
@Deprecated
public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
List<OfflinePlayer> members = new ArrayList<OfflinePlayer>();
for (String memberName : PartyManager.getAllMembers(player)) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
members.add(member);
}
return members;
}
/**
* Get a list of all player names in this player's party.
* </br>
* This function is designed for API usage.
*
* @param player The player to check
* @return all the player names in the player's party
*/
public static List<String> getMembers(Player player) {
return PartyManager.getAllMembers(player);
}

View File

@ -7,6 +7,7 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -41,8 +42,8 @@ public class PartyInfoCommand implements CommandExecutor {
private String createMembersList() {
StringBuilder memberList = new StringBuilder();
for (OfflinePlayer member : playerParty.getMembers()) {
String memberName = member.getName();
for (String memberName : playerParty.getMembers()) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
memberList.append(ChatColor.GOLD);

View File

@ -6,10 +6,11 @@ import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
public class Party {
private List<OfflinePlayer> members = new ArrayList<OfflinePlayer>();
private List<String> members = new ArrayList<String>();
private String leader;
private String name;
private String password;
@ -23,14 +24,15 @@ public class Party {
private boolean shareHerbalismDrops = true;
private boolean shareWoodcuttingDrops = true;
public List<OfflinePlayer> getMembers() {
public List<String> getMembers() {
return members;
}
public List<Player> getOnlineMembers() {
List<Player> onlineMembers = new ArrayList<Player>();
for (OfflinePlayer member : members) {
for (String memberName : members) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
if (member.isOnline()) {
onlineMembers.add(member.getPlayer());
}

View File

@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@ -15,7 +14,6 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.runnables.party.PartyLoaderTask;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.UserManager;
@ -99,7 +97,7 @@ public final class PartyManager {
* @param player The player to check
* @return all the players in the player's party
*/
public static List<OfflinePlayer> getAllMembers(Player player) {
public static List<String> getAllMembers(Player player) {
Party party = UserManager.getPlayer(player).getParty();
if (party == null) {
@ -165,8 +163,8 @@ public final class PartyManager {
*/
public static Party getPlayerParty(String playerName) {
for (Party party : parties) {
for (OfflinePlayer member : party.getMembers()) {
if (member.getName().equalsIgnoreCase(playerName)) {
for (String memberName : party.getMembers()) {
if (memberName.equalsIgnoreCase(playerName)) {
return party;
}
}
@ -191,9 +189,11 @@ public final class PartyManager {
* @param party The party
*/
public static void removeFromParty(OfflinePlayer player, Party party) {
List<OfflinePlayer> members = party.getMembers();
List<String> members = party.getMembers();
members.remove(player);
while (members.remove(player.getName())) {
// Remove all the duplicates as well
}
if (members.isEmpty()) {
parties.remove(party);
@ -201,7 +201,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().equalsIgnoreCase(player.getName())) {
String newLeader = members.get(0).getName();
String newLeader = members.get(0);
party.setLeader(newLeader);
}
@ -222,10 +222,10 @@ public final class PartyManager {
* @param party The party to remove
*/
public static void disbandParty(Party party) {
List<OfflinePlayer> members = party.getMembers();
List<String> members = party.getMembers();
for (OfflinePlayer member : members) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(member.getName());
for (String memberName : members) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName);
if (mcMMOPlayer != null) {
mcMMOPlayer.removeParty();
@ -361,7 +361,10 @@ public final class PartyManager {
informPartyMembersJoin(player, party);
mcMMOPlayer.setParty(party);
party.getMembers().add(player);
if (!party.getMembers().contains(player.getName())) {
party.getMembers().add(player.getName());
}
}
/**
@ -439,14 +442,6 @@ public final class PartyManager {
* Load party file.
*/
public static void loadParties() {
try {
mcMMO.p.getServer().getOfflinePlayer("nossr50"); // TODO: Find a less-hacky way to manage reloading.
}
catch (IndexOutOfBoundsException ex){
new PartyLoaderTask().runTaskLater(mcMMO.p, 0);
return;
}
File file = new File(partiesFilePath);
if (!file.exists()) {
@ -473,11 +468,12 @@ public final class PartyManager {
party.setItemShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ItemShareMode")));
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
List<OfflinePlayer> members = party.getMembers();
Server server = mcMMO.p.getServer();
List<String> members = party.getMembers();
for (String memberName : memberNames) {
members.add(server.getOfflinePlayer(memberName));
if (!members.contains(memberName)) {
members.add(memberName);
}
}
parties.add(party);
@ -507,8 +503,10 @@ public final class PartyManager {
List<String> memberNames = new ArrayList<String>();
for (OfflinePlayer member : party.getMembers()) {
memberNames.add(member.getName());
for (String member : party.getMembers()) {
if (!memberNames.contains(member)) {
memberNames.add(member);
}
}
partiesFile.set(partyName + ".Members", memberNames);

View File

@ -7,6 +7,7 @@ import java.util.Map.Entry;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.party.PartyManager;
@ -26,7 +27,9 @@ public class PartyAutoKickTask extends BukkitRunnable {
for (Iterator<Party> partyIterator = PartyManager.getParties().iterator(); partyIterator.hasNext();) {
Party party = partyIterator.next();
for (OfflinePlayer member : party.getMembers()) {
for (String memberName : party.getMembers()) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
if (currentTime - member.getLastPlayed() > kickTime) {
toRemove.put(member, party);
}