API Examples

These are some examples that you can do with the Parties API:



Get player party

Player somePlayer;
PartiesAPI api = Parties.getApi();
String partyName = api.getPartyPlayer(somePlayer.getUniqueId()).getPartyName();


Change party description if empty

PartiesAPI api = Parties.getApi();
Party party = api.getParty("PartyName");
String description = party.getDescription();
if (description.isEmpty()) {
    party.setDescription("new description");
    api.updateParty(party);
}


Create a party

Player leader; // You need a leader
PartiesAPI api = Parties.getApi();
Status status = api.createParty(api.getPartyPlayer(leader.getUniqueId(), "partyName");
if (status == Status.SUCCESS) {
    // Party created
} else {
    // Something gone wrong
    switch (status) {
      case ALREADYINPARTY:
        // Player already has a party
      case ALREADYEXISTPARTY:
        // Party already exists
    }
}


Get party information upon creation

@EventHandler
public void onPartyCreate(PartiesPartyPostCreateEvent event) {
    String description = event.getParty().getDescription();
    String prefix = event.getParty().getPrefix();
    // etc..
}


Get online parties

PartiesAPI api = Parties.getApi();
List<Party> list = api.getOnlineParties();