/** * @param EntityExplodeEvent $event * * @priority HIGH * @ignoreCancelled true */ public function onEntityExplode(EntityExplodeEvent $event) { if ($this->plugin->getConfig()->get("protect-from-explosion", true) != true) { return; } $radius = $this->plugin->getConfig()->get("explosion-radius", 8); foreach ($this->plugin->getAllZones() as $zone) { if ($zone->isOnRadius($event->getPosition(), $radius)) { $owner = $this->plugin->getServer()->getPlayer($zone->getOwner()); if ($owner instanceof Player) { $owner->sendMessage('[iZone] Something explode near zone: ' . $zone->getName()); } $event->setCancelled(true); break; } } return; }
public function __construct(iZone $plugin) { $this->_plugin = $plugin; $config = $plugin->getConfig()->get("dataProviderSettings", []); if (!isset($config["host"]) or !isset($config["user"]) or !isset($config["password"]) or !isset($config["database"])) { $this->_plugin->getLogger()->critical("Invalid MySQL settings"); $this->_plugin->setDataProvider(new DummyProvider($this->_plugin)); return; } $this->database = new \mysqli($config["host"], $config["user"], $config["password"], $config["database"], isset($config["port"]) ? $config["port"] : 3306); if ($this->database->connect_error) { $this->_plugin->getLogger()->critical("Couldn't connect to MySQL: " . $this->database->connect_error); $this->_plugin->setDataProvider(new DummyProvider($this->_plugin)); return; } $resource = $this->_plugin->getResource("mysqli.sql"); $this->database->query(stream_get_contents($resource)); fclose($resource); $this->_plugin->getServer()->getScheduler()->scheduleRepeatingTask(new MySQLiTask($this->_plugin, $this->database), 600); //Each 30 seconds $this->_plugin->getLogger()->info("Connected to MySQL server"); }