Clans API and how to use it - Hempfest/Clans GitHub Wiki

Importing w/ pom

Let's learn some quick things to get you started modifying things using clans API and events.

Modifying your first event.

(Example, sends a message to the claim owner that a player is in their claim)

public class Example implements Listener {

	private final List<Player> msgSent = new ArrayList<>();

	@EventHandler(priority = EventPriority.NORMAL)
	public void onClaimUpdate(ClaimResidentEvent event) {
		event.setClaimTitle("&5Something cool", "%s owns this land");
		Player p = event.getResident().getPlayer();
		// Getting the claim object.
		Claim claim = event.getClaim();
		List<String> members = Arrays.asList(claim.getClan().getMembers());
		if (!members.contains(p.getName())) {
			if (!msgSent.contains(p)) {
				msgSent.add(p);
				claim.getClan().messageClan("&4&lBREACH &6> " + p.getName() + " is traversing clan land.");
			}
		}
	}
	
	@EventHandler(priority = EventPriority.NORMAL)
	public void onWildUpdate(WildernessInhabitantEvent event) {
		msgSent.remove(event.getPlayer());
	}

}

Accessing cached clan objects

(Alternative to new instances)

// Grabbing a clan object using the player as the key
Clan clan = HempfestClans.clanManager(player);

// Grabbing a clan object using a clanId as the key
Clan clan = Clan.clanUtil.getClan(clanId);

// Using stream() to scramble for a result (not sure why but this be how)
Clan clan = Clan.clanUtil.getClans.stream().filter(c -> Objects.equals(c.getClanID, clanId)).findFirst().orElse(null);

Retrieving a clan's ID or Tag

String id = Clan.clanUtil.getClanID(clanName);

String tag = Clan.clanUtil.getClanTag(clanId);

Know your Util

public Clan clan = new Clan(clanID); //- [A clan object class for getting clan information by clan id.]
public Claim claim = new Claim(claimID); //- [A claim object class for getting stats regarding a claim by id.]
public ClanUtil clanUtil = new ClanUtil(); //- [Utility class for setting clan information and getting player information]
public ClaimUtil claimUtil = new ClaimUtil(); //- [Utility class for setting claim information]
public StringLibrary lib = new StringLibrary(); //- [Utility class for handling player messaging and list pagination.]

⚠️ **GitHub.com Fallback** ⚠️