Config Class for simple config manipulation of multiple formats.
Exemplo n.º 1
1
 public function payTax()
 {
     if (($percent = $this->config->get("tax-as-percentage")) !== "") {
         $players = $this->getServer()->getOnlinePlayers();
         foreach ($players as $player) {
             if ($player->hasPermission("economytax.tax.avoid")) {
                 continue;
             }
             $money = $this->api->myMoney($player);
             $taking = $money * ($percent / 100);
             $this->api->reduceMoney($player, min($money, $taking), true, "EconomyTax");
             $player->sendMessage("Your " . EconomyAPI::getInstance()->getMonetaryUnit() . "{$taking} has taken by tax.");
         }
     } else {
         $money = $this->config->get("tax-as-money");
         $players = $this->getServer()->getOnlinePlayers();
         foreach ($players as $player) {
             if ($player->hasPermission("economytax.tax.avoid")) {
                 continue;
             }
             $this->api->reduceMoney($player, min($this->api->myMoney($player), $money), true, "EconomyTax");
             $player->sendMessage("Your " . EconomyAPI::getInstance()->getMonetaryUnit() . "{$money} has taken by tax.");
         }
     }
 }
Exemplo n.º 2
1
 /**
  * @param Player $player
  * @param bool $value
  */
 public function setExempt(Player $player, $value = true)
 {
     if ($value) {
         $this->exempts->set(strtolower($player->getName()));
         $this->exempts->save();
     } else {
         $this->exempts->remove(strtolower($player->getName()));
         $this->exempts->save();
     }
 }
Exemplo n.º 3
0
 public function saveYml()
 {
     ksort($this->nn);
     $nn = new Config($this->getServer()->getDataPath() . "/plugins/! MineBlock/" . "NickName.yml", Config::YAML, []);
     $nn->setAll($this->nn);
     $nn->save();
 }
Exemplo n.º 4
0
 public function savePlayer(IPlayer $player, array $config)
 {
     $name = trim(strtolower($player->getName()));
     $data = new Config($this->plugin->getDataFolder() . "players/" . $name[0] . "/{$name}.yml", Config::YAML);
     $data->setAll($config);
     $data->save();
 }
Exemplo n.º 5
0
 public function saveYml()
 {
     $fly = new Config($this->getServer()->getDataPath() . "/plugins/! DeBePlugins/" . "Fly.yml", Config::YAML);
     $fly->setAll($this->fly);
     $fly->save();
     $this->loadYml();
 }
Exemplo n.º 6
0
 public function checkUpdate()
 {
     $this->getPlugin()->getServer()->getPluginManager()->callEvent($event = new UpdateCheckingEvent($this->getPlugin(), $this->channel));
     if ($event->isCancelled()) {
         return false;
     }
     if ($this->channel == "beta") {
         $address = "https://api.github.com/repos/cybercube-hk/jail/releases";
     } else {
         $this->plugin->getLogger()->alert("[UPDATER] INVALID CHANNEL!");
         return false;
     }
     $i = json_decode(Utils::getURL($address), true);
     if ($this->channel == "beta") {
         $i = $i[0];
         $this->newversion = substr($i["name"], 6);
         $this->dlurl = $i["assets"][0]["browser_download_url"];
     }
     $plugin = $this->getPlugin();
     if ($plugin::VERSION_STRING !== $this->newversion) {
         $path = $this->plugin->getDataFolder() . "newest-version-download-link.txt";
         echo "\n";
         $this->plugin->getLogger()->info("Your version is too old or too new!  The latest " . $this->channel . " version is: (version: " . $this->newversion . ")");
         $this->plugin->getLogger()->info("Download url for the latest version: §e" . $this->dlurl . "");
         $this->plugin->getLogger()->info("The link is being saved into: §bnewest-version-download-link.txt\n");
         $txt = new Config($path, Config::ENUM);
         $txt->set("Version " . $this->newversion . " -> " . $this->dlurl, true);
         $txt->save();
         return true;
     }
     echo "\n";
     $this->plugin->getLogger()->info("No updates found!  Your Jail version is up-to-date!\n");
     return true;
 }
