Skip to content

Accessing Factions

Bartłomiej Stępień edited this page Apr 15, 2024 · 5 revisions

To access Eagle Factions services you need to get EagleFactions instance first. You can read here to get to know how to get it.

Accessing Factions

To get a faction you are interested in you can use FactionLogic interface.

One thing to remember is that by default any Faction object is immutable. To change its state you should use methods in FactionLogic interface.

FactionLogic factionLogic = eaglefactions.getFactionLogic();

// Getting faction by player. Returns Optional as player does not necessarily be in a faction.
Optional<Faction> faction = factionLogic.getFactionByPlayerUUID(playerUUID);

// Getting faction by name. Returns faction or null.
Faction faction1 = factionLogic.getFactionByName("my_faction_name");

// Getting faction by chunk. Return Optional as chunk may not be claimed by any faction.
Optional<Faction> faction2 = factionLogic.getFactionByChunk(worldUUID, chunkPosition);

// You can also loop through all factions if needed by fetching them with following
Map<String, Faction> factions = factionLogic.getFactions();

Saving factions

As because Faction is immutable by default, methods in FactionLogic should be used to save/update it. For example if we would want to add a claim to a faction, we could do the following:

Faction myFaction = factionLogic.getFactionByPlayerUUID(playerUUID);
Claim claim = new Claim(worldUUID, chunkPosition);

// Add new claim to faction
factionLogic.addClaim(faction, claim);

Creating new faction

It is also possible to create a new faction by getting its builder from EagleFactions instance. Remember that after building it, you should pass it to FactionLogic#addFaction.

Faction faction = eagleFactions.getBuilderForFaction(myFactionName, tag, leaderUUID)
    .description(myDescription)
    .ranks(ranks) // Remember that in default EF implementation, "default" and "leader" ranks are required to exist.
    .messageOfTheDay(messageOfTheDay)
    ...moreMethods
    .build();

factionLogic.addFaction(faction);
Clone this wiki locally