2012-06-08 23:48:41 +02:00
|
|
|
package com.gmail.nossr50.party;
|
|
|
|
|
2013-08-26 22:08:45 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2020-10-27 00:31:02 +01:00
|
|
|
import com.gmail.nossr50.datatypes.chat.ChatChannel;
|
2019-01-13 09:45:17 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2013-08-26 22:08:45 +02:00
|
|
|
import com.gmail.nossr50.datatypes.party.ItemShareType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.party.Party;
|
2014-07-12 19:44:47 +02:00
|
|
|
import com.gmail.nossr50.datatypes.party.PartyLeader;
|
2013-07-15 15:56:45 +02:00
|
|
|
import com.gmail.nossr50.datatypes.party.ShareMode;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-10-28 14:01:44 +01:00
|
|
|
import com.gmail.nossr50.events.party.McMMOPartyAllianceChangeEvent;
|
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;
|
2018-07-26 02:29:40 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-01-30 15:17:50 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2019-01-11 15:17:07 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2019-01-13 09:45:17 +01:00
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2019-01-13 04:08:54 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
2018-07-26 02:29:40 +02:00
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.UUID;
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public final class PartyManager {
|
2020-07-13 20:39:03 +02:00
|
|
|
private static final String partiesFilePath = mcMMO.getFlatFileDirectory() + "parties.yml";
|
2020-07-13 21:31:30 +02:00
|
|
|
private static final List<Party> parties = new ArrayList<>();
|
2020-07-13 20:39:03 +02:00
|
|
|
private static final File partyFile = new File(partiesFilePath);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-01-27 01:32:41 +01:00
|
|
|
private PartyManager() {}
|
|
|
|
|
2013-08-26 14:39:16 +02:00
|
|
|
/**
|
|
|
|
* Check if a party with a given name already exists.
|
|
|
|
*
|
|
|
|
* @param player The player to notify
|
|
|
|
* @param partyName The name of the party to check
|
|
|
|
* @return true if a party with that name exists, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean checkPartyExistence(Player player, String partyName) {
|
|
|
|
if (getParty(partyName) == null) {
|
2013-03-12 21:25:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.AlreadyExists", partyName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-11 15:17:07 +01:00
|
|
|
/**
|
|
|
|
* Checks if the player can join a party, parties can have a size limit, although there is a permission to bypass this
|
|
|
|
* @param player player who is attempting to join the party
|
|
|
|
* @param targetParty the target party
|
|
|
|
* @return true if party is full and cannot be joined
|
|
|
|
*/
|
|
|
|
public static boolean isPartyFull(Player player, Party targetParty)
|
|
|
|
{
|
|
|
|
return !Permissions.partySizeBypass(player) && Config.getInstance().getPartyMaxSize() >= 1 && targetParty.getOnlineMembers().size() >= Config.getInstance().getPartyMaxSize();
|
|
|
|
}
|
|
|
|
|
2013-08-26 14:39:16 +02:00
|
|
|
/**
|
|
|
|
* Attempt to change parties or join a new party.
|
|
|
|
*
|
|
|
|
* @param mcMMOPlayer The player changing or joining parties
|
|
|
|
* @param newPartyName The name of the party being joined
|
|
|
|
* @return true if the party was joined successfully, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean changeOrJoinParty(McMMOPlayer mcMMOPlayer, String newPartyName) {
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
|
2013-02-08 05:59:02 +01:00
|
|
|
if (mcMMOPlayer.inParty()) {
|
2013-08-26 14:39:16 +02:00
|
|
|
Party oldParty = mcMMOPlayer.getParty();
|
|
|
|
|
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-08-26 17:55:35 +02:00
|
|
|
removeFromParty(mcMMOPlayer);
|
2013-02-08 05:59:02 +01:00
|
|
|
}
|
2018-07-26 02:29:40 +02:00
|
|
|
else return handlePartyChangeEvent(player, null, newPartyName, EventReason.JOINED_PARTY);
|
2013-02-08 05:59:02 +01:00
|
|
|
|
|
|
|
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) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(firstPlayer) == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(secondPlayer) == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-26 14:39:16 +02:00
|
|
|
Party firstParty = UserManager.getPlayer(firstPlayer).getParty();
|
|
|
|
Party secondParty = UserManager.getPlayer(secondPlayer).getParty();
|
2012-07-10 20:02:48 +02:00
|
|
|
|
2013-08-26 14:39:16 +02:00
|
|
|
if (firstParty == null || secondParty == null) {
|
2013-05-23 03:20:35 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-26 14:39:16 +02:00
|
|
|
return firstParty.equals(secondParty);
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2013-10-28 14:01:44 +01:00
|
|
|
public static boolean areAllies(Player firstPlayer, Player secondPlayer) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(firstPlayer) == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(secondPlayer) == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-28 14:01:44 +01:00
|
|
|
Party firstParty = UserManager.getPlayer(firstPlayer).getParty();
|
|
|
|
Party secondParty = UserManager.getPlayer(secondPlayer).getParty();
|
|
|
|
|
|
|
|
if (firstParty == null || secondParty == null || firstParty.getAlly() == null || secondParty.getAlly() == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return firstParty.equals(secondParty.getAlly()) && secondParty.equals(firstParty.getAlly());
|
|
|
|
}
|
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
/**
|
|
|
|
* Get the near party members.
|
|
|
|
*
|
2013-08-26 14:39:16 +02:00
|
|
|
* @param mcMMOPlayer The player to check
|
2013-01-30 15:17:50 +01:00
|
|
|
* @return the near party members
|
|
|
|
*/
|
2013-08-26 14:39:16 +02:00
|
|
|
public static List<Player> getNearMembers(McMMOPlayer mcMMOPlayer) {
|
2020-07-13 21:31:30 +02:00
|
|
|
List<Player> nearMembers = new ArrayList<>();
|
2013-08-26 14:39:16 +02:00
|
|
|
Party party = mcMMOPlayer.getParty();
|
2013-05-22 19:02:26 +02:00
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
if (party != null) {
|
2013-08-26 14:39:16 +02:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
double range = Config.getInstance().getPartyShareRange();
|
|
|
|
|
2013-01-30 15:17:50 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-11 06:06:51 +01:00
|
|
|
public static List<Player> getNearVisibleMembers(McMMOPlayer mcMMOPlayer) {
|
2020-07-13 21:31:30 +02:00
|
|
|
List<Player> nearMembers = new ArrayList<>();
|
2019-01-11 06:06:51 +01:00
|
|
|
Party party = mcMMOPlayer.getParty();
|
|
|
|
|
|
|
|
if (party != null) {
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
double range = Config.getInstance().getPartyShareRange();
|
|
|
|
|
|
|
|
for (Player member : party.getVisibleMembers(player)) {
|
2019-02-04 02:44:10 +01:00
|
|
|
if (!player.equals(member)
|
|
|
|
&& member.isValid()
|
|
|
|
&& Misc.isNear(player.getLocation(), member.getLocation(), range)) {
|
2019-01-11 06:06:51 +01:00
|
|
|
nearMembers.add(member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
public static LinkedHashMap<UUID, String> getAllMembers(Player player) {
|
2013-08-26 17:55:35 +02:00
|
|
|
Party party = getParty(player);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2020-07-13 21:31:30 +02:00
|
|
|
return party == null ? new LinkedHashMap<>() : 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-08-26 17:55:35 +02:00
|
|
|
return getOnlineMembers(getParty(player));
|
2013-05-22 19:02:26 +02:00
|
|
|
}
|
2013-03-17 15:46:29 +01:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
private static List<Player> getOnlineMembers(Party party) {
|
2020-07-13 21:31:30 +02:00
|
|
|
return party == null ? new ArrayList<>() : 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) {
|
2014-02-10 17:14:34 +01:00
|
|
|
if (party.getName().equalsIgnoreCase(partyName)) {
|
2012-06-08 23:48:41 +02:00
|
|
|
return party;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-08-26 22:08:45 +02:00
|
|
|
/**
|
|
|
|
* Retrieve a party by a members name
|
|
|
|
*
|
|
|
|
* @param playerName The members name
|
|
|
|
* @return the existing party, null otherwise
|
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
@Deprecated
|
2013-08-26 22:08:45 +02:00
|
|
|
public static Party getPlayerParty(String playerName) {
|
|
|
|
for (Party party : parties) {
|
2020-07-13 21:31:30 +02:00
|
|
|
if (party.getMembers().containsKey(playerName)) {
|
2014-07-12 19:44:47 +02:00
|
|
|
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();
|
2020-07-13 21:31:30 +02:00
|
|
|
if (members.containsKey(uuid) || members.containsValue(playerName)) {
|
2014-07-12 19:44:47 +02:00
|
|
|
|
|
|
|
// Name changes
|
|
|
|
if (members.get(uuid) == null || !members.get(uuid).equals(playerName)) {
|
|
|
|
members.put(uuid, playerName);
|
|
|
|
}
|
|
|
|
|
2013-08-26 22:08:45 +02:00
|
|
|
return party;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-06-09 19:48:18 +02:00
|
|
|
/**
|
2013-08-26 17:55:35 +02:00
|
|
|
* Retrieve a party by member
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
2013-08-26 17:55:35 +02:00
|
|
|
* @param player The member
|
2012-06-09 19:48:18 +02:00
|
|
|
* @return the existing party, null otherwise
|
|
|
|
*/
|
2013-08-26 17:55:35 +02:00
|
|
|
public static Party getParty(Player player) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
|
|
|
|
2013-10-09 06:12:04 +02:00
|
|
|
return mcMMOPlayer.getParty();
|
2012-06-09 19:48:18 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2014-07-12 19:44:47 +02:00
|
|
|
LinkedHashMap<UUID, String> members = party.getMembers();
|
2013-05-22 19:02:26 +02:00
|
|
|
String playerName = player.getName();
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
members.remove(player.getUniqueId());
|
|
|
|
|
|
|
|
if (player.isOnline()) {
|
|
|
|
party.getOnlineMembers().remove(player.getPlayer());
|
|
|
|
}
|
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
|
2014-07-12 19:44:47 +02:00
|
|
|
if (party.getLeader().getUniqueId().equals(player.getUniqueId())) {
|
|
|
|
setPartyLeader(members.keySet().iterator().next(), party);
|
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-08-26 17:55:35 +02:00
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
/**
|
|
|
|
* Remove a player from a party.
|
|
|
|
*
|
|
|
|
* @param mcMMOPlayer The player to remove
|
|
|
|
*/
|
|
|
|
public static void removeFromParty(McMMOPlayer mcMMOPlayer) {
|
|
|
|
removeFromParty(mcMMOPlayer.getPlayer(), mcMMOPlayer.getParty());
|
|
|
|
processPartyLeaving(mcMMOPlayer);
|
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) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//TODO: Potential issues with unloaded profile?
|
2013-09-30 10:39:14 +02:00
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Profile not loaded
|
|
|
|
if(UserManager.getPlayer(member) == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-30 10:39:14 +02:00
|
|
|
processPartyLeaving(UserManager.getPlayer(member));
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 22:41:47 +01:00
|
|
|
// Disband the alliance between the disbanded party and it's ally
|
|
|
|
if (party.getAlly() != null) {
|
|
|
|
party.getAlly().setAlly(null);
|
|
|
|
}
|
|
|
|
|
2013-02-09 14:34:53 +01:00
|
|
|
parties.remove(party);
|
2013-01-26 00:40:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new 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-08-26 17:55:35 +02:00
|
|
|
public static void createParty(McMMOPlayer mcMMOPlayer, String partyName, String password) {
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
Party party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName.replace(".", ""), password);
|
2013-05-22 19:02:26 +02:00
|
|
|
|
|
|
|
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-08-26 17:55:35 +02:00
|
|
|
addToParty(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-08-26 17:55:35 +02:00
|
|
|
if (party.isLocked()) {
|
|
|
|
String partyPassword = party.getPassword();
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
if (partyPassword == null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Locked"));
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 19:02:26 +02:00
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
if (password == null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.None"));
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 19:02:26 +02:00
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
if (!password.equals(partyPassword)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Password.Incorrect"));
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 19:02:26 +02:00
|
|
|
}
|
2013-08-26 17:55:35 +02:00
|
|
|
|
|
|
|
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 mcMMOPlayer The player to add to the party
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-08-26 17:55:35 +02:00
|
|
|
public static void joinInvitedParty(McMMOPlayer mcMMOPlayer) {
|
2013-02-08 04:05:08 +01:00
|
|
|
Party invite = mcMMOPlayer.getPartyInvite();
|
2012-06-11 07:45:14 +02:00
|
|
|
|
2013-09-30 11:22:15 +02:00
|
|
|
// Check if the party still exists, it might have been disbanded
|
|
|
|
if (!parties.contains(invite)) {
|
2019-01-13 09:45:17 +01:00
|
|
|
NotificationManager.sendPlayerInformation(mcMMOPlayer.getPlayer(), NotificationType.PARTY_MESSAGE, "Party.Disband");
|
2013-09-30 11:22:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2019-01-13 09:45:17 +01:00
|
|
|
/*
|
|
|
|
* Don't let players join a full party
|
|
|
|
*/
|
|
|
|
if(Config.getInstance().getPartyMaxSize() > 0 && invite.getMembers().size() >= Config.getInstance().getPartyMaxSize())
|
|
|
|
{
|
|
|
|
NotificationManager.sendPlayerInformation(mcMMOPlayer.getPlayer(), NotificationType.PARTY_MESSAGE, "Commands.Party.PartyFull.InviteAccept", invite.getName(), String.valueOf(Config.getInstance().getPartyMaxSize()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationManager.sendPlayerInformation(mcMMOPlayer.getPlayer(), NotificationType.PARTY_MESSAGE, "Commands.Party.Invite.Accepted", invite.getName());
|
2013-02-08 04:05:08 +01:00
|
|
|
mcMMOPlayer.removePartyInvite();
|
2013-08-26 17:55:35 +02:00
|
|
|
addToParty(mcMMOPlayer, invite);
|
2012-06-11 07:45:14 +02:00
|
|
|
}
|
|
|
|
|
2013-10-28 14:01:44 +01:00
|
|
|
/**
|
|
|
|
* Accept a party alliance invitation
|
|
|
|
*
|
|
|
|
* @param mcMMOPlayer The player who accepts the alliance invite
|
|
|
|
*/
|
|
|
|
public static void acceptAllianceInvite(McMMOPlayer mcMMOPlayer) {
|
|
|
|
Party invite = mcMMOPlayer.getPartyAllianceInvite();
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
|
|
|
|
// Check if the party still exists, it might have been disbanded
|
|
|
|
if (!parties.contains(invite)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Party.Disband"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!handlePartyChangeAllianceEvent(player, mcMMOPlayer.getParty().getName(), invite.getName(), McMMOPartyAllianceChangeEvent.EventReason.FORMED_ALLIANCE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Invite.Accepted", invite.getName()));
|
|
|
|
mcMMOPlayer.removePartyAllianceInvite();
|
|
|
|
|
|
|
|
createAlliance(mcMMOPlayer.getParty(), invite);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void createAlliance(Party firstParty, Party secondParty) {
|
|
|
|
firstParty.setAlly(secondParty);
|
|
|
|
secondParty.setAlly(firstParty);
|
|
|
|
|
|
|
|
for (Player member : firstParty.getOnlineMembers()) {
|
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Alliance.Formed", secondParty.getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player member : secondParty.getOnlineMembers()) {
|
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Alliance.Formed", firstParty.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean disbandAlliance(Player player, Party firstParty, Party secondParty){
|
|
|
|
if (!handlePartyChangeAllianceEvent(player, firstParty.getName(), secondParty.getName(), McMMOPartyAllianceChangeEvent.EventReason.DISBAND_ALLIANCE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PartyManager.disbandAlliance(firstParty, secondParty);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void disbandAlliance(Party firstParty, Party secondParty) {
|
|
|
|
firstParty.setAlly(null);
|
|
|
|
secondParty.setAlly(null);
|
|
|
|
|
|
|
|
for (Player member : firstParty.getOnlineMembers()) {
|
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Alliance.Disband", secondParty.getName()));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player member : secondParty.getOnlineMembers()) {
|
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Alliance.Disband", firstParty.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:45:14 +02:00
|
|
|
/**
|
|
|
|
* Add a player to a party
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
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-08-26 17:55:35 +02:00
|
|
|
public static void addToParty(McMMOPlayer mcMMOPlayer, Party party) {
|
2014-07-12 19:44:47 +02:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
String playerName = player.getName();
|
2013-02-25 13:23:18 +01:00
|
|
|
|
2013-05-22 19:02:26 +02:00
|
|
|
informPartyMembersJoin(party, playerName);
|
2013-02-03 16:27:59 +01:00
|
|
|
mcMMOPlayer.setParty(party);
|
2014-07-12 19:44:47 +02:00
|
|
|
party.getMembers().put(player.getUniqueId(), player.getName());
|
|
|
|
party.getOnlineMembers().add(player);
|
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
|
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
public static String getPartyLeaderName(String partyName) {
|
2012-06-08 23:48:41 +02:00
|
|
|
Party party = getParty(partyName);
|
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
return party == null ? null : party.getLeader().getPlayerName();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the leader of a party.
|
|
|
|
*
|
2014-07-12 19:44:47 +02:00
|
|
|
* @param uuid The uuid 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
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
public static void setPartyLeader(UUID uuid, Party party) {
|
|
|
|
OfflinePlayer player = mcMMO.p.getServer().getOfflinePlayer(uuid);
|
|
|
|
UUID leaderUniqueId = party.getLeader().getUniqueId();
|
2012-06-08 23:48:41 +02:00
|
|
|
|
|
|
|
for (Player member : party.getOnlineMembers()) {
|
2014-07-12 19:44:47 +02:00
|
|
|
UUID memberUniqueId = member.getUniqueId();
|
2013-08-26 17:55:35 +02:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
if (memberUniqueId.equals(player.getUniqueId())) {
|
2013-01-17 17:02:55 +01:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.Player"));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
2014-07-12 19:44:47 +02:00
|
|
|
else if (memberUniqueId.equals(leaderUniqueId)) {
|
2013-01-17 17:02:55 +01:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.NotLeader"));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-07-12 19:44:47 +02:00
|
|
|
member.sendMessage(LocaleLoader.getString("Party.Owner.New", player.getName()));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
party.setLeader(new PartyLeader(player.getUniqueId(), player.getName()));
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*
|
2012-06-11 07:45:14 +02:00
|
|
|
* @return true if the player can invite
|
2012-06-08 23:48:41 +02:00
|
|
|
*/
|
2013-08-26 18:20:56 +02:00
|
|
|
public static boolean canInvite(McMMOPlayer mcMMOPlayer) {
|
|
|
|
Party party = mcMMOPlayer.getParty();
|
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
return !party.isLocked() || party.getLeader().getUniqueId().equals(mcMMOPlayer.getPlayer().getUniqueId());
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-10 04:47:35 +01:00
|
|
|
// if (mcMMO.getUpgradeManager().shouldUpgrade(UpgradeType.ADD_UUIDS_PARTY)) {
|
|
|
|
// loadAndUpgradeParties();
|
|
|
|
// return;
|
|
|
|
// }
|
2014-07-12 19:44:47 +02:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
try {
|
|
|
|
YamlConfiguration partiesFile;
|
|
|
|
partiesFile = YamlConfiguration.loadConfiguration(partyFile);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2020-07-13 21:31:30 +02:00
|
|
|
ArrayList<Party> hasAlly = new ArrayList<>();
|
2013-10-28 14:01:44 +01:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
for (String partyName : partiesFile.getConfigurationSection("").getKeys(false)) {
|
|
|
|
Party party = new Party(partyName);
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
String[] leaderSplit = partiesFile.getString(partyName + ".Leader").split("[|]");
|
|
|
|
party.setLeader(new PartyLeader(UUID.fromString(leaderSplit[0]), leaderSplit[1]));
|
|
|
|
party.setPassword(partiesFile.getString(partyName + ".Password"));
|
|
|
|
party.setLocked(partiesFile.getBoolean(partyName + ".Locked"));
|
|
|
|
party.setLevel(partiesFile.getInt(partyName + ".Level"));
|
|
|
|
party.setXp(partiesFile.getInt(partyName + ".Xp"));
|
2013-10-28 14:01:44 +01:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
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));
|
|
|
|
}
|
2013-10-28 14:01:44 +01:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
LinkedHashMap<UUID, String> members = party.getMembers();
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
for (String memberEntry : partiesFile.getStringList(partyName + ".Members")) {
|
|
|
|
String[] memberSplit = memberEntry.split("[|]");
|
|
|
|
members.put(UUID.fromString(memberSplit[0]), memberSplit[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
parties.add(party);
|
2013-08-07 00:38:17 +02:00
|
|
|
}
|
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
mcMMO.p.debug("Loaded (" + parties.size() + ") Parties...");
|
2013-02-09 14:34:53 +01:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
for (Party party : hasAlly) {
|
|
|
|
party.setAlly(PartyManager.getParty(partiesFile.getString(party.getName() + ".Ally")));
|
2013-02-09 14:34:53 +01:00
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2019-06-17 16:38:30 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
2013-10-28 14:01:44 +01:00
|
|
|
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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() {
|
2021-03-17 00:43:25 +01:00
|
|
|
mcMMO.p.debug("[Party Data] Saving...");
|
|
|
|
|
2013-04-23 15:32:28 +02:00
|
|
|
if (partyFile.exists()) {
|
2014-01-19 11:49:30 +01:00
|
|
|
if (!partyFile.delete()) {
|
|
|
|
mcMMO.p.getLogger().warning("Could not delete party file. Party saving failed!");
|
|
|
|
return;
|
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
YamlConfiguration partiesFile = new YamlConfiguration();
|
|
|
|
|
|
|
|
for (Party party : parties) {
|
|
|
|
String partyName = party.getName();
|
2014-07-12 19:44:47 +02:00
|
|
|
PartyLeader leader = party.getLeader();
|
2012-06-08 23:48:41 +02:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
partiesFile.set(partyName + ".Leader", leader.getUniqueId().toString() + "|" + leader.getPlayerName());
|
2012-06-08 23:48:41 +02:00
|
|
|
partiesFile.set(partyName + ".Password", party.getPassword());
|
|
|
|
partiesFile.set(partyName + ".Locked", party.isLocked());
|
2013-11-11 17:42:57 +01:00
|
|
|
partiesFile.set(partyName + ".Level", party.getLevel());
|
|
|
|
partiesFile.set(partyName + ".Xp", (int) party.getXp());
|
2013-10-28 14:01:44 +01:00
|
|
|
partiesFile.set(partyName + ".Ally", (party.getAlly() != null) ? party.getAlly().getName() : "");
|
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
|
|
|
|
2013-08-07 00:38:17 +02:00
|
|
|
for (ItemShareType itemShareType : ItemShareType.values()) {
|
|
|
|
partiesFile.set(partyName + ".ItemShareType." + itemShareType.toString(), party.sharingDrops(itemShareType));
|
|
|
|
}
|
|
|
|
|
2020-07-13 21:31:30 +02:00
|
|
|
List<String> members = new ArrayList<>();
|
2013-02-09 15:26:41 +01:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
for (Entry<UUID, String> memberEntry : party.getMembers().entrySet()) {
|
|
|
|
String memberUniqueId = memberEntry.getKey() == null ? "" : memberEntry.getKey().toString();
|
|
|
|
String memberName = memberEntry.getValue();
|
|
|
|
|
|
|
|
if (!members.contains(memberName)) {
|
|
|
|
members.add(memberUniqueId + "|" + memberName);
|
2013-04-13 00:41:27 +02:00
|
|
|
}
|
2013-02-09 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
partiesFile.set(partyName + ".Members", members);
|
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
|
|
|
|
2021-03-10 04:47:35 +01:00
|
|
|
// 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<>();
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
// }
|
2014-07-12 19:44:47 +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-10-28 14:01:44 +01:00
|
|
|
/**
|
|
|
|
* Handle party alliance change event.
|
|
|
|
*
|
|
|
|
* @param player The player changing party alliances
|
|
|
|
* @param oldAllyName The name of the old ally
|
|
|
|
* @param newAllyName The name of the new ally
|
|
|
|
* @param reason The reason for changing allies
|
|
|
|
* @return true if the change event was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean handlePartyChangeAllianceEvent(Player player, String oldAllyName, String newAllyName, McMMOPartyAllianceChangeEvent.EventReason reason) {
|
|
|
|
McMMOPartyAllianceChangeEvent event = new McMMOPartyAllianceChangeEvent(player, oldAllyName, newAllyName, reason);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
|
|
|
|
return !event.isCancelled();
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
/**
|
|
|
|
* Remove party data from the mcMMOPlayer.
|
|
|
|
*
|
|
|
|
* @param mcMMOPlayer The player to remove party data from.
|
|
|
|
*/
|
|
|
|
public static void processPartyLeaving(McMMOPlayer mcMMOPlayer) {
|
|
|
|
mcMMOPlayer.removeParty();
|
2020-10-27 00:31:02 +01:00
|
|
|
mcMMOPlayer.setChatMode(ChatChannel.NONE);
|
2013-08-26 17:55:35 +02:00
|
|
|
mcMMOPlayer.setItemShareModifier(10);
|
|
|
|
}
|
|
|
|
|
2013-11-11 17:42:57 +01:00
|
|
|
/**
|
|
|
|
* Notify party members when the party levels up.
|
|
|
|
*
|
|
|
|
* @param party The concerned party
|
|
|
|
* @param levelsGained The amount of levels gained
|
|
|
|
* @param level The current party level
|
|
|
|
*/
|
|
|
|
public static void informPartyMembersLevelUp(Party party, int levelsGained, int level) {
|
|
|
|
boolean levelUpSoundsEnabled = Config.getInstance().getLevelUpSoundsEnabled();
|
|
|
|
for (Player member : party.getOnlineMembers()) {
|
|
|
|
member.sendMessage(LocaleLoader.getString("Party.LevelUp", levelsGained, level));
|
|
|
|
|
|
|
|
if (levelUpSoundsEnabled) {
|
2019-01-13 04:08:54 +01:00
|
|
|
SoundManager.sendSound(member, member.getLocation(), SoundType.LEVEL_UP);
|
2013-11-11 17:42:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-06-08 23:48:41 +02:00
|
|
|
}
|