Exemplo n.º 7
0
 public function saveYml()
 {
     asort($this->si);
     $si = new Config($this->getServer()->getDataPath() . "/plugins/! MineBlock/" . "SubInventory.yml", Config::YAML);
     $si->setAll($this->si);
     $si->save();
 }
 public function setPlayer(IPlayer $player, $rank)
 {
     $fileName = $this->plugin->getDataFolder() . "players/" . strtolower($player->getName()) . ".yml";
     $config = new Config($fileName, Config::YAML, ["name" => $player->getName(), "rank" => $rank]);
     $config->set("rank", $rank);
     $config->save(true);
 }
Exemplo n.º 9
0
 public function onRun($currentTick)
 {
     $config = new Config($this->getOwner()->getDataFolder() . "dispensers.yml", Config::YAML);
     $config->setAll($this->getOwner()->getDispenserList());
     $config->save();
     $this->getOwner()->getLogger()->info(TextFormat::AQUA . "Auto-saved!");
 }
Exemplo n.º 10
0
 public function process()
 {
     $path = $this->getServer()->getPluginManager()->getPlugin("SimpleAuth")->getDataFolder() . "/players/";
     foreach (glob($path . "*/*.yml") as $file) {
         $data = new Config($file, Config::YAML);
         $pname = trim(strtolower(basename($file, ".yml")));
         $regdate = $data->get("registerdate");
         $logindate = $data->get("logindate");
         $ip = $data->get("lastip");
         $hash = $data->get("hash");
         /*$this->db->query("UPDATE simpleauth_players SET name = 
         		'" . $pname . "', hash = '" . $hash . "', registerdate = '"
         		. $regdate ."', logindate = '" . $logindate . "', lastip = '"
         		. $ip . "' WHERE ");*/
         $result = $this->db->query("INSERT INTO simpleauth_players (name, hash, registerdate, logindate, lastip)\n\t\t\t\t\t\t\t\t\t\tVALUES ('{$pname}', '{$hash}', '{$regdate}', '{$logindate}', '{$ip}')");
         if ($result) {
             $this->users++;
         } else {
             $this->getServer()->getPluginManager()->disablePlugin($this);
             $this->getLogger()->critical("Unable to sumbit user to MySQL Database: Unknown Error. Disabling Plugin...");
         }
         if ($this->users % 100 === 0) {
             $this->getLogger()->notice((string) $this->users . " processed.");
         }
     }
 }
Exemplo n.º 11
0
 public function checkConfig()
 {
     if ($this->version > ConfigUpdater::CONFIG_VERSION) {
         $this->tapToDo->getLogger()->warning("The config loaded is not supported. It may not function correctly. ");
     }
     while ($this->version < ConfigUpdater::CONFIG_VERSION) {
         switch ($this->version) {
             case 0:
                 $this->tapToDo->getLogger()->info("Updating config from version 0 to 1...");
                 $blocks = $this->config->getAll();
                 foreach ($blocks as $id => $block) {
                     foreach ($block["commands"] as $i => $command) {
                         if (strpos($command, "%safe") === false && strpos($command, "%op") === false) {
                             $command .= "%pow";
                         }
                         $block["commands"][$i] = str_replace("%safe", "", $command);
                     }
                     $blocks[$id] = $block;
                 }
                 unlink($this->tapToDo->getDataFolder() . "blocks.yml");
                 $this->tapToDo->saveResource("blocks.yml");
                 $this->config = new Config($this->tapToDo->getDataFolder() . "blocks.yml", Config::YAML);
                 $this->config->set("version", 1);
                 $this->config->set("blocks", $blocks);
                 $this->config->save();
                 $this->version = 1;
                 break;
         }
     }
     return $this->config;
 }
Exemplo n.º 12
0
 /**
  * Save a config section to the plugins' config.yml
  *
  * @param str $key - section to save
  * @param mixed $settings - settings to save
  */
 public function cfgSave($key, $settings)
 {
     $cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML);
     $dat = $cfg->getAll();
     $dat[$key] = $settings;
     $cfg->setAll($dat);
     $cfg->save();
 }
Exemplo n.º 13
0
 public function save()
 {
     $config = new Config($this->path . "protects.yml", Config::YAML);
     $config->setAll($this->yml);
     $config->save();
     $config = new Config($this->path . "options.yml", Config::YAML);
     $config->setAll($this->option);
     $config->save();
 }
