コード例 #1
0
ファイル: Main.php プロジェクト: DWWf/pocketmine-plugins
 public function onEnable()
 {
     if (!is_dir($this->getDataFolder())) {
         mkdir($this->getDataFolder());
     }
     mc::plugin_init($this, $this->getFile());
     $wp = $this->getServer()->getPluginManager()->getPlugin("WorldProtect");
     if ($wp !== null && version_compare($wp->getDescription()->getVersion(), "2.1.0") < 0) {
         $this->getLogger()->warning(TextFormat::RED . mc::_("This version of SignWarp requires"));
         $this->getLogger()->warning(TextFormat::RED . mc::_("at least version 2.1.0 of WorldProtect"));
         $this->getLogger()->warning(TextFormat::RED . mc::_("Only version %1% available", $wp->getDescription()->getVersion()));
         throw new \RuntimeException("Runtime checks failed");
         return;
     }
     $defaults = ["version" => $this->getDescription()->getVersion(), "# settings" => "configurable variables", "settings" => ["# dynamic updates" => "Signs will be udpated with the number of players in a world", "dynamic-updates" => true, "# xyz.cmd" => "If true, the **xyz** command will be available", "xyz.cmd" => true], "# text" => "Text displayed on the different signs", "text" => ["# transfer" => "Fast transfer signs", "transfer" => ["[TRANSFER]"], "# world" => "World teleport signs", "world" => ["[WORLD]"], "# warp" => "Local world teleport signs", "warp" => ["[WARP]", "[SWARP]"], "# players" => "Text to use when displaying player counts", "players" => ["Players:"]]];
     $cfg = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll();
     if ($this->getServer()->getPluginManager()->getPlugin("FastTransfer")) {
         $this->getLogger()->info(TextFormat::GREEN . mc::_("Enabling FastTransfer support"));
     } else {
         $this->getLogger()->warning(TextFormat::BLUE . mc::_("Disabling FastTransfer support"));
         $cfg["text"]["transfer"] = [];
     }
     $this->text = ["sign" => []];
     foreach (["world", "warp", "transfer"] as $n) {
         $thist->text[$n] = [];
         foreach ($cfg["text"][$n] as $m) {
             $this->text[$n][$m] = $m;
             $this->text["sign"][$m] = $m;
         }
     }
     $this->text["players"] = $cfg["text"]["players"];
     if ($cfg["settings"]["xyz.cmd"]) {
         $newCmd = new PluginCommand("xyz", $this);
         $newCmd->setDescription(mc::_("Returns x,y,z coordinates"));
         $newCmd->setUsage(mc::_("/xyz"));
         $newCmd->setPermission("signwarp.cmd.xyz");
         $cmdMap = $this->getServer()->getCommandMap();
         $cmdMap->registerAll($this->getDescription()->getName(), [$newCmd]);
         $this->getLogger()->info(TextFormat::GREEN . mc::_("enabled /xyz command"));
     }
     if ($cfg["settings"]["dynamic-updates"]) {
         $this->getLogger()->info(TextFormat::GREEN . mc::_("dynamic-updates: ON"));
         $tt = new PluginCallbackTask($this, [$this, "updateSigns"], []);
         $this->getServer()->getScheduler()->scheduleRepeatingTask($tt, 40);
     } else {
         $this->getLogger()->info(TextFormat::YELLOW . mc::_("dynamic-updates: OFF"));
     }
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
 }