API Examples
In this page you can see some examples of Parties API usage.
Table of contents
- Check if two players are in the same party
- Get the party name of a player
- Change party description if not set
- Create a party
- Get party information upon creation
- Get online parties
- Get parties with most members
Check if two players are in the same party
Player player1;
Player player2;
PartiesAPI api = Parties.getApi();
api.areInTheSameParty(player1.getUniqueId(), player2.getUniqueId());
Get the party name of a player
Player somePlayer;
PartiesAPI api = Parties.getApi();
String partyName = api.getPartyPlayer(somePlayer.getUniqueId()).getPartyName();
Change party description if not set
PartiesAPI api = Parties.getApi();
Party party = api.getParty("PartyName");
String description = party.getDescription();
if (description == null) {
party.setDescription("new description");
}
Create a party
Player leader; // You need a leader
PartiesAPI api = Parties.getApi();
boolean success = api.createParty("partyName", api.getPartyPlayer(leader.getUniqueId()));
Get party information upon creation
@EventHandler
public void onPartyCreate(BukkitPartiesPartyPostCreateEvent event) {
String name = event.getParty().getName();
String description = event.getParty().getDescription();
// etc..
}
Get online parties
PartiesAPI api = Parties.getApi();
List<Party> list = api.getOnlineParties();
Get parties with most members
PartiesAPI api = Parties.getApi();
LinkedList<Party> list = api.getPartiesListByMembers(3, 0);
// 3 is the number of parties to get
// 0 is the offset
Party party1 = list.get(0);
Party party2 = list.get(1);
Party party3 = list.get(2);
// Example: Get 5 parties after the first 3
LinkedList<Party> list = api.getPartiesListByMembers(5, 3);