Exemplo n.º 1
0
 public function onEnable()
 {
     $this->dbm = null;
     if (!is_dir($this->getDataFolder())) {
         mkdir($this->getDataFolder());
     }
     mc2::plugin_init_alt($this, $this->getFile());
     $this->api = new KillRateAPI($this);
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $defaults = ["version" => $this->getDescription()->getVersion(), "features" => ["# signs" => "enable/disable signs", "signs" => true, "# ranks" => "Enable support for RankUp plugin", "ranks" => false, "# achievements" => "Enable PocketMine achievements", "achievements" => true, "# kill-streak" => "Enable kill-streak tracking.", "kill-streak" => false, "# rewards" => "award money.", "rewards" => true], "settings" => ["# points" => "award points.", "points" => true, "# min-kills" => "Minimum number of kills before declaring a kill-streak", "min-kills" => 7, "# reset-on-death" => "Reset counters on death.", "reset-on-death" => false, "# creative" => "track creative kills.", "creative" => false, "# dynamic-updates" => "Update signs.", "dynamic-updates" => 80, "# default-rank" => "Default rank (when resetting ranks)", "default-rank" => false], "values" => ["<Example>" => ["money", "points"], "*" => [1, 10], "Player" => [100, 100]], "formats" => ["default" => "{sname} {count}", "names" => "{n}.{player}", "scores" => "{count}"], "database" => ["# backend" => "Use SQLiteMgr or MySqlMgr", "backend" => "SQLiteMgr", "# MySql" => "MySQL settings.", "MySql" => ["host" => "localhost", "user" => "nobody", "password" => "secret", "database" => "KillRateDb", "port" => 3306]], "signs" => ["[STATS]" => "stats", "[ONLINE TOPS]" => "online-tops", "[RANKINGS]" => "rankings", "[RANKNAMES]" => "rankings-names", "[RANKPOINTS]" => "rankings-points", "[TOPNAMES]" => "online-top-names", "[TOPPOINTS]" => "online-top-points"]];
     $cfg = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll();
     if (version_compare($cfg["version"], "2.1") < 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__ . "\\" . $cfg["database"]["backend"];
     $this->dbm = new $backend($this, $cfg["database"]);
     $this->getLogger()->info(mc::_("Using %1% as backend", $cfg["database"]["backend"]));
     $this->money = null;
     if (isset($cfg["features"]["rewards"])) {
         $this->money = MoneyAPI::moneyPlugin($this);
         if ($this->money) {
             MoneyAPI::foundMoney($this, $this->money);
         } else {
             MoneyAPI::noMoney($this);
             $this->money = null;
         }
     }
     $this->signmgr = $cfg["features"]["signs"] ? new SignMgr($this, $cfg) : null;
     $this->achievements = new AchievementsGiver($this, $cfg["features"]["achievements"]);
     $this->ranks = new RankMgr($this, $cfg["features"]["ranks"], $cfg["settings"]);
     $this->settings = $cfg["settings"];
     $this->prizes = $cfg["values"];
     $this->kstreak = new KillStreak($this, $cfg["features"]["kill-streak"], $cfg["settings"], $this->money);
 }
Exemplo n.º 2
0
 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"]);
     }
 }