コード例 #1
0
ファイル: Main.php プロジェクト: AvivShopen/bad-plugins
 public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
 {
     if ($cmd->getName() != "mobster") {
         return false;
     }
     if (isset($args[0]) && strtolower($args[0]) == "spawn") {
         array_shift($args);
     }
     if (!$sender->hasPermission("mobsters.cmd.spawn")) {
         $sender->sendMessage("You are not allowed to do that!");
         return true;
     }
     if (count($args) != 2) {
         return false;
     }
     $mob = strtolower(array_shift($args));
     if (($class = $this->mobClass($mob)) === null) {
         $sender->sendMessage("Unknown mob class: {$mob}");
         return true;
     }
     $location = explode(":", array_shift($args), 2);
     if (count($location) < 2) {
         if ($sender instanceof Player) {
             $level = $sender->getLevel();
         } else {
             $level = $this->getServer()->getDefaultLevel();
         }
     } else {
         $level = $this->getServer()->getLevelByName($location[1]);
         if ($level === null) {
             $sender->sendMessage("Unknown level: " . $location[1]);
             return true;
         }
     }
     $location = array_map("floatval", explode(",", $location[0], 5));
     if (count($location) < 3) {
         $sender->sendMessage("Invalid location specified");
         return false;
     }
     $location = new Location(...$location);
     $location->setLevel($level);
     $this->spawnMob($class, $location);
     $sender->sendMessage("Spawned {$mob}");
     return true;
 }