Ejemplo n.º 1
0
 public static function getDefaults()
 {
     if (self::$default_flags == null) {
         $flags = array();
         foreach (scandir(Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mflag") as $key => $flagRaw) {
             if (!in_array($flagRaw, array(".", ".."))) {
                 $path = Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mflag" . DIRECTORY_SEPARATOR . $flagRaw;
                 if (is_file($path)) {
                     $flagName = basename($flagRaw, ".json");
                     $flag = new Flag($flagName);
                     $flags[$flagName] = $flag;
                 }
             }
         }
         self::$default_flags = $flags;
     }
     return self::$default_flags;
 }
Ejemplo n.º 2
0
 public static function getAll()
 {
     if (self::$player_cache == null) {
         $players = array();
         if (!Factions::checkMStore(true)) {
             return $players;
         }
         foreach (scandir(Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mplayer") as $key => $playerRaw) {
             if (!in_array($playerRaw, array(".", ".."))) {
                 $path = Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mplayer" . DIRECTORY_SEPARATOR . $playerRaw;
                 if (is_file($path)) {
                     $playerId = basename($path, ".json");
                     $player = new Player($playerId);
                     $players[$playerId] = $player;
                 }
             }
         }
         self::$player_cache = $players;
     }
     return self::$player_cache;
 }
Ejemplo n.º 3
0
 function __construct($name, $state = null)
 {
     $this->name = $name;
     if ($state != null) {
         $this->state = $state;
     } else {
         $path = Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_mflag" . DIRECTORY_SEPARATOR . $name . ".json";
         $rawJSON = json_decode(file_get_contents($path));
         if ($rawJSON->standard == "true" || $rawJSON->standard == true || $rawJSON->standard == 1 || $rawJSON->standard == "1") {
             $this->state == true;
         } else {
             $this->state == false;
         }
         $this->name = $rawJSON->name;
     }
     // Ensure the state value is nice and tidy
     if ($this->state == 1 || $this->state == true) {
         $this->state = true;
     } else {
         $this->state = false;
     }
 }
Ejemplo n.º 4
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.º 5
0
 private function getPathToJSON()
 {
     return Factions::getMStorePath() . DIRECTORY_SEPARATOR . "factions_faction" . DIRECTORY_SEPARATOR . $this->id . ".json";
 }