-
-
Notifications
You must be signed in to change notification settings - Fork 42
API
/** @var $player IPlayer|string */
$member = Members::get($player);
/** @var $factionId string */
$faction = Factions::get($factionId);
Special faction IDs are
var_dump(Faction::WARZONE); // warzone
var_dump(Faction::WILDERNESS); // wilderness
var_dump(Faction::SAFEZONE); // safezone
$faction = Factions::getByName(Faction::NAME_SAFEZONE);
Factions::create(string $id, string $name, string $description, array $members = [], array $flags = [], array $perms = [], array $data): Faction
$id: Should be at least one character up to 16 characters. Use Faction::createId()
to generate random uid
$name: Name should pass Faction::validateName(string $name)
check
Example:
$errors = Faction::validateName($name);
if (($c = count($errors)) > 0) {
foreach ($errors as $n => $error) {
# Notify
}
return true;
}
# Create faction...
$description: Pass some random string, there is no rules for this, yet!
$members: Raw member data format looks like this:
"leader": {
"ChrisPrime"
},
"officer": {
"Hugo",
"Andreas"
},
"member": [],
"recruit": {
"Ninja",
"Tako",
"Wuthang"
}
There is a method Factions::createMembersList()
to format array in this format. Be sure to pass $leader
.
If $members
won't contain any member under leader
rank and faction isn't permanent then it will be disbanded or leader rank will be given to next member in case there is any.
Here is an example how to create a Faction.
$faction = Factions::create(
Faction::createId(),
"Test",
"Test Description",
Factions::createMembersList(
Members::get("Dummy", true),
["Hyena", "Hippo"],
[],
["Kugo"]
),
[
Flags::getById(Flag::PERMANENT),
"pvp" => false,
Flag::OPEN => true
],
[
Permissions::getById(Permission::STATUS),
"build" => ["recruit", "leader"],
Permission::PAINBUILD => ["officer", "member"]
],
$data = []
);
NOTE: Faction must be attached to global store using Factions::attach()
or else the faction will cause an errors and won't be saved/loaded.