/** * @param Level $level */ public function removeShield(Level $level) { $shield = $this->shields[strtolower($level->getName())]; if (isset($shield)) { if ($shield->isEnabled()) { $shield->setEnabled(false); $this->plugin->getServer()->getLogger()->info("Unloaded shield for level \"" . $level->getName() . "\"."); } } }
/** * @param PlayerItemHeldEvent $event * @priority HIGHEST * @ignoreCancelled true */ public function onPlayerItemHeld(PlayerItemHeldEvent $event) { if ($this->plugin->getStorage()->getShield($event->getPlayer()->getLevel())->isItemBanned($event->getItem())) { $event->setCancelled(true); $event->getPlayer()->sendTip($this->plugin->getConfig()->get("itemNotAllowed")); } }
/** * @param CommandSender $sender * @param string $label * @param string[] $args * @return bool */ public function execute(CommandSender $sender, $label, array $args) { if (!$this->testPermission($sender)) { return false; } if (isset($args[0])) { $storage = $this->plugin->getStorage(); switch (strtolower($args[0])) { case "help": $this->sendCommandHelp($sender); return true; case "l": case "load": if (isset($args[1])) { if ($level = $sender->getServer()->getLevelByName($args[1])) { $storage->addShield($level); $sender->sendMessage(TextFormat::GREEN . "Loaded shield for level \"" . $args[1] . "\"."); } else { $sender->sendMessage(TextFormat::RED . "That shield couldn't be found."); } } return true; case "u": case "unload": if (isset($args[1])) { if ($level = $sender->getServer()->getLevelByName($args[1])) { $storage->removeShield($level); $sender->sendMessage(TextFormat::GREEN . "Unloaded shield for level \"" . $args[1] . "\"."); } else { $sender->sendMessage(TextFormat::RED . "That shield couldn't be found."); } } return true; default: $sender->sendMessage("/globalshield <sub-command> [parameters]"); return false; } } else { $this->sendCommandHelp($sender); return false; } }