예제 #1
0
 public function onEnable()
 {
     $this->saveDefaultConfig();
     self::$data = $this->getConfig()->getAll();
     $path = $this->getDataFolder();
     self::$spawn = (new Config($path . "spawner.yml", Config::YAML))->getAll();
     self::$drops = (new Config($path . "drops.yml", Config::YAML))->getAll();
     /*self::$drops = [
                 Zombie::NETWORK_ID => [
                     #[Item id, Item meta, Count]
                     #example: [Item::FEATHER, 0, "1,10"]
                 ],
                 Creeper::NETWORK_ID => [
     
                 ],
             ];*/
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $this->getServer()->getLogger()->info(TextFormat::GOLD . "[EntityManager]Plugin has been enabled");
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new SpawnEntityTask($this), $this->getData("spawn.tick", 100));
     if ($this->getData("autoclear.turn-on", true)) {
         $this->getServer()->getScheduler()->scheduleRepeatingTask(new AutoClearTask($this), $this->getData("autoclear.tick", 6000));
     }
 }
예제 #2
0
 public function onEnable()
 {
     $path = $this->getServer()->getDataPath() . "plugins/EntityManager/";
     if (!is_dir($path)) {
         mkdir($path);
     }
     $getData = function ($ar, $key, $default) {
         $vars = explode(".", $key);
         $base = array_shift($vars);
         if (!isset($ar[$base])) {
             return $default;
         }
         $base = $ar[$base];
         while (count($vars) > 0) {
             $baseKey = array_shift($vars);
             if (!is_array($base) or !isset($base[$baseKey])) {
                 return $default;
             }
             $base = $base[$baseKey];
         }
         return $base;
     };
     $data = [];
     if (file_exists($path . "config.yml")) {
         $data = yaml_parse($this->yaml($path . "config.yml"));
     }
     self::$data = ["entity" => ["maximum" => $getData($data, "entity.maximum", 50), "explode" => $getData($data, "entity.explode", true)], "spawn" => ["rand" => $getData($data, "spawn.rand", "1/5"), "tick" => $getData($data, "spawn.tick", 150)], "autospawn" => ["turn-on" => $getData($data, "autospawn.turn-on", $getData($data, "spawn.auto", true)), "radius" => $getData($data, "autospawn.radius", $getData($data, "spawn.radius", 25))]];
     file_put_contents($path . "config.yml", yaml_emit(self::$data, YAML_UTF8_ENCODING));
     if (file_exists($path . "SpawnerData.yml")) {
         self::$spawn = yaml_parse($this->yaml($path . "SpawnerData.yml"));
         unlink($path . "SpawnerData.yml");
     } elseif (file_exists($path . "spawner.yml")) {
         self::$spawn = yaml_parse($this->yaml($path . "spawner.yml"));
     } else {
         self::$spawn = [];
         file_put_contents($path . "spawner.yml", yaml_emit([], YAML_UTF8_ENCODING));
     }
     if (file_exists($path . "drops.yml")) {
         self::$drops = yaml_parse($this->yaml($path . "drops.yml"));
     } else {
         self::$drops = [Zombie::NETWORK_ID => [], Creeper::NETWORK_ID => []];
         file_put_contents($path . "drops.yml", yaml_emit([], YAML_UTF8_ENCODING));
     }
     foreach (self::$knownEntities as $id => $name) {
         if (!is_numeric($id)) {
             continue;
         }
         $item = Item::get(Item::SPAWN_EGG, $id);
         if (!Item::isCreativeItem($item)) {
             Item::addCreativeItem($item);
         }
     }
     $this->getServer()->getPluginManager()->registerEvents($this, $this);
     $this->getServer()->getLogger()->info(TextFormat::GOLD . "[EntityManager]Plugin has been enabled");
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new UpdateEntityTask($this), 1);
     $this->getServer()->getScheduler()->scheduleRepeatingTask(new SpawnEntityTask($this), $this->getData("spawn.tick"));
 }