public function calcWeather() { $this->weatherTime++; $this->weatherLast++; if ($this->weatherTime >= $this->level->getServer()->weatherChangeTime) { $this->weatherTime = 0; //0晴天1下雨2雷雨3阴天雷 $weather = $this->wea[mt_rand(0, count($this->wea) - 1)]; $this->level->getServer()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this->level, $weather)); if (!$ev->isCancelled()) { return; } else { $this->weatherNow = $ev->getWeather(); $this->strength1 = mt_rand(90000, 110000); $this->strength2 = mt_rand(5000, 30000); $this->changeWeather($this->weatherNow, $this->strength1, $this->strength2); } } if ($this->weatherLast >= $this->level->getServer()->weatherLastTime and $this->level->getServer()->weatherLastTime > 0) { $this->level->getServer()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this->level, 0)); if (!$ev->isCancelled()) { return; } else { $this->weatherNow = $ev->getWeather(); $this->strength1 = 0; $this->strength2 = 0; $this->changeWeather($this->weatherNow, $this->strength1, $this->strength2); } } if ($this->weatherNow > 0 and is_int($this->weatherTime / $this->level->getServer()->lightningTime)) { foreach ($this->level->getPlayers() as $p) { $x = $p->getX() + rand(-100, 100); $y = $p->getY() + rand(20, 50); $z = $p->getZ() + rand(-100, 100); $this->level->addwLighting($x, $y, $z, $p); } } }
public function setWeather(int $wea, int $duration = 12000) { $this->level->getServer()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this->level, $wea, $duration)); if (!$ev->isCancelled()) { $this->weatherNow = $ev->getWeather(); $this->strength1 = mt_rand(90000, 110000); $this->strength2 = mt_rand(30000, 40000); $this->duration = $ev->getDuration(); $this->changeWeather($wea, $this->strength1, $this->strength2); } }
public function setWeather(int $wea, int $duration = 12000) { $this->level->getServer()->getPluginManager()->callEvent($ev = new WeatherChangeEvent($this->level, $wea, $duration)); if (!$ev->isCancelled()) { $this->weatherNow = $ev->getWeather(); $this->strength1 = mt_rand(90000, 110000); //If we're clearing the weather, it doesn't matter what strength values we set $this->strength2 = mt_rand(30000, 40000); $this->duration = $ev->getDuration(); $this->sendWeatherToAll(); } }