-
Notifications
You must be signed in to change notification settings - Fork 13
API: Factions
You can work with Factions extremely easily with the LegacyFactions API.
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?
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
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();
There are lots of other methods that can be accessed on the FactionColl instance. You can see those here.
📚 Looking for documentation? You're in the right place. Start with the items on the right of the page.
🐞 Found a bug? Please open a GitHub Issue.
🆘 Need help? Jump on our discord channel - we'll do our best to help 😄
⭐️ If you like LegacyFactions please leave a review and let others know!