Exemplo n.º 14
0
 public function onDisable()
 {
     $save = new Config($this->getDataFolder() . "GambleDB.yml", Config::YAML);
     $save->setAll($this->db);
     $save->save();
     $save = new Config($this->getDataFolder() . "lotto.yml", Config::YAML);
     $save->setAll($this->lotto);
     $save->save();
 }
Exemplo n.º 15
0
 public function onDisable()
 {
     $config = new Config($this->getDataFolder() . "donators.yml", Config::YAML, array());
     $config->setAll($this->donators);
     $config->save();
     $kits = new Config($this->getDataFolder() . "kits.yml", Config::YAML, array());
     $kits->setAll($this->kits);
     $kits->save();
 }
Exemplo n.º 16
0
 public static function init()
 {
     if (!file_exists($this->plugin->dataDir . $this->filename . ".yml")) {
         $this->plugin->getLogger()->info(TextFormat::RED . "Can't find " . $this->filename . " creating new one !");
         $d = new Config($this->plugin->dataDir . $this->filename . ".yml", Config::YAML, array());
         $d->save();
         return $d;
     }
     return new Config($this->plugin->dataDir . $this->filename . ".yml", Config::YAML, array());
 }
Exemplo n.º 17
0
 public function onDisable()
 {
     $save = new Config($this->getDataFolder() . "database.yml", Config::YAML);
     $save->setAll($this->db);
     $save->save();
     if ($this->interlocker->dummyPlayer instanceof DummyPlayer) {
         $this->interlocker->dummyPlayer->loggedIn = false;
         $this->interlocker->dummyPlayer->close();
     }
 }
Exemplo n.º 18
0
 public function onEnable()
 {
     // Initializing config files
     $this->saveResource("config.yml");
     $yml = new Config($this->getDataFolder() . "config.yml", Config::YAML);
     $this->yml = $yml->getAll();
     $this->getLogger()->debug("Config files have been saved!");
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $this->getServer()->getLogger()->info(Color::BOLD . Color::GOLD . "M" . Color::AQUA . "TeamPvP " . Color::GREEN . "Enabled" . Color::RED . "!");
 }
