Skip to content

API: Factions

Mark Hughes edited this page Aug 11, 2017 · 3 revisions

You can work with Factions extremely easily with the LegacyFactions API.

Getting Factions

Use the Factions Collection class (FactionColl) to get a list of all Factions:

List<Faction> all = FactionColl.all();

You can use this in a for loop like this:

for (Faction faction : FactionColl.all()) {
    String tag = faction.getTag();
}

You can see all the methods for the Faction class right here on GitHub.

Want to take advantage of lambdas? The FactionColl in LegacyFactions provides this to you:

FactionColl.all(faction -> {
    faction.sendMessage("Woo!");
});

You can also get a Faction by FPlayer, Player, Faction Id, or name all from the one .get() method:

Faction faction = FactionColl.get(player);
Faction faction = FactionColl.get("-1");
Faction faction = FactionColl.get("name");
...

The .get() method will work it out for you. Easy, right?

Warps

Should you want to work with warps you can grab the warps class for the faction like so:

Faction faction = ...; // Get your faction however

FactionWarps warps = faction.warps(); // Ta-da!

With this you can get, create, and delete warps. This will not call events.

FactionWarp someWarp = faction.warps().get("cave_warp");
Location location = someWarp.getLocation();

if (someWarp.hasPassword()) {
    sendMessage("this warp has a password: " + someWarp.getPassword()); // in practice, we probably wouldn't do this!
}

someWarp.delete();

This is an example of creating a warp:

faction.warps().setWarp("hello", location);
faction.warps().setWarp("hello", location, "P4s$W0Rd"); // if it exists, we overwrite it

Creating a Faction

Not all methods are statically available, and you will need to get the instance of the FactionColl to access them:

Faction newFaction = FactionColl.get().createFaction();

Other Methods

There are lots of other methods that can be accessed on the FactionColl instance. You can see those here.