Ejemplo n.º 1
0
use FactionsPHP\BukkitTools;
// This next line is required - points us to the mstore folder
Factions::setMStorePath("/Users/markhughes/Spigot/mstore");
// This next line is optional, but lets us use players names (you should though)
BukkitTools::enableUserCache("/Users/markhughes/Spigot/usercache.json");
// Get all Factions (pass false to exclude permanent factions)
foreach (Factions::getAll(true) as $faction) {
    // Get faction name
    $name = $faction->getName();
    // Get creation date, pass no args for timestamp
    $created = $faction->getCreationDate("d/m/Y");
    echol($name);
    echol("Created on " . $created);
    // Check for a leader
    if ($faction->getLeader() != null) {
        $leader = $faction->getLeader();
        $leaderName = $leader->getName();
        echol("The leader is: {$leaderName}");
    }
    echol("");
}
// You can also get by id
$faction = Factions::getById("0268c6f1-66fc-4ba7-9091-097518064b56");
// You can also get the player
$player = Players::getByName("MarkehMe");
// and their faction
$playersFaction = $player->getFaction();
// Of course, other general player information we managed to fetch
echol($player->getPower());
echol($player->getRole());
echol($player->getLastActivityMillis());
Ejemplo n.º 2
0
 private function getJSON()
 {
     if ($this->json == null) {
         $this->json = json_decode(file_get_contents($this->getPathToJSON()));
         // Load flags up nicely
         $this->flags = [];
         if (isset($this->json->flags)) {
             foreach ($this->json->flags as $name => $state) {
                 $this->flags[$name] = new Flag($name, $state);
             }
         }
         $this->ensureAllFlagsLogged();
         // Load perms up nicely too
         $this->perms = [];
         if (isset($this->json->perms)) {
             foreach ($this->json->perms as $name => $perms) {
                 $this->perms[$name] = new Perm($name, $perms);
             }
         }
         $this->ensureAllPermsLogged();
         foreach (Players::getAll() as $playerId => $player) {
             if ($player->getFactionId() == $this->id) {
                 $this->members[$playerId] = $player;
                 if ($player->getRole() == "LEADER") {
                     $this->leader = $player;
                 }
                 if ($player->getRole() == "OFFICER") {
                     $this->officers[$playerId] = $player;
                 }
             }
         }
     }
     return $this->json;
 }