Exemplo n.º 19
0
 public function saveShops()
 {
     $shops = $this->shops;
     foreach ($shops as $loc => $data) {
         $shops[$loc]["case"] = "";
     }
     $conf = new Config($this->getDataFolder() . "shops.yml", Config::YAML);
     $conf->setAll($shops);
     $conf->save();
 }
 /**
  *
  * @param string $name        	
  *
  * @return CompoundTag
  */
 public function getOfflinePlayerData($name)
 {
     $name = strtolower($name);
     $path = $this->datapath . "players/";
     if (file_exists($path . "{$name}.dat")) {
         try {
             $nbt = new NBT(NBT::BIG_ENDIAN);
             $nbt->readCompressed(file_get_contents($path . "{$name}.dat"));
             return $nbt->getData();
         } catch (\Throwable $e) {
             // zlib decode error / corrupt data
             rename($path . "{$name}.dat", $path . "{$name}.dat.bak");
         }
     }
     $spawn = explode(':', $this->spawn);
     $nbt = new CompoundTag("", [new LongTag("firstPlayed", floor(microtime(true) * 1000)), new LongTag("lastPlayed", floor(microtime(true) * 1000)), new ListTag("Pos", [new DoubleTag(0, $spawn[0]), new DoubleTag(1, $spawn[1]), new DoubleTag(2, $spawn[2])]), new StringTag("Level", $spawn[3]), new ListTag("Inventory", []), new CompoundTag("Achievements", []), new IntTag("playerGameType", $this->gamemode), new ListTag("Motion", [new DoubleTag(0, 0.0), new DoubleTag(1, 0.0), new DoubleTag(2, 0.0)]), new ListTag("Rotation", [new FloatTag(0, 0.0), new FloatTag(1, 0.0)]), new FloatTag("FallDistance", 0.0), new ShortTag("Fire", 0), new ShortTag("Air", 300), new ByteTag("OnGround", 1), new ByteTag("Invulnerable", 0), new StringTag("NameTag", $name)]);
     $nbt->Pos->setTagType(NBT::TAG_Double);
     $nbt->Inventory->setTagType(NBT::TAG_Compound);
     $nbt->Motion->setTagType(NBT::TAG_Double);
     $nbt->Rotation->setTagType(NBT::TAG_Float);
     if (file_exists($path . "{$name}.yml")) {
         // Importing old PocketMine-MP files
         $data = new Config($path . "{$name}.yml", Config::YAML, []);
         $nbt["playerGameType"] = (int) $data->get("gamemode");
         $nbt["Level"] = $data->get("position")["level"];
         $nbt["Pos"][0] = $data->get("position")["x"];
         $nbt["Pos"][1] = $data->get("position")["y"];
         $nbt["Pos"][2] = $data->get("position")["z"];
         $nbt["SpawnLevel"] = $data->get("spawn")["level"];
         $nbt["SpawnX"] = (int) $data->get("spawn")["x"];
         $nbt["SpawnY"] = (int) $data->get("spawn")["y"];
         $nbt["SpawnZ"] = (int) $data->get("spawn")["z"];
         foreach ($data->get("inventory") as $slot => $item) {
             if (count($item) === 3) {
                 $nbt->Inventory[$slot + 9] = new CompoundTag("", [new ShortTag("id", $item[0]), new ShortTag("Damage", $item[1]), new ByteTag("Count", $item[2]), new ByteTag("Slot", $slot + 9), new ByteTag("TrueSlot", $slot + 9)]);
             }
         }
         foreach ($data->get("hotbar") as $slot => $itemSlot) {
             if (isset($nbt->Inventory[$itemSlot + 9])) {
                 $item = $nbt->Inventory[$itemSlot + 9];
                 $nbt->Inventory[$slot] = new CompoundTag("", [new ShortTag("id", $item["id"]), new ShortTag("Damage", $item["Damage"]), new ByteTag("Count", $item["Count"]), new ByteTag("Slot", $slot), new ByteTag("TrueSlot", $item["TrueSlot"])]);
             }
         }
         foreach ($data->get("armor") as $slot => $item) {
             if (count($item) === 2) {
                 $nbt->Inventory[$slot + 100] = new CompoundTag("", [new ShortTag("id", $item[0]), new ShortTag("Damage", $item[1]), new ByteTag("Count", 1), new ByteTag("Slot", $slot + 100)]);
             }
         }
         foreach ($data->get("achievements") as $achievement => $status) {
             $nbt->Achievements[$achievement] = new ByteTag($achievement, $status == true ? 1 : 0);
         }
         unlink($path . "{$name}.yml");
     }
     return $nbt;
 }
Exemplo n.º 21
0
 public function saveChests()
 {
     $save = [];
     foreach ($this->chests as $chest) {
         /** @var ChestPattern $pattern */
         $pattern = $chest->getPattern();
         $save[] = ["x" => $chest->getPosition()->x, "y" => $chest->getPosition()->y, "z" => $chest->getPosition()->z, "levelName" => $chest->getPosition()->getLevel()->getName(), "patternName" => $pattern::getName(), "patternArgs" => $pattern->getPatternData()];
     }
     $this->config->setAll($save);
     $this->config->save();
 }
Exemplo n.º 22
0
 public function onEnable()
 {
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     if (!file_exists($this->getDataFolder())) {
         @mkdir($this->getDataFolder(), 0755, true);
     }
     $c = new Config($this->getDataFolder() . "country.yml", Config::YAML, array("en" => false, "us" => false, "fr" => false, "cn" => true, "in" => true, "sy" => true, "so" => true, "kr" => true));
     $c->save();
     $this->c = $c->getAll();
     $this->reason = ["en" => "§aYou are not allowed to get in as of your living country", "us" => "§aYou are not allowed to get in as of your living country", "fr" => "§aYou are not allowed to get in as of your living country", "cn" => "§a你因为安全高风险国家的国家,一直踢。", "in" => "§aक्योंकि सुरक्षा के उच्च जोखिम वाले देशों के अपने देश, लात कर दिया गया है", "sy" => "§aكان بلدكم بسبب الدول عالية المخاطر الأمنية، ركلة.", "so" => "§aYour dalka sababtoo ah dalalka khatarta sare ammaanka, ayaa laad", "kr" => "§a당신의 나라는 보안 위험이 높은 국가이기 때문에, kick되었습니다."];
 }
 public function updatePlayer(IPlayer $player, $type)
 {
     $name = strtolower($player->getName());
     if ($this->playerExists($player)) {
         @mkdir($this->plugin->getDataFolder() . "players/" . $name . ".yml");
         $data = new Config($this->plugin->getDataFolder() . "players/" . $name . ".yml");
         $data->set($type, $data->getAll()[$type] + 1);
         return $data->save();
     } else {
         $this->addPlayer($player);
     }
 }
Exemplo n.º 24
0
 public function __construct(Config $config)
 {
     $dat = $config->getALL();
     $version = $dat["messages-version"];
     $language = $dat["default-language"];
     $messages = $dat["messages"];
     $this->messagesVersion = (isset($version) and is_int($version)) ? $version : 0;
     $this->defaultLanguage = (isset($language) and is_string($language)) ? $language : "eng";
     $this->messages = (isset($messages) and is_array($messages)) ? $messages : [];
     $this->config = $config;
     $this->dat = $dat;
 }
Exemplo n.º 25
0
 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));
 }
Exemplo n.º 26
0
 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];
 }
Exemplo n.º 27
0
 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);
 }
Exemplo n.º 28
0
 public function initPermissions()
 {
     foreach ($this->config->get('groups') as $name => $groupData) {
         $perms = [];
         foreach ($groupData['perms'] as $str) {
             $str = $this->getServer()->getPluginManager()->getPermission($str);
             if ($str instanceof Permission) {
                 $perms[] = $str;
             }
         }
         $this->groups[$name] = new Group($this, $name, $perms, $groupData['entrance'], $groupData['exit'], $groupData['members']);
     }
 }
Exemplo n.º 29
-1
 public function onEnable()
 {
     @mkdir($this->getDataFolder());
     $this->saveDefaultConfig();
     $this->reloadConfig();
     $this->saveResource("config.yml", false);
     $this->config = new Config($this->getDataFolder() . "config.yml");
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $config = $this->config->get("mysql_settings");
     if (!isset($config["host"]) or !isset($config["user"]) or !isset($config["password"]) or !isset($config["database"])) {
         $this->getLogger()->critical("MISSED MYSQL SETTINGS!");
         $this->getLogger()->critical("PLEASE, CHANGE IT IN config.yml");
         $this->getLogger()->critical("PLUGIN: PlayerStats");
         return;
     }
     $this->db = new \mysqli($config["host"], $config["user"], $config["password"], $config["database"], isset($config["port"]) ? $config["port"] : 3306);
     if ($this->db->connect_error) {
         $this->getLogger()->critical("Couldn't connect to MySQL: " . $this->db->connect_error);
         $this->getLogger()->critical("Disabled PlayerStats plugin !");
         $this->getServer()->getPluginManager()->disablePlugin($this->getServer()->getPluginManager()->getPlugin("PlayerStats"));
         return;
     }
     $this->getLogger()->info("Creating query to database...");
     $resource = $this->getResource("mysql.sql");
     $this->db->query(stream_get_contents($resource));
     @fclose($resource);
     $this->getLogger()->info("Done!");
     $this->getLogger()->info("Successfully connected to MySQL server!");
 }
Exemplo n.º 30
-1
 public function loadInventory(Player $player, Inventory $inv)
 {
     $n = trim(strtolower($player->getName()));
     if ($n === "") {
         return false;
     }
     $d = substr($n, 0, 1);
     $path = $this->getDataFolder() . $d . "/" . $n . ".yml";
     if (!is_file($path)) {
         return false;
     }
     $cfg = new Config($path, Config::YAML);
     $yaml = $cfg->getAll();
     if ($this->isGlobal) {
         $ln = "*";
     } else {
         $ln = trim(strtolower($player->getLevel()->getName()));
     }
     if (!isset($yaml[$ln])) {
         return false;
     }
     $inv->clearAll();
     foreach ($yaml[$ln] as $slot => $t) {
         list($id, $dam, $cnt) = explode(":", $t);
         $item = Item::get($id, $dam, $cnt);
         $inv->setItem($slot, $item);
     }
     return true;
 }