2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.api;
|
|
|
|
|
2019-01-11 15:17:07 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2019-01-14 06:27:56 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
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;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.party.PartyManager;
|
2019-01-15 07:11:58 +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-15 07:11:58 +01:00
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.*;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public final class PartyAPI {
|
|
|
|
private PartyAPI() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the name of the party a player is in.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to check the party name of
|
2013-03-17 14:02:15 +01:00
|
|
|
* @return the name of the player's party, or null if not in a party
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static String getPartyName(Player player) {
|
2013-03-17 14:02:15 +01:00
|
|
|
if (!inParty(player)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
return UserManager.getPlayer(player).getParty().getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a player is in a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return true if the player is in a party, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean inParty(Player player) {
|
2019-04-13 00:17:05 +02:00
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
return false;
|
|
|
|
|
2013-08-20 20:10:49 +02:00
|
|
|
return UserManager.getPlayer(player).inParty();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if two players are in the same party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param playera The first player to check
|
|
|
|
* @param playerb The second player to check
|
|
|
|
* @return true if the two players are in the same party, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean inSameParty(Player playera, Player playerb) {
|
|
|
|
return PartyManager.inSameParty(playera, playerb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all current parties.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @return the list of parties.
|
|
|
|
*/
|
|
|
|
public static List<Party> getParties() {
|
|
|
|
return PartyManager.getParties();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a player to a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add to the party
|
|
|
|
* @param partyName The party to add the player to
|
2019-01-11 15:17:07 +01:00
|
|
|
* @deprecated parties can have limits, use the other method
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2019-01-11 15:17:07 +01:00
|
|
|
@Deprecated
|
2013-03-01 06:52:01 +01:00
|
|
|
public static void addToParty(Player player, String partyName) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Check if player profile is loaded
|
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
return;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
Party party = PartyManager.getParty(partyName);
|
|
|
|
|
2019-01-11 15:17:07 +01:00
|
|
|
if (party == null) {
|
|
|
|
party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName);
|
|
|
|
} else {
|
|
|
|
if(PartyManager.isPartyFull(player, party))
|
|
|
|
{
|
2019-01-14 06:27:56 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.PARTY_MESSAGE, "Commands.Party.PartyFull", party.toString());
|
2019-01-11 15:17:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PartyManager.addToParty(UserManager.getPlayer(player), party);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The max party size of the server
|
|
|
|
* 0 or less for no size limit
|
|
|
|
* @return the max party size on this server
|
|
|
|
*/
|
|
|
|
public static int getMaxPartySize()
|
|
|
|
{
|
|
|
|
return Config.getInstance().getPartyMaxSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a player to a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to add to the party
|
|
|
|
* @param partyName The party to add the player to
|
|
|
|
* @param bypassLimit if true bypasses party size limits
|
|
|
|
*/
|
2019-04-13 00:17:05 +02:00
|
|
|
//TODO: bypasslimit not used?
|
2019-01-11 15:17:07 +01:00
|
|
|
public static void addToParty(Player player, String partyName, boolean bypassLimit) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Check if player profile is loaded
|
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
return;
|
|
|
|
|
2019-01-11 15:17:07 +01:00
|
|
|
Party party = PartyManager.getParty(partyName);
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
if (party == null) {
|
2014-07-12 19:44:47 +02:00
|
|
|
party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
PartyManager.addToParty(UserManager.getPlayer(player), party);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a player from a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to remove
|
|
|
|
*/
|
|
|
|
public static void removeFromParty(Player player) {
|
2019-04-13 00:17:05 +02:00
|
|
|
//Check if player profile is loaded
|
|
|
|
if(UserManager.getPlayer(player) == null)
|
|
|
|
return;
|
|
|
|
|
2013-08-26 17:55:35 +02:00
|
|
|
PartyManager.removeFromParty(UserManager.getPlayer(player));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the leader of a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param partyName The party name
|
|
|
|
* @return the leader of the party
|
|
|
|
*/
|
|
|
|
public static String getPartyLeader(String partyName) {
|
2014-07-12 19:44:47 +02:00
|
|
|
return PartyManager.getPartyLeaderName(partyName);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the leader of a party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param partyName The name of the party to set the leader of
|
2014-07-12 19:44:47 +02:00
|
|
|
* @param playerName The playerName to set as leader
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
@Deprecated
|
|
|
|
public static void setPartyLeader(String partyName, String playerName) {
|
|
|
|
PartyManager.setPartyLeader(mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId(), PartyManager.getParty(partyName));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all players in this player's party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all the players in the player's party
|
|
|
|
*/
|
2013-04-13 00:41:27 +02:00
|
|
|
@Deprecated
|
2013-03-01 06:52:01 +01:00
|
|
|
public static List<OfflinePlayer> getOnlineAndOfflineMembers(Player player) {
|
2020-07-13 21:31:30 +02:00
|
|
|
List<OfflinePlayer> members = new ArrayList<>();
|
2013-04-13 00:41:27 +02:00
|
|
|
|
2014-07-12 19:44:47 +02:00
|
|
|
for (UUID memberUniqueId : PartyManager.getAllMembers(player).keySet()) {
|
|
|
|
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId);
|
2013-04-13 00:41:27 +02:00
|
|
|
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
|
|
|
|
*/
|
2014-07-12 19:44:47 +02:00
|
|
|
@Deprecated
|
2013-04-13 18:43:22 +02:00
|
|
|
public static LinkedHashSet<String> getMembers(Player player) {
|
2014-07-12 19:44:47 +02:00
|
|
|
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) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return PartyManager.getAllMembers(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param partyName The party to check
|
|
|
|
* @return all online players in this party
|
|
|
|
*/
|
|
|
|
public static List<Player> getOnlineMembers(String partyName) {
|
|
|
|
return PartyManager.getOnlineMembers(partyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of all online players in this player's party.
|
|
|
|
* </br>
|
|
|
|
* This function is designed for API usage.
|
|
|
|
*
|
|
|
|
* @param player The player to check
|
|
|
|
* @return all online players in the player's party
|
|
|
|
*/
|
|
|
|
public static List<Player> getOnlineMembers(Player player) {
|
|
|
|
return PartyManager.getOnlineMembers(player);
|
|
|
|
}
|
2013-10-28 14:01:44 +01:00
|
|
|
|
|
|
|
public static boolean hasAlly(String partyName) {
|
2014-05-02 00:53:05 +02:00
|
|
|
return getAllyName(partyName) != null;
|
2013-10-28 14:01:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getAllyName(String partyName) {
|
|
|
|
Party ally = PartyManager.getParty(partyName).getAlly();
|
|
|
|
if (ally != null) {
|
|
|
|
return ally.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|