mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 22:56:45 +01:00
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:
parent
faecb9a439
commit
682c2631f0
@ -14,6 +14,7 @@ Version 1.4.06-dev
|
|||||||
+ Added new API method to McMMOPlayerLevelUpEvent to set levels gained
|
+ Added new API method to McMMOPlayerLevelUpEvent to set levels gained
|
||||||
+ Added new permission node for /ptp; mcmmo.commands.ptp.send (enabled by default)
|
+ Added new permission node for /ptp; mcmmo.commands.ptp.send (enabled by default)
|
||||||
+ Added configurable cooldown and warmup times when using /ptp
|
+ 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 displaying partial names when trying to use /ptp
|
||||||
= Fixed wolves from Call of the Wild only having 8 health
|
= Fixed wolves from Call of the Wild only having 8 health
|
||||||
= Fixed bug where /party chat was not working
|
= Fixed bug where /party chat was not working
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.gmail.nossr50.api;
|
package com.gmail.nossr50.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
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;
|
||||||
@ -127,7 +129,26 @@ public final class PartyAPI {
|
|||||||
* @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
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
|
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);
|
return PartyManager.getAllMembers(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ 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.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
@ -41,8 +42,8 @@ public class PartyInfoCommand implements CommandExecutor {
|
|||||||
private String createMembersList() {
|
private String createMembersList() {
|
||||||
StringBuilder memberList = new StringBuilder();
|
StringBuilder memberList = new StringBuilder();
|
||||||
|
|
||||||
for (OfflinePlayer member : playerParty.getMembers()) {
|
for (String memberName : playerParty.getMembers()) {
|
||||||
String memberName = member.getName();
|
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
||||||
|
|
||||||
if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
|
if (playerParty.getLeader().equalsIgnoreCase(memberName)) {
|
||||||
memberList.append(ChatColor.GOLD);
|
memberList.append(ChatColor.GOLD);
|
||||||
|
@ -6,10 +6,11 @@ import java.util.List;
|
|||||||
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.party.ShareHandler;
|
import com.gmail.nossr50.party.ShareHandler;
|
||||||
|
|
||||||
public class Party {
|
public class Party {
|
||||||
private List<OfflinePlayer> members = new ArrayList<OfflinePlayer>();
|
private List<String> members = new ArrayList<String>();
|
||||||
private String leader;
|
private String leader;
|
||||||
private String name;
|
private String name;
|
||||||
private String password;
|
private String password;
|
||||||
@ -23,14 +24,15 @@ public class Party {
|
|||||||
private boolean shareHerbalismDrops = true;
|
private boolean shareHerbalismDrops = true;
|
||||||
private boolean shareWoodcuttingDrops = true;
|
private boolean shareWoodcuttingDrops = true;
|
||||||
|
|
||||||
public List<OfflinePlayer> getMembers() {
|
public List<String> getMembers() {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Player> getOnlineMembers() {
|
public List<Player> getOnlineMembers() {
|
||||||
List<Player> onlineMembers = new ArrayList<Player>();
|
List<Player> onlineMembers = new ArrayList<Player>();
|
||||||
|
|
||||||
for (OfflinePlayer member : members) {
|
for (String memberName : members) {
|
||||||
|
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberName);
|
||||||
if (member.isOnline()) {
|
if (member.isOnline()) {
|
||||||
onlineMembers.add(member.getPlayer());
|
onlineMembers.add(member.getPlayer());
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
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;
|
||||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.runnables.party.PartyLoaderTask;
|
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ 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 List<OfflinePlayer> getAllMembers(Player player) {
|
public static List<String> getAllMembers(Player player) {
|
||||||
Party party = UserManager.getPlayer(player).getParty();
|
Party party = UserManager.getPlayer(player).getParty();
|
||||||
|
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
@ -165,8 +163,8 @@ public final class PartyManager {
|
|||||||
*/
|
*/
|
||||||
public static Party getPlayerParty(String playerName) {
|
public static Party getPlayerParty(String playerName) {
|
||||||
for (Party party : parties) {
|
for (Party party : parties) {
|
||||||
for (OfflinePlayer member : party.getMembers()) {
|
for (String memberName : party.getMembers()) {
|
||||||
if (member.getName().equalsIgnoreCase(playerName)) {
|
if (memberName.equalsIgnoreCase(playerName)) {
|
||||||
return party;
|
return party;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,9 +189,11 @@ 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) {
|
||||||
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()) {
|
if (members.isEmpty()) {
|
||||||
parties.remove(party);
|
parties.remove(party);
|
||||||
@ -201,7 +201,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().equalsIgnoreCase(player.getName())) {
|
if (party.getLeader().equalsIgnoreCase(player.getName())) {
|
||||||
String newLeader = members.get(0).getName();
|
String newLeader = members.get(0);
|
||||||
party.setLeader(newLeader);
|
party.setLeader(newLeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,10 +222,10 @@ public final class PartyManager {
|
|||||||
* @param party The party to remove
|
* @param party The party to remove
|
||||||
*/
|
*/
|
||||||
public static void disbandParty(Party party) {
|
public static void disbandParty(Party party) {
|
||||||
List<OfflinePlayer> members = party.getMembers();
|
List<String> members = party.getMembers();
|
||||||
|
|
||||||
for (OfflinePlayer member : members) {
|
for (String memberName : members) {
|
||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(member.getName());
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(memberName);
|
||||||
|
|
||||||
if (mcMMOPlayer != null) {
|
if (mcMMOPlayer != null) {
|
||||||
mcMMOPlayer.removeParty();
|
mcMMOPlayer.removeParty();
|
||||||
@ -361,7 +361,10 @@ public final class PartyManager {
|
|||||||
|
|
||||||
informPartyMembersJoin(player, party);
|
informPartyMembersJoin(player, party);
|
||||||
mcMMOPlayer.setParty(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.
|
* Load party file.
|
||||||
*/
|
*/
|
||||||
public static void loadParties() {
|
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);
|
File file = new File(partiesFilePath);
|
||||||
|
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@ -473,11 +468,12 @@ public final class PartyManager {
|
|||||||
party.setItemShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ItemShareMode")));
|
party.setItemShareMode(ShareHandler.ShareMode.getFromString(partiesFile.getString(partyName + ".ItemShareMode")));
|
||||||
|
|
||||||
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
|
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
|
||||||
List<OfflinePlayer> members = party.getMembers();
|
List<String> members = party.getMembers();
|
||||||
Server server = mcMMO.p.getServer();
|
|
||||||
|
|
||||||
for (String memberName : memberNames) {
|
for (String memberName : memberNames) {
|
||||||
members.add(server.getOfflinePlayer(memberName));
|
if (!members.contains(memberName)) {
|
||||||
|
members.add(memberName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parties.add(party);
|
parties.add(party);
|
||||||
@ -507,8 +503,10 @@ public final class PartyManager {
|
|||||||
|
|
||||||
List<String> memberNames = new ArrayList<String>();
|
List<String> memberNames = new ArrayList<String>();
|
||||||
|
|
||||||
for (OfflinePlayer member : party.getMembers()) {
|
for (String member : party.getMembers()) {
|
||||||
memberNames.add(member.getName());
|
if (!memberNames.contains(member)) {
|
||||||
|
memberNames.add(member);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
partiesFile.set(partyName + ".Members", memberNames);
|
partiesFile.set(partyName + ".Members", memberNames);
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Map.Entry;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.datatypes.party.Party;
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
import com.gmail.nossr50.party.PartyManager;
|
import com.gmail.nossr50.party.PartyManager;
|
||||||
@ -26,7 +27,9 @@ public class PartyAutoKickTask extends BukkitRunnable {
|
|||||||
for (Iterator<Party> partyIterator = PartyManager.getParties().iterator(); partyIterator.hasNext();) {
|
for (Iterator<Party> partyIterator = PartyManager.getParties().iterator(); partyIterator.hasNext();) {
|
||||||
Party party = partyIterator.next();
|
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) {
|
if (currentTime - member.getLastPlayed() > kickTime) {
|
||||||
toRemove.put(member, party);
|
toRemove.put(member, party);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user