public function onBlockPlace(BlockPlaceEvent $ev) { if ($ev->isCancelled()) { return; } $pl = $ev->getPlayer(); if ($this->checkBlockPlaceBreak($pl)) { return; } $this->owner->msg($pl, mc::_("You are not allowed to do that here")); $ev->setCancelled(); }
/** * @priority HIGHEST */ public function onTeleport(EntityTeleportEvent $ev) { //echo __METHOD__.",".__LINE__."\n"; //##DEBUG if ($ev->isCancelled()) { return; } $pl = $ev->getEntity(); if (!$pl instanceof Player) { return; } if ($pl->hasPermission("wp.cmd.gm.exempt")) { return; } //echo __METHOD__.",".__LINE__."\n"; //##DEBUG $world = $ev->getTo()->getLevel(); if (!$world) { $world = $pl->getLevel(); } $world = $world->getName(); $gm = $this->owner->getCfg($world, "gamemode", null); if ($gm === null) { $gm = $this->owner->getServer()->getGamemode(); } if ($pl->getGamemode() == $gm) { return; } $pl->sendMessage(mc::_("Changing gamemode to %1%", MPMU::gamemodeStr($gm))); $pl->setGamemode($gm); }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args) { if ($scmd != "motd") { return false; } if (count($args) == 0) { $this->owner->unsetCfg($world, "motd"); $c->sendMessage(mc::_("[WP] motd for %1% removed", $world)); return true; } $this->owner->setCfg($world, "motd", implode(" ", $args)); $c->sendMessage(mc::_("[WP] motd for %1% updated", $world)); return true; }
public function onConsume(PlayerItemConsumeEvent $ev) { if ($ev->isCancelled()) { return; } $pl = $ev->getPlayer(); if ($pl->hasPermission("wp.banitem.exempt")) { return; } $world = $pl->getLevel()->getName(); if (!isset($this->wcfg[$world])) { return; } $item = $ev->getItem(); if (!isset($this->wcfg[$world][$item->getId()])) { return; } $pl->sendMessage(mc::_("You can not use that item here!")); $ev->setCancelled(); }
public function onTeleport(EntityTeleportEvent $ev) { if ($ev->isCancelled()) { return; } $pl = $ev->getEntity(); if (!$pl instanceof Player) { return; } $to = clone $ev->getTo(); if (!$to) { return; } // This should never happen! if ($to->getLevel()) { $world = $to->getLevel()->getName(); } else { $from = $ev->getFrom(); if (!$from) { return; } // OK, this would be weird... if (!$from->getLevel()) { return; } // Can't determine the level at all! $world = $from->getLevel()->getName(); } //echo __METHOD__.",".__LINE__."world=$world\n"; //##DEBUG if ($this->checkMove($world, $to->getX(), $to->getZ())) { return; } $this->owner->msg($pl, mc::_("You are teleporting outside the world")); $ev->setCancelled(); }
public function onExplode(EntityExplodeEvent $ev) { //echo __METHOD__.",".__LINE__."\n"; if ($ev->isCancelled()) { return; } $et = $ev->getEntity(); $world = $et->getLevel()->getName(); if (!isset($this->wcfg[$world])) { return; } if ($this->wcfg[$world] == "spawn") { $sp = $et->getLevel()->getSpawnLocation(); $dist = $sp->distance($et); if ($dist > $this->owner->getServer()->getSpawnRadius()) { return; } } $ev->setCancelled(); $this->owner->getLogger()->notice(TextFormat::RED . mc::_("Explosion was stopped in %1%", $world)); }
public function onPvP(EntityDamageEvent $ev) { if ($ev->isCancelled()) { return; } if (!$ev instanceof EntityDamageByEntityEvent) { return; } if (!(($pl = $ev->getEntity()) instanceof Player && $ev->getDamager() instanceof Player)) { return; } $world = $pl->getLevel()->getName(); if (!isset($this->wcfg[$world])) { return; } if ($this->wcfg[$world] !== false) { $sp = $pl->getLevel()->getSpawnLocation(); $dist = $sp->distance($pl); if ($dist > $this->owner->getServer()->getSpawnRadius()) { return; } } $this->owner->msg($ev->getDamager(), mc::_("You are not allowed to do that here")); $ev->setCancelled(); }
public function onTeleport(EntityTeleportEvent $ev) { //echo __METHOD__.",".__LINE__."\n"; //##DEBUG if ($ev->isCancelled()) { return; } $et = $ev->getEntity(); if (!$et instanceof Player) { return; } $from = $ev->getFrom()->getLevel(); $to = $ev->getTo()->getLevel(); if (!$from) { // THIS SHOULDN'T HAPPEN! return; } if (!$to) { // Somebody did not initialize the level properly! // But we return because they do not intent to change worlds return; } $from = $from->getName(); $to = $to->getName(); //echo "FROM:$from TO:$to\n";//##DEBUG if ($from == $to) { return; } $max = $this->getCfg($to, 0); if ($max == 0) { return; } $np = count($this->owner->getServer()->getLevelByName($to)->getPlayers()); if ($np >= $max) { $ev->setCancelled(); $et->sendMessage(mc::_("Unable to teleport to %1%\nWorld is full", $to)); $this->owner->getLogger()->notice(mc::_("%1% is FULL", $to)); } }
public function isAuth($c, $world) { if (!$c instanceof Player) { return true; } if (!isset($this->wcfg[$world])) { return true; } if (!isset($this->wcfg[$world]["auth"])) { return true; } if (!count($this->wcfg[$world]["auth"])) { return true; } echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG $iusr = strtolower($c->getName()); if (isset($this->wcfg[$world][$iusr])) { return true; } $c->sendMessage(mc::_("[WP] You are not allowed to do this")); return false; }
public function onBlockBreak(BlockBreakEvent $ev) { if ($ev->isCancelled()) { return; } $bl = $ev->getBlock(); $world = $bl->getLevel()->getName(); if (!isset($this->wcfg[$world])) { return; } if (!isset($this->wcfg[$world][$bl->getId()])) { return; } $pl = $ev->getPlayer(); $pl->sendMessage(mc::_("It can not be broken!")); $ev->setCancelled(); }
private function wpList(CommandSender $c, $pageNumber) { $dir = $this->owner->getServer()->getDataPath() . "worlds/"; if (!is_dir($dir)) { $c->sendMessage(mc::_("[WP] Missing path %1%", $dir)); return true; } $txt = []; $dh = opendir($dir); if (!$dh) { return false; } $cnt = 0; while (($world = readdir($dh)) !== false) { if ($world == '.' || $world == '..') { continue; } if (!$this->owner->getServer()->isLevelGenerated($world)) { continue; } $f = "{$dir}{$world}/wpcfg.yml"; if (is_file($f)) { $attrs = $this->attrList((new Config($f, Config::YAML))->getAll()); } else { $attrs = []; } $ln = "- " . TextFormat::YELLOW . $world; if (count($attrs)) { $ln .= TextFormat::AQUA . " (" . implode(", ", $attrs) . ")"; } $txt[] = $ln; ++$cnt; } if (!count($ln)) { $c->sendMessage(mc::_("Nothing to report")); return true; } array_unshift($txt, mc::_("Worlds: %1%", $cnt)); return $this->paginateText($c, $pageNumber, $txt); }
/** * @priority LOWEST */ public function onCmd(PlayerCommandPreprocessEvent $ev) { echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG if ($ev->isCancelled()) { return; } $pl = $ev->getPlayer(); $world = $pl->getLevel()->getName(); if (!isset($this->wcfg[$world])) { return; } $cmdline = trim($ev->getMessage()); if ($cmdline == "") { return; } $cmdline = preg_split('/\\s+/', $cmdline); $cmd = strtolower($cmdline[0]); if (!isset($this->wcfg[$world][$cmd])) { return; } echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG $pl->sendMessage(mc::_("That command is banned here!")); $ev->setCancelled(); }