public function onEnable() { @mkdir($this->getDataFolder()); $this->createConfig(); $this->convertData(); switch (strtolower($this->config->get("provider"))) { case "yaml": $this->provider = new YamlProvider($this->getDataFolder() . "Money.yml"); break; case "mysql": $this->provider = new MySQLProvider($this->mysql->getAll()); break; default: $this->getLogger()->critical("Invalid provider was given. Aborting..."); return; } $this->getLogger()->notice("Provider was set to: " . $this->provider->getName()); $this->scanResources(); if (!is_file($this->getDataFolder() . "PlayerLang.dat")) { file_put_contents($this->getDataFolder() . "PlayerLang.dat", serialize([])); } $this->playerLang = unserialize(file_get_contents($this->getDataFolder() . "PlayerLang.dat")); if (!isset($this->playerLang["console"])) { $this->getLangFile(); } $commands = ["setmoney" => "onebone\\economyapi\\commands\\SetMoneyCommand", "seemoney" => "onebone\\economyapi\\commands\\SeeMoneyCommand", "mymoney" => "onebone\\economyapi\\commands\\MyMoneyCommand", "pay" => "onebone\\economyapi\\commands\\PayCommand", "givemoney" => "onebone\\economyapi\\commands\\GiveMoneyCommand", "topmoney" => "onebone\\economyapi\\commands\\TopMoneyCommand", "setlang" => "onebone\\economyapi\\commands\\SetLangCommand", "takemoney" => "onebone\\economyapi\\commands\\TakeMoneyCommand", "mystatus" => "onebone\\economyapi\\commands\\MyStatusCommand"]; $commandMap = $this->getServer()->getCommandMap(); foreach ($commands as $key => $command) { foreach ($this->command->get($key) as $cmd) { $commandMap->register("economyapi", new $command($this, $cmd)); } } $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->monetaryUnit = $this->config->get("monetary-unit"); $time = $this->config->get("auto-save-interval"); if (is_numeric($time)) { $interval = $time * 1200; if ($interval > 0) { $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new SaveTask($this), $interval, $interval); $this->getLogger()->notice("Auto save has been set to interval : " . $time . " min(s)"); } } $update_check = new Config($this->getDataFolder() . "update-check.yml", Config::YAML, yaml_parse($this->readResource("update-check.yml"))); if ($update_check->get("check-update")) { try { $this->getLogger()->info("Checking for updates... It may be take some while."); $host = $update_check->get("update-host"); $url = "http://" . $host . "/?package_version=" . self::PACKAGE_VERSION . "&version=" . $this->getDescription()->getVersion() . "&lang=" . $this->getServer()->getLanguage()->getName(); $desc = json_decode(Utils::getUrl($url), true); if ($desc["update-available"]) { $this->getLogger()->notice("New version of EconomyS v" . $desc["new-version"] . " was released. You can download file from " . $desc["download-address"]); } if ($desc["notice"] !== "") { $this->getLogger()->notice($desc["notice"]); } } catch (\Exception $e) { $this->getLogger()->warning("An exception during check-update has been detected."); } } }
private function initialize() { if ($this->getConfig()->get("check-update")) { $this->checkUpdate(); } switch (strtolower($this->getConfig()->get("provider"))) { case "yaml": $this->provider = new YamlProvider($this->getDataFolder() . "Money.yml"); break; case "mysql": $this->provider = new MySQLProvider($this->getConfig()->get("provider-settings")); break; default: $this->getLogger()->critical("Invalid database was given."); return false; } $this->initializeLanguage(); $this->getLogger()->notice("Database provider was set to: " . $this->provider->getName()); $this->registerCommands(); }