2012-06-08 23:48:41 +02:00
|
|
|
package com.gmail.nossr50.party;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2013-04-13 18:43:22 +02:00
|
|
|
import java.util.LinkedHashSet;
|
2012-06-08 23:48:41 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2013-02-09 14:34:53 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
2012-06-08 23:48:41 +02:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-02-08 04:01:14 +01:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent.EventReason;
|
2012-06-08 23:48:41 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-30 15:17:50 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public final class PartyManager {
|
2013-04-23 15:10:03 +02:00
|
|
|
private static String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
|
2012-06-08 23:48:41 +02:00
|
|
|
private static List<Party> parties = new ArrayList<Party>();
|
2013-04-23 15:32:28 +02:00
|
|
|
private static File partyFile = new File(partiesFilePath);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-01-27 01:32:41 +01:00
|
|
|
private PartyManager() {}
|
|
|
|
|
2013-03-12 21:25:42 +01:00
|
|
|
public static boolean checkPartyExistence(Player player, Party party, String partyName) {
|
|
|
|
if (party == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", partyName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-09 06:57:00 +01:00
|
|
|
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, Player player, Party oldParty, String newPartyName) {
|
2013-02-08 05:59:02 +01:00
|
|
|
if (mcMMOPlayer.inParty()) {
|
2013-02-09 06:57:00 +01:00
|
|
|
if (!handlePartyChangeEvent(player, oldParty.getName(), newPartyName, EventReason.CHANGED_PARTIES)) {
|
2013-02-08 05:59:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-09 14:34:53 +01:00
|
|
|
removeFromParty(player, oldParty);
|
2013-02-08 05:59:02 +01:00
|
|
|
}
|
2013-02-09 06:57:00 +01:00
|
|
|
else if (!handlePartyChangeEvent(player, null, newPartyName, EventReason.JOINED_PARTY)) {
|
2013-02-08 05:59:02 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
/**
|
2013-02-11 14:14:43 +01:00
|
|
|
* Check if two online players are in the same party.
|
2012-06-08 23:48:41 +02:00
|
|
|
*
|
|
|
|
* @param firstPlayer The first player
|
|
|
|
* @param secondPlayer The second player
|
|
|
|
* @return true if they are in the same party, false otherwise
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static boolean inSameParty(Player firstPlayer, Player secondPlayer) {
|
2013-03-01 06:52:01 +01:00
|
|
|
McMMOPlayer firstMcMMOPlayer = UserManager.getPlayer(firstPlayer);
|
|
|
|
McMMOPlayer secondMcMMOPlayer = UserManager.getPlayer(secondPlayer);
|
2012-07-10 20:02:48 +02:00
|
|
|
|
2013-02-03 16:27:59 +01:00
|
|
|
if (firstMcMMOPlayer == null || secondMcMMOPlayer == null) {
|
2012-07-10 20:02:48 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
return firstMcMMOPlayer.getParty().equals(secondMcMMOPlayer.getParty());
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
/**
|
|
|
|
* Get the near party members.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @param range The distance
|
|
|
|
* @return the near party members
|
|
|
|
*/
|
|
|
|
public static List<Player> getNearMembers(Player player, Party party, double range) {
|
|
|
|
List<Player> nearMembers = new ArrayList<Player>();
|
2013-05-22 19:02:26 +02:00
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
if (party != null) {
|
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2013-05-22 19:02:26 +02:00
|
|
|
if (!player.equals(member) && member.isValid() && Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
2013-01-30 15:17:50 +01:00
|
|
|
nearMembers.add(member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-22 19:02:26 +02:00
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
return nearMembers;
|
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* Get a list of all players in this player's party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all the players in the player's party
|
|
|
|
*/
|
2013-04-13 18:43:22 +02:00
|
|
|
public static LinkedHashSet<String> getAllMembers(Player player) {
|
2013-05-22 19:02:26 +02:00
|
|
|
Party party = getPlayerParty(player.getName());
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
return party == null ? null : party.getMembers();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this party.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return all online players in this party
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static List<Player> getOnlineMembers(String partyName) {
|
2013-05-22 19:02:26 +02:00
|
|
|
return getOnlineMembers(getParty(partyName));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this party.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all online players in this party
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static List<Player> getOnlineMembers(Player player) {
|
2013-05-22 19:02:26 +02:00
|
|
|
return getOnlineMembers(getPlayerParty(player.getName()));
|
|
|
|
}
|
2013-03-17 15:46:29 +01:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
private static List<Player> getOnlineMembers(Party party) {
|
|
|
|
return party == null ? null : party.getOnlineMembers();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a party by its name
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2012-06-08 23:48:41 +02:00
|
|
|
* @param partyName The party name
|
|
|
|
* @return the existing party, null otherwise
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static Party getParty(String partyName) {
|
2012-06-08 23:48:41 +02:00
|
|
|
for (Party party : parties) {
|
|
|
|
if (party.getName().equals(partyName)) {
|
|
|
|
return party;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-06-09 19:48:18 +02:00
|
|
|
/**
|
|
|
|
* Retrieve a party by a member name
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2012-06-09 19:48:18 +02:00
|
|
|
* @param playerName The member name
|
|
|
|
* @return the existing party, null otherwise
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static Party getPlayerParty(String playerName) {
|
2012-06-09 19:48:18 +02:00
|
|
|
for (Party party : parties) {
|
2013-04-13 00:41:27 +02:00
|
|
|
for (String memberName : party.getMembers()) {
|
|
|
|
if (memberName.equalsIgnoreCase(playerName)) {
|
2013-02-09 15:52:09 +01:00
|
|
|
return party;
|
|
|
|
}
|
2012-06-09 19:48:18 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-09 15:52:09 +01:00
|
|
|
|
2012-06-09 19:48:18 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
/**
|
2012-06-11 08:20:39 +02:00
|
|
|
* Get a list of all current parties.
|
2012-06-08 23:48:41 +02:00
|
|
|
*
|
|
|
|
* @return the list of parties.
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static List<Party> getParties() {
|
2012-06-08 23:48:41 +02:00
|
|
|
return parties;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a player from a party.
|
|
|
|
*
|
2013-02-09 14:34:53 +01:00
|
|
|
* @param player The player to remove
|
2012-06-11 07:45:14 +02:00
|
|
|
* @param party The party
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-02-09 14:34:53 +01:00
|
|
|
public static void removeFromParty(OfflinePlayer player, Party party) {
|
2013-04-13 18:43:22 +02:00
|
|
|
LinkedHashSet<String> members = party.getMembers();
|
2013-05-22 19:02:26 +02:00
|
|
|
String playerName = player.getName();
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
members.remove(playerName);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
if (members.isEmpty()) {
|
|
|
|
parties.remove(party);
|
|
|
|
}
|
|
|
|
else {
|
2013-03-01 06:52:01 +01:00
|
|
|
// If the leaving player was the party leader, appoint a new leader from the party members
|
2013-05-22 19:02:26 +02:00
|
|
|
if (party.getLeader().equalsIgnoreCase(playerName)) {
|
2013-04-13 18:43:22 +02:00
|
|
|
String newLeader = members.iterator().next();
|
2013-02-09 14:34:53 +01:00
|
|
|
party.setLeader(newLeader);
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
informPartyMembersQuit(party, playerName);
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
processPartyLeaving(UserManager.getPlayer(player));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:40:23 +01:00
|
|
|
/**
|
|
|
|
* Disband a party. Kicks out all members and removes the party.
|
|
|
|
*
|
|
|
|
* @param party The party to remove
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static void disbandParty(Party party) {
|
2013-05-22 19:02:26 +02:00
|
|
|
for (String memberName : party.getMembers()) {
|
|
|
|
processPartyLeaving(UserManager.getPlayer(memberName));
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2013-02-09 14:34:53 +01:00
|
|
|
parties.remove(party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new party
|
|
|
|
*
|
|
|
|
* @param player The player to add to the party
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param mcMMOPlayer The player to add to the party
|
2013-01-26 00:40:23 +01:00
|
|
|
* @param partyName The party to add the player to
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param password The password for this party, null if there was no password
|
2013-01-26 00:40:23 +01:00
|
|
|
*/
|
2013-02-03 16:27:59 +01:00
|
|
|
public static void createParty(Player player, McMMOPlayer mcMMOPlayer, String partyName, String password) {
|
2013-01-26 00:40:23 +01:00
|
|
|
partyName = partyName.replace(".", "");
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
Party party = getParty(partyName);
|
|
|
|
String playerName = player.getName();
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
if (party != null) {
|
2013-01-26 00:40:23 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
party = new Party(playerName, partyName, password);
|
|
|
|
|
|
|
|
if (password != null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.Set", password));
|
|
|
|
}
|
|
|
|
|
|
|
|
parties.add(party);
|
|
|
|
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Create", party.getName()));
|
2013-05-22 19:02:26 +02:00
|
|
|
addToParty(playerName, mcMMOPlayer, party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* Add a player to a party.
|
|
|
|
*
|
|
|
|
* @param player The player to add to the party
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param mcMMOPlayer The player to add to the party
|
2013-02-09 16:21:13 +01:00
|
|
|
* @param party The party to add the player to
|
2012-06-08 23:48:41 +02:00
|
|
|
* @param password the password for this party, null if there was no password
|
|
|
|
*/
|
2013-02-09 16:21:13 +01:00
|
|
|
public static void joinParty(Player player, McMMOPlayer mcMMOPlayer, Party party, String password) {
|
2013-05-22 19:02:26 +02:00
|
|
|
if (!checkPartyPassword(player, party, password) || mcMMOPlayer.getParty() == party) {
|
2013-02-25 13:23:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", party.getName()));
|
2013-05-22 19:02:26 +02:00
|
|
|
addToParty(player.getName(), mcMMOPlayer, party);
|
2012-06-11 07:45:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a player can join a party
|
|
|
|
*
|
|
|
|
* @param player The player trying to join a party
|
|
|
|
* @param party The party
|
|
|
|
* @param password The password provided by the player
|
|
|
|
* @return true if the player can join the party
|
|
|
|
*/
|
2013-02-08 03:46:12 +01:00
|
|
|
public static boolean checkPartyPassword(Player player, Party party, String password) {
|
2013-05-22 19:02:26 +02:00
|
|
|
if (!party.isLocked()) {
|
|
|
|
return true;
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
String partyPassword = party.getPassword();
|
|
|
|
|
|
|
|
if (partyPassword == null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password == null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.None"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (!password.equals(partyPassword)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.Incorrect"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accept a party invitation
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param Player The plaer to add to the party
|
|
|
|
* @param mcMMOPlayer The player to add to the party
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-02-03 16:27:59 +01:00
|
|
|
public static void joinInvitedParty(Player player, McMMOPlayer mcMMOPlayer) {
|
2013-02-08 04:05:08 +01:00
|
|
|
Party invite = mcMMOPlayer.getPartyInvite();
|
2012-06-11 07:45:14 +02:00
|
|
|
|
2013-02-25 13:23:18 +01:00
|
|
|
if (mcMMOPlayer.getParty() == invite) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
if (!parties.contains(invite)) {
|
|
|
|
parties.add(invite);
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Invite.Accepted", invite.getName()));
|
2013-02-08 04:05:08 +01:00
|
|
|
mcMMOPlayer.removePartyInvite();
|
2013-05-22 19:02:26 +02:00
|
|
|
addToParty(player.getName(), mcMMOPlayer, invite);
|
2012-06-11 07:45:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a player to a party
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2013-02-09 14:34:53 +01:00
|
|
|
* @param player The player to add to a party
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param mcMMOPlayer The player to add to the party
|
2012-06-11 07:45:14 +02:00
|
|
|
* @param party The party
|
|
|
|
*/
|
2013-05-22 19:02:26 +02:00
|
|
|
public static void addToParty(String playerName, McMMOPlayer mcMMOPlayer, Party party) {
|
2013-02-25 13:23:18 +01:00
|
|
|
if (mcMMOPlayer.getParty() == party) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
informPartyMembersJoin(party, playerName);
|
2013-02-03 16:27:59 +01:00
|
|
|
mcMMOPlayer.setParty(party);
|
2013-04-13 00:41:27 +02:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
party.getMembers().add(playerName);
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the leader of a party.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @return the leader of the party
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static String getPartyLeader(String partyName) {
|
2012-06-08 23:48:41 +02:00
|
|
|
Party party = getParty(partyName);
|
|
|
|
|
|
|
|
if (party == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return party.getLeader();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the leader of a party.
|
|
|
|
*
|
|
|
|
* @param playerName The name of the player to set as leader
|
2012-06-11 07:45:14 +02:00
|
|
|
* @param party The party
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static void setPartyLeader(String playerName, Party party) {
|
2012-06-08 23:48:41 +02:00
|
|
|
String leaderName = party.getLeader();
|
|
|
|
|
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2013-03-10 22:07:07 +01:00
|
|
|
if (member.getName().equalsIgnoreCase(playerName)) {
|
2013-01-17 17:02:55 +01:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.Player"));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
2013-03-10 22:07:07 +01:00
|
|
|
else if (member.getName().equalsIgnoreCase(leaderName)) {
|
2013-01-17 17:02:55 +01:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader"));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-02-02 08:55:49 +01:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.New", playerName));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
party.setLeader(playerName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-03 16:27:59 +01:00
|
|
|
* Check if a player can invite others to his party.
|
2012-06-08 23:48:41 +02:00
|
|
|
*
|
|
|
|
* @param player The player to check
|
2013-02-03 16:27:59 +01:00
|
|
|
* @param mcMMOPlayer The player to check
|
2012-06-11 07:45:14 +02:00
|
|
|
* @return true if the player can invite
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-02-08 22:56:54 +01:00
|
|
|
public static boolean canInvite(Player player, Party party) {
|
2013-03-10 22:07:07 +01:00
|
|
|
if (party.isLocked() && !party.getLeader().equalsIgnoreCase(player.getName())) {
|
2012-06-08 23:48:41 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a string is a valid party name.
|
|
|
|
*
|
|
|
|
* @param partyName The party name to check
|
|
|
|
* @return true if this is a valid party, false otherwise
|
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static boolean isParty(String partyName) {
|
2013-05-22 19:02:26 +02:00
|
|
|
return getParty(partyName) != null;
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-09 20:11:11 +02:00
|
|
|
* Load party file.
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-01-27 01:32:41 +01:00
|
|
|
public static void loadParties() {
|
2013-04-23 15:32:28 +02:00
|
|
|
if (!partyFile.exists()) {
|
2012-06-08 23:48:41 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-23 15:32:28 +02:00
|
|
|
YamlConfiguration partiesFile = YamlConfiguration.loadConfiguration(partyFile);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
|
|
|
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
|
2013-05-22 19:02:26 +02:00
|
|
|
Party party = new Party(partyName);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
|
|
|
party.setLeader(partiesFile.getString(partyName + ".Leader"));
|
|
|
|
party.setPassword(partiesFile.getString(partyName + ".Password"));
|
|
|
|
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
|
2013-04-18 15:09:12 +02:00
|
|
|
party.setXpShareMode(ShareHandler.ShareMode.getShareMode(partiesFile.getString(partyName + ".ExpShareMode", "NONE")));
|
|
|
|
party.setItemShareMode(ShareHandler.ShareMode.getShareMode(partiesFile.getString(partyName + ".ItemShareMode", "NONE")));
|
2013-02-09 14:34:53 +01:00
|
|
|
|
|
|
|
List<String> memberNames = partiesFile.getStringList(partyName + ".Members");
|
2013-04-13 18:43:22 +02:00
|
|
|
LinkedHashSet<String> members = party.getMembers();
|
2013-02-09 14:34:53 +01:00
|
|
|
|
|
|
|
for (String memberName : memberNames) {
|
2013-04-13 18:43:22 +02:00
|
|
|
members.add(memberName);
|
2013-02-09 14:34:53 +01:00
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
|
|
|
|
parties.add(party);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-09 20:11:11 +02:00
|
|
|
* Save party file.
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-01-26 23:01:55 +01:00
|
|
|
public static void saveParties() {
|
2013-04-23 15:32:28 +02:00
|
|
|
if (partyFile.exists()) {
|
|
|
|
partyFile.delete();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
YamlConfiguration partiesFile = new YamlConfiguration();
|
|
|
|
|
|
|
|
for (Party party : parties) {
|
|
|
|
String partyName = party.getName();
|
|
|
|
|
|
|
|
partiesFile.set(partyName + ".Leader", party.getLeader());
|
|
|
|
partiesFile.set(partyName + ".Password", party.getPassword());
|
|
|
|
partiesFile.set(partyName + ".Locked", party.isLocked());
|
2013-02-01 06:38:25 +01:00
|
|
|
partiesFile.set(partyName + ".ExpShareMode", party.getXpShareMode().toString());
|
2013-02-09 12:24:02 +01:00
|
|
|
partiesFile.set(partyName + ".ItemShareMode", party.getItemShareMode().toString());
|
2013-02-09 15:26:41 +01:00
|
|
|
|
|
|
|
List<String> memberNames = new ArrayList<String>();
|
|
|
|
|
2013-04-13 00:41:27 +02:00
|
|
|
for (String member : party.getMembers()) {
|
|
|
|
if (!memberNames.contains(member)) {
|
|
|
|
memberNames.add(member);
|
|
|
|
}
|
2013-02-09 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
partiesFile.set(partyName + ".Members", memberNames);
|
2013-03-08 05:28:40 +01:00
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-03-08 05:28:40 +01:00
|
|
|
try {
|
2013-04-23 15:32:28 +02:00
|
|
|
partiesFile.save(partyFile);
|
2013-03-08 05:28:40 +01:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-08 04:01:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle party change event.
|
|
|
|
*
|
|
|
|
* @param player The player changing parties
|
|
|
|
* @param oldPartyName The name of the old party
|
|
|
|
* @param newPartyName The name of the new party
|
|
|
|
* @param reason The reason for changing parties
|
|
|
|
* @return true if the change event was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean handlePartyChangeEvent(Player player, String oldPartyName, String newPartyName, EventReason reason) {
|
|
|
|
McMMOPartyChangeEvent event = new McMMOPartyChangeEvent(player, oldPartyName, newPartyName, reason);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return !event.isCancelled();
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
/**
|
2013-05-22 19:02:26 +02:00
|
|
|
* Notify party members when a player joins.
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
|
|
|
* @param party The concerned party
|
2013-05-22 19:02:26 +02:00
|
|
|
* @param playerName The name of the player that joined
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-05-22 19:02:26 +02:00
|
|
|
private static void informPartyMembersJoin(Party party, String playerName) {
|
2013-03-01 06:52:01 +01:00
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2013-05-22 19:02:26 +02:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.InformedOnJoin", playerName));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify party members when a party member quits.
|
|
|
|
*
|
|
|
|
* @param party The concerned party
|
2013-05-22 19:02:26 +02:00
|
|
|
* @param playerName The name of the player that left
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-05-22 19:02:26 +02:00
|
|
|
private static void informPartyMembersQuit(Party party, String playerName) {
|
2013-03-01 06:52:01 +01:00
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2013-05-22 19:02:26 +02:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.InformedOnQuit", playerName));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-22 19:02:26 +02:00
|
|
|
|
|
|
|
private static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
|
|
|
if (mcMMOPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcMMOPlayer.removeParty();
|
|
|
|
mcMMOPlayer.setPartyChat(false);
|
|
|
|
mcMMOPlayer.setItemShareModifier(10);
|
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|