public function onEnable() { $this->dbm = null; if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } mc::plugin_init($this, $this->getFile()); $this->getServer()->getPluginManager()->registerEvents($this, $this); $defaults = ["version" => $this->getDescription()->getVersion(), "# settings" => "Configuration settings", "settings" => ["# points" => "award points.", "points" => true, "# rewards" => "award money.", "rewards" => true, "# creative" => "track creative kills.", "creative" => false, "# dynamic-updates" => "Update signs.", "dynamic-updates" => 80, "# reset-on-death" => "Reset counters on death.", "reset-on-death" => false, "# kill-streak" => "Enable kill-streak tracking.", "kill-streak" => false, "# achievements" => "Enable PocketMine achievements", "achievements" => true], "# values" => "configure awards. (1st.money, 2nd.points)", "values" => ["*" => [1, 10], "Player" => [100, 100]], "# formats" => "Sign formats.", "formats" => ["default" => "{sname} {count}", "names" => "{n}.{player}", "scores" => "{count}"], "# backend" => "Use SQLiteMgr or MySqlMgr", "backend" => "SQLiteMgr", "# MySql" => "MySQL settings.", "MySql" => ["host" => "localhost", "user" => "nobody", "password" => "secret", "database" => "KillRateDb", "port" => 3306], "# signs" => "placed signs text.", "signs" => ["[STATS]" => "stats", "[ONLINE TOPS]" => "online-tops", "[RANKINGS]" => "rankings", "[RANKNAMES]" => "rankings-names", "[RANKPOINTS]" => "rankings-points", "[TOPNAMES]" => "online-top-names", "[TOPPOINTS]" => "online-top-points"]]; $this->cfg = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll(); if (version_compare($this->cfg["version"], "1.2.0") < 0) { $this->getLogger()->warning(TextFormat::RED . mc::_("Configuration has been changed")); $this->getLogger()->warning(mc::_("It is recommended to delete old config.yml")); } $backend = __NAMESPACE__ . "\\" . $this->cfg["backend"]; $this->dbm = new $backend($this); if ($this->cfg["backend"] != "SQLiteMgr") { $this->getLogger()->warning(TextFormat::RED . mc::_("Using %1% backend is untested", $this->cfg["backend"])); $this->getLogger()->warning(TextFormat::RED . mc::_("Please report bugs")); } else { $this->getLogger()->info(mc::_("Using %1% as backend", $this->cfg["backend"])); } if (isset($this->cfg["settings"]["rewards"])) { $this->money = MoneyAPI::moneyPlugin($this); if ($this->money) { MoneyAPI::foundMoney($this, $this->money); } else { MoneyAPI::noMoney($this); } } if ($this->cfg["settings"]["dynamic-updates"] && $this->cfg["settings"]["dynamic-updates"] > 0) { $this->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this, [$this, "updateTimer"], []), $this->cfg["settings"]["dynamic-updates"]); } if (MPMU::apiVersion("1.12.0")) { if (MPMU::apiVersion(">1.12.0")) { $this->getLogger()->warning(TextFormat::YELLOW . mc::_("This plugin has not been tested to run on %1%", MPMU::apiVersion())); } $this->api = 12; } else { $this->api = 10; } $this->stats = []; if ($this->cfg["settings"]["achievements"]) { Achievement::add("killer", "First Blood!", []); Achievement::add("serialKiller", "Killer Streak!", ["killer"]); } }
/** * Checks message files and nags the user to submit translations... * * @param Plugin $plugin - owning plugin * @param str $path - output of $plugin->getFile() * @return int|false - false on error or the number of messages loaded */ public static function plugin_init_alt($plugin, $path) { $lang = $plugin->getServer()->getProperty("settings.language"); if (mc::plugin_init($plugin, $path) === false && $lang != "eng") { list($fp, $fill) = [$plugin->getResource("messages/eng.ini"), "English"]; if ($fp === null) { list($fp, $fill) = [$plugin->getResource("messages/messages.ini"), "EMPTY"]; } if ($fp === null) { return false; } file_put_contents($plugin->getDataFolder() . "messages.ini", stream_get_contents($fp) . "\n\"<nagme>\"=\"yes\"\n"); mc::plugin_init($plugin, $path); $plugin->getLogger()->error(TextFormat::RED . "Your selected language \"" . $lang . "\" is not supported"); $plugin->getLogger()->error(TextFormat::YELLOW . "Creating a custom \"messages.ini\" with " . $fill . " strings"); $plugin->getLogger()->error(TextFormat::AQUA . "Please consider translating and submitting a translation"); $plugin->getLogger()->error(TextFormat::AQUA . "to the developer"); $plugin->getLogger()->error(TextFormat::YELLOW . "If you later change your language in \"pocketmine.yml\""); $plugin->getLogger()->error(TextFormat::YELLOW . "make sure you delete this \"messages.ini\""); $plugin->getLogger()->error(TextFormat::YELLOW . "otherwise your changes will not be recognized"); return; } if (mc::_("<nagme>") !== "yes") { return; } // Potentially the language may exists since this was created... $fp = $plugin->getResource("messages/" . $lang . ".ini"); if ($fp === null && $lang != "eng") { $plugin->getLogger()->error(TextFormat::RED . "Your selected language \"" . $lang . "\" is not supported"); $plugin->getLogger()->error(TextFormat::AQUA . "Please consider translating \"messages.ini\""); $plugin->getLogger()->error(TextFormat::AQUA . "and submitting a translation to the developer"); return; } if ($fp !== null) { fclose($fp); } // This language is actually supported... $plugin->getLogger()->error(TextFormat::RED . "Using a supported language: \"" . $lang . "\""); $plugin->getLogger()->error(TextFormat::YELLOW . "Saving/Fixing \"messages.ini\" as"); $plugin->getLogger()->error(TextFormat::YELLOW . "\"messages.bak\"..."); $orig = file_get_contents($plugin->getDataFolder() . "messages.ini"); file_put_contents($plugin->getDataFolder() . "messages.bak", strtr($orig, ["<nagme>" => "<don't nagme>"])); unlink($plugin->getDataFolder() . "messages.ini"); }