public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args)
 {
     if ($scmd != "banitem" && $scmd != "unbanitem") {
         return false;
     }
     if (count($args) == 0) {
         $ids = $this->owner->getCfg($world, "banitem", []);
         if (count($ids) == 0) {
             $c->sendMessage(mc::_("[WP] No banned items in %1%", $world));
         } else {
             $ln = mc::_("[WP] Items(%1%):", count($ids));
             $q = "";
             foreach ($ids as $id => $n) {
                 $ln .= "{$q} {$n}({$id})";
                 $q = ",";
             }
             $c->sendMessage($ln);
         }
         return true;
     }
     $cc = 0;
     echo __METHOD__ . "," . __LINE__ . "\n";
     //##DEBUG
     $ids = $this->owner->getCfg($world, "banitem", []);
     if ($scmd == "unbanitem") {
         foreach ($args as $i) {
             $item = Item::fromString($i);
             if (isset($ids[$item->getId()])) {
                 unset($ids[$item->getId()]);
                 ++$cc;
             }
         }
     } elseif ($scmd == "banitem") {
         foreach ($args as $i) {
             $item = Item::fromString($i);
             if (isset($ids[$item->getId()])) {
                 continue;
             }
             $ids[$item->getId()] = MPMU::itemName($item);
             ++$cc;
         }
     } else {
         return false;
     }
     if (!$cc) {
         $c->sendMessage(mc::_("No items updated"));
         return true;
     }
     if (count($ids)) {
         $this->owner->setCfg($world, "banitem", $ids);
     } else {
         $this->owner->unsetCfg($world, "banitem");
     }
     $c->sendMessage(mc::_("Items changed: %1%", $cc));
     return true;
 }
 public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args)
 {
     if ($scmd != "breakable" && $scmd != "unbreakable") {
         return false;
     }
     if (count($args) == 0) {
         $ids = $this->owner->getCfg($world, "unbreakable", []);
         if (count($ids) == 0) {
             $c->sendMessage(mc::_("[WP] No unbreakable blocks in %1%", $world));
         } else {
             $ln = mc::_("[WP] Blocks(%1%):", count($ids));
             $q = "";
             foreach ($ids as $id => $n) {
                 $ln .= "{$q} {$n}({$id})";
                 $q = ",";
             }
             $c->sendMessage($ln);
         }
         return true;
     }
     $cc = 0;
     $ids = $this->owner->getCfg($world, "unbreakable", []);
     if ($scmd == "breakable") {
         foreach ($args as $i) {
             $item = Item::fromString($i);
             if (isset($ids[$item->getId()])) {
                 unset($ids[$item->getId()]);
                 ++$cc;
             }
         }
     } elseif ($scmd == "unbreakable") {
         foreach ($args as $i) {
             $item = Item::fromString($i);
             if (isset($ids[$item->getId()])) {
                 continue;
             }
             $ids[$item->getId()] = MPMU::itemName($item);
             ++$cc;
         }
     } else {
         return false;
     }
     if (!$cc) {
         $c->sendMessage(mc::_("No blocks updated"));
         return true;
     }
     if (count($ids)) {
         $this->owner->setCfg($world, "unbreakable", $ids);
     } else {
         $this->owner->unsetCfg($world, "unbreakable");
     }
     $c->sendMessage(mc::_("Blocks changed: %1%", $cc));
     return true;
 }
 /**
  * @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);
 }
Exemple #4
0
 public function msg($pl, $txt)
 {
     if (MPMU::apiVersion("1.12.0")) {
         $pl->sendTip($txt);
         return;
     }
     list($time, $otxt) = $this->getState("spam", $pl, [0, ""]);
     if (time() - $time < self::SPAM_DELAY && $otxt == $txt) {
         return;
     }
     $this->setState("spam", $pl, [time(), $txt]);
     $pl->sendMessage($txt);
 }
 private function wpDetails(CommandSender $c, $world, $pageNumber)
 {
     if (!$this->owner->getServer()->isLevelGenerated($world)) {
         $c->sendMessage(mc::_("World %1% does not exist", $world));
         return;
     }
     $f = $this->owner->getServer()->getDataPath() . "worlds/{$world}/wpcfg.yml";
     if (!is_file($f)) {
         $c->sendMessage(mc::_("World %1% is not protected", $world));
         return;
     }
     $wcfg = (new Config($f, Config::YAML))->getAll();
     $txt = [mc::_("Details for %1%", $world)];
     if (isset($wcfg["protect"])) {
         $txt[] = TextFormat::AQUA . mc::_("Protect:  ") . TextFormat::WHITE . $wcfg["protect"];
     }
     if (isset($wcfg["max-players"])) {
         $txt[] = TextFormat::AQUA . mc::_("Max Players:  ") . TextFormat::WHITE . $wcfg["max-players"];
     }
     if (isset($wcfg["gamemode"])) {
         $txt[] = TextFormat::AQUA . mc::_("Gamemode:  ") . TextFormat::WHITE . MPMU::gamemodeStr($wcfg["gamemode"]);
     }
     if (isset($wcfg["pvp"])) {
         if ($wcfg["pvp"] === true) {
             $txt[] = TextFormat::AQUA . mc::_("PvP: ") . TextFormat::RED . mc::_("on");
         } elseif ($wcfg["pvp"] === false) {
             $txt[] = TextFormat::AQUA . mc::_("PvP: ") . TextFormat::GREEN . mc::_("off");
         } else {
             $txt[] = TextFormat::AQUA . mc::_("PvP: ") . TextFormat::YELLOW . mc::_("spawn-off");
         }
     }
     if (isset($wcfg["no-explode"])) {
         if ($wcfg["no-explode"] === "off") {
             $txt[] = TextFormat::AQUA . mc::_("NoExplode: ") . TextFormat::RED . mc::_("off");
         } elseif ($wcfg["no-explode"] === "world") {
             $txt[] = TextFormat::AQUA . mc::_("NoExplode: ") . TextFormat::GREEN . mc::_("world");
         } else {
             $txt[] = TextFormat::AQUA . mc::_("NoExplode: ") . TextFormat::YELLOW . mc::_("spawn");
         }
     }
     if (isset($wcfg["border"])) {
         $txt[] = TextFormat::AQUA . mc::_("Border: ") . TextFormat::WHITE . implode(",", $wcfg["border"]);
     }
     if (isset($wcfg["auth"])) {
         $txt[] = TextFormat::AQUA . mc::_("Auth List(%1%): ", count($wcfg["auth"])) . TextFormat::WHITE . implode(",", $wcfg["auth"]);
     }
     if (isset($wcfg["unbreakable"])) {
         $txt[] = TextFormat::AQUA . mc::_("Unbreakable(%1%): ", count($wcfg["unbreakable"])) . TextFormat::WHITE . implode(",", $wcfg["unbreakable"]);
     }
     if (isset($wcfg["banitem"])) {
         $txt[] = TextFormat::AQUA . mc::_("Banned(%1%): ", count($wcfg["banitem"])) . TextFormat::WHITE . implode(",", $wcfg["banitem"]);
     }
     if (isset($wcfg["motd"])) {
         $txt[] = mc::_("MOTD:");
         if (is_array($wcfg["motd"])) {
             foreach ($wcfg["motd"] as $ln) {
                 $txt[] = TextFormat::BLUE . "  " . $ln . TextFormat::RESET;
             }
         } else {
             $txt[] = TextFormat::BLUE . "  " . $wcfg["motd"];
         }
     }
     return $this->paginateText($c, $pageNumber, $txt);
 }