public function getProperty($variable, $defaultValue = null) { if (!array_key_exists($variable, $this->propertyCache)) { $v = getopt("", ["{$variable}::"]); if (isset($v[$variable])) { $this->propertyCache[$variable] = $v[$variable]; } else { $this->propertyCache[$variable] = $this->properties->getNested($variable); } } return $this->propertyCache[$variable] === null ? $defaultValue : $this->propertyCache[$variable]; }
public function getMessage($key, $args = []) { $message = $this->messages->getNested($key, false); if (!$message) { $this->tntRun->getServer()->getLogger()->warning($this->tntRun->getTag() . "Translation for " . $key . " not found in messages.yml!"); return ""; } foreach ($args as $k => $str) { $message = str_replace("%" . $k, $str, $message); } return $this->tntRun->getTag() . trim($this->translateColors($message)); }
public function translateAndFormat($key, ...$args) { $message = $this->messages->getNested($key, false); if (!$message) { $this->tntRun->getServer()->getLogger()->warning("TntRun translation for " . $key . " not found in messages.yml"); return ""; } foreach ($args as $k => $str) { $message = str_replace("%" . $k, $str, $message); } return $this->translateColors($this->tag . $message); }
/** * @param $node * @param ...$vars * @return mixed|null */ public function getMessage($node, ...$vars) { $msg = $this->messages->getNested($node); if ($msg != null) { $number = 0; foreach ($vars as $v) { $msg = str_replace("%var{$number}%", $v, $msg); $number++; } return $msg; } return null; }
/** * @param $identifier * @return bool|string */ public function getMessage($identifier) { if (trim($identifier) === "") { return false; } if (($c = $this->config->getNested($identifier)) !== null) { return $c; } elseif (($o = $this->original->getNested($identifier)) !== null) { return $o; } else { return false; } }
public static function fromConfig(Config $config) { $cred = new MySQLCredentials(); $cred->host = $config->getNested("Database.MySQL.Connection.Address", "example.com"); $cred->port = $config->getNested("Database.MySQL.Connection.Port", 3306); $cred->username = $config->getNested("Database.MySQL.Connection.Username", "root"); $cred->password = $config->getNested("Database.MySQL.Connection.Password", ""); $cred->schema = $config->getNested("Database.MySQL.Connection.Schema", "hereauth"); $cred->socket = $config->getNested("Database.MySQL.Connection.Socket", ""); return $cred; }
public function getOriginalNametag(PPGroup $group, $levelName = null) { if ($levelName === null) { if ($this->config->getNested("groups." . $group->getName() . ".nametag") === null) { $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ") / Setting it to default value."); $this->config->setNested("groups." . $group->getName() . ".nametag", "&8&l[" . $group->getName() . "]&f&r {display_name}"); $this->config->save(); $this->config->reload(); } return $this->config->getNested("groups." . $group->getName() . ".nametag"); } else { if ($this->config->getNested("groups." . $group->getName() . "worlds.{$levelName}.nametag") === null) { $this->getLogger()->critical("Invalid nametag found in config.yml (Group: " . $group->getName() . ", WorldName = {$levelName}) / Setting it to default value."); $this->config->setNested("groups." . $group->getName() . "worlds.{$levelName}.nametag", "&8&l[" . $group->getName() . "]&f&r {display_name}"); $this->config->save(); $this->config->reload(); } return $this->config->getNested("groups." . $group->getName() . "worlds.{$levelName}.nametag"); } }
/** * @param string $variable * @param mixed $defaultValue * * @return mixed */ public function getProperty($variable, $defaultValue = null) { $value = $this->config->getNested($variable); return $value === null ? $defaultValue : $value; }
$opts = getopt("", ["data:", "plugins:", "no-wizard", "enable-profiler"]); define("pocketmine\\DATA", isset($opts["data"]) ? $opts["data"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR); define("pocketmine\\PLUGIN_PATH", isset($opts["plugins"]) ? $opts["plugins"] . DIRECTORY_SEPARATOR : \getcwd() . DIRECTORY_SEPARATOR . "plugins" . DIRECTORY_SEPARATOR); Terminal::init(); define("pocketmine\\ANSI", Terminal::hasFormattingCodes()); if (!file_exists(\pocketmine\DATA)) { mkdir(\pocketmine\DATA, 0777, true); } //Logger has a dependency on timezone, so we'll set it to UTC until we can get the actual timezone. date_default_timezone_set("UTC"); if (!file_exists("katana.yml")) { $content = file_get_contents("src/pocketmine/resources/katana.yml"); @file_put_contents("katana.yml", $content); } $tmpKatanaProperties = new Config("katana.yml", Config::YAML, []); $saveLog = $tmpKatanaProperties->getNested("console.save-console", true); $logger = new MainLogger(\pocketmine\DATA . "server.log", \pocketmine\ANSI, $saveLog); if ($saveLog) { $logger->info("Writing logs to server.log"); } else { $logger->info("Server logging disabled"); } if (!ini_get("date.timezone")) { if ($timezone = detect_system_timezone() and date_default_timezone_set($timezone)) { //Success! Timezone has already been set and validated in the if statement. //This here is just for redundancy just in case some program wants to read timezone data from the ini. ini_set("date.timezone", $timezone); } else { //If system timezone detection fails or timezone is an invalid value. if ($response = Utils::getURL("http://ip-api.com/json") and $ip_geolocation_data = json_decode($response, true) and $ip_geolocation_data['status'] != 'fail' and date_default_timezone_set($ip_geolocation_data['timezone'])) { //Again, for redundancy.
public function initConfig() { if (!file_exists($this->getDataFolder())) { @mkdir($this->getDataFolder()); } $this->saveResource("config.yml"); $cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML); SurvivalGames::$cfg["language"] = $cfg->get("language", "English"); SurvivalGames::$cfg["auto_start_players"] = $cfg->get("auto_start_players", ""); SurvivalGames::$cfg["auto_start_time"] = $cfg->get("auto_start_time", ""); SurvivalGames::$cfg["auto_start_vote"] = $cfg->get("auto_start_vote", ""); SurvivalGames::$cfg["enable_player_queue"] = $cfg->get("enable_player_queue", true); SurvivalGames::$cfg["grace_period"] = $cfg->get("grace_period", 20); SurvivalGames::$cfg["lobby_position"]["x"] = $cfg->getNested("lobby_position.x", $this->getServer()->getDefaultLevel()->getSpawnLocation()->x); SurvivalGames::$cfg["lobby_position"]["y"] = $cfg->getNested("lobby_position.y", $this->getServer()->getDefaultLevel()->getSpawnLocation()->y); SurvivalGames::$cfg["lobby_position"]["z"] = $cfg->getNested("lobby_position.z", $this->getServer()->getDefaultLevel()->getSpawnLocation()->z); SurvivalGames::$cfg["lobby_position"]["world"] = $cfg->getNested("lobby_position.world", $this->getServer()->getDefaultLevel()->getName()); if (!$this->getServer()->isLevelLoaded(SurvivalGames::$cfg["lobby_position"]["world"])) { $this->getServer()->loadLevel(SurvivalGames::$cfg["lobby_position"]["world"]); } SurvivalGames::$cfg["block"]["place"]["whitelist"] = $cfg->getNested("block.place.whitelist", [18, 105, 31, 37, 38, 50, 103, 43]); SurvivalGames::$cfg["block"]["break"]["whitelist"] = $cfg->getNested("block.break.whitelist", [18, 105, 31, 37, 38, 50, 103, 43]); SurvivalGames::$cfg["endgame"]["players"] = $cfg->getNested("endgame.players", 3); SurvivalGames::$cfg["endgame"]["fire_lightning"]["enabled"] = $cfg->getNested("endgame.fire_lightning.enabled", true); SurvivalGames::$cfg["endgame"]["fire_lightning"]["interval"] = $cfg->getNested("endgame.fire_lightning.interval", 20); SurvivalGames::$cfg["deathmatch"]["enabled"] = $cfg->getNested("deathmatch.enabled", false); SurvivalGames::$cfg["deathmatch"]["time"] = $cfg->getNested("deathmatch.time", 30); SurvivalGames::$cfg["deathmatch"]["killtime"] = $cfg->getNested("deathmatch.killtime", 5); SurvivalGames::$cfg["stats"] = $cfg->get("stats", true); SurvivalGames::$cfg["stats_provider"] = $cfg->get("stats_provider", "yaml"); if (!file_exists($this->getDataFolder() . "arenas/")) { @mkdir($this->getDataFolder() . "arenas/"); $this->saveResource("arenas/default.yml"); } if (!file_exists($this->getDataFolder() . "languages/")) { @mkdir($this->getDataFolder() . "languages/"); } $this->saveResource("languages/English.yml"); $this->saveResource("languages/Czech.yml"); if (!file_exists($this->getDataFolder() . "languages/" . SurvivalGames::$cfg['language'] . ".yml")) { $this->msg = new Config($this->getDataFolder() . "languages/English.yml", Config::YAML); $this->getServer()->getLogger()->info("Selected language English"); return; } $this->msg = new Config($this->getDataFolder() . "languages/" . SurvivalGames::$cfg['Language'] . ".yml", Config::YAML); $this->getServer()->getLogger()->info("Selected language " . SurvivalGames::$cfg['Language']); }
{ if (($rank & self::RANK_IMPORTANCE_VIP) === self::RANK_IMPORTANCE_VIP) { return 129600; } if (($rank & self::RANK_IMPORTANCE_DONATOR) === self::RANK_IMPORTANCE_DONATOR) { return 216000; } return PHP_INT_MAX; } /** * @param Vector3 $from * @param Vector3 $to * @return mixed */ public static function isLocalChat($from, $to) { return $from->distanceSquared($to) <= 1600; } } $config = new Config("legionpe.yml", Config::YAML, ["localize" => ["id" => 0, "ip" => "pe.legionpvp.eu", "port" => 19132, "class" => "hub"], "system" => ["isTest" => false, "maxPlayers" => 60]]); Settings::$SYSTEM_MAX_PLAYERS = $config->getNested("system.maxPlayers"); Settings::$SYSTEM_IS_TEST = $config->getNested("system.isTest"); Settings::$PROCESS_ID = getmypid(); Settings::$LOCALIZE_ID = $config->getNested("localize.id"); Settings::$LOCALIZE_IP = $config->getNested("localize.ip"); Settings::$LOCALIZE_PORT = $config->getNested("localize.port"); $array = ["hub" => Settings::CLASS_HUB, "pvp" => Settings::CLASS_KITPVP, "kitpvp" => Settings::CLASS_KITPVP, "parkour" => Settings::CLASS_PARKOUR, "spleef" => Settings::CLASS_SPLEEF, "infected" => Settings::CLASS_INFECTED, "classic" => Settings::CLASS_CLASSICAL, "classical" => Settings::CLASS_CLASSICAL]; if (!isset($array[$config->getNested("localize.class")])) { throw new \RuntimeException("Invalid class: " . var_export($config->getNested("localize.class"), true)); } Settings::$LOCALIZE_CLASS = $array[$config->getNested("localize.class")];
/** * Get the worth of an item * * @param $itemId * @return bool|int */ public function getItemWorth($itemId) { return $this->economy->getNested("worth." . (int) $itemId, false); }
public function onRespawn(PlayerRespawnEvent $event) { $player = $event->getPlayer(); $name = $player->getName(); if ($this->inArena($player)) { $arena = $this->getArena($player); $config = new Config($this->getDataFolder() . "Arenas/" . $arena . ".yml", Config::YAML); $team = $this->getTeam($player->getNameTag()); if ($config->getNested("Bed." . $team . ".Alive") == true) { $welt = $config->getNested("Spawn." . $team . ".Welt"); $x = $config->getNested("Spawn." . $team . ".X"); $y = $config->getNested("Spawn." . $team . ".Y"); $z = $config->getNested("Spawn." . $team . ".Z"); $level = $this->getServer()->getLevelByName($welt); $event->setRespawnPosition(new Position($x, $y, $z, $level)); } else { $event->setRespawnPosition($this->getServer()->getDefaultLevel()->getSafeSpawn()); $player->sendMessage($this->prefix . TextFormat::RED . "Dein Bett wurde zerstört, du kannst nicht mehr respawnen!"); $this->removePlayerFromArena($arena, $name); $this->lasthit[$player->getName()] = "no"; $player->setNameTag($player->getName()); } } }
public function checkFile(Config $arena) { if (!(is_numeric($arena->getNested("signs.join_sign_x")) && is_numeric($arena->getNested("signs.join_sign_y")) && is_numeric($arena->getNested("signs.join_sign_z")) && is_string($arena->getNested("signs.join_sign_world")) && is_string($arena->getNested("signs.status_line_1")) && is_string($arena->getNested("signs.status_line_2")) && is_string($arena->getNested("signs.status_line_3")) && is_string($arena->getNested("signs.status_line_4")) && is_numeric($arena->getNested("signs.return_sign_x")) && is_numeric($arena->getNested("signs.return_sign_y")) && is_numeric($arena->getNested("signs.return_sign_z")) && is_string($arena->getNested("arena.arena_world")) && is_numeric($arena->getNested("arena.join_position_x")) && is_numeric($arena->getNested("arena.join_position_y")) && is_numeric($arena->getNested("arena.join_position_z")) && is_numeric($arena->getNested("arena.lobby_position_x")) && is_numeric($arena->getNested("arena.lobby_position_y")) && is_numeric($arena->getNested("arena.lobby_position_z")) && is_numeric($arena->getNested("arena.first_corner_x")) && is_numeric($arena->getNested("arena.first_corner_z")) && is_numeric($arena->getNested("arena.second_corner_x")) && is_numeric($arena->getNested("arena.second_corner_z")) && is_numeric($arena->getNested("arena.spec_spawn_x")) && is_numeric($arena->getNested("arena.spec_spawn_y")) && is_numeric($arena->getNested("arena.spec_spawn_z")) && is_numeric($arena->getNested("arena.leave_position_x")) && is_numeric($arena->getNested("arena.leave_position_y")) && is_numeric($arena->getNested("arena.leave_position_z")) && is_string($arena->getNested("arena.leave_position_world")) && is_numeric($arena->getNested("arena.max_game_time")) && is_numeric($arena->getNested("arena.max_players")) && is_numeric($arena->getNested("arena.min_players")) && is_numeric($arena->getNested("arena.starting_time")) && is_numeric($arena->getNested("arena.color_wait_time")) && is_numeric($arena->getNested("arena.floor_y")) && is_string($arena->getNested("arena.finish_msg_levels")) && !is_string($arena->getNested("arena.money_reward")))) { return false; } if (!((strtolower($arena->get("type")) == "furious" || strtolower($arena->get("type")) == "stoned" || strtolower($arena->get("type")) == "classic") && (strtolower($arena->get("material")) == "wool" || strtolower($arena->get("material")) == "clay") && (strtolower($arena->getNested("signs.enable_status")) == "true" || strtolower($arena->getNested("signs.enable_status")) == "false") && (strtolower($arena->getNested("arena.spectator_mode")) == "true" || strtolower($arena->getNested("arena.spectator_mode")) == "false") && (strtolower($arena->getNested("arena.time")) == "true" || strtolower($arena->getNested("arena.time")) == "day" || strtolower($arena->getNested("arena.time")) == "night" || is_numeric(strtolower($arena->getNested("arena.time")))) && (strtolower($arena->get("enabled")) == "true" || strtolower($arena->get("enabled")) == "false"))) { return false; } return true; }
public function isWhitelisted(Player $player) { $cfg = new Config($this->getDataFolder() . "players.yml", Config::YAML); if ($cfg->getNested("Players." . strtolower($player->getName())) == "true") { return true; } return false; }