Пример #1
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $params)
 {
     switch ($command->getName()) {
         case "npc":
             switch (strtolower(array_shift($params))) {
                 case "create":
                 case "c":
                     if (!$sender instanceof Player) {
                         $sender->sendMessage(TextFormat::RED . "Please run this command in-game.");
                         return true;
                     }
                     if (!$sender->hasPermission("npc.command.npc.create")) {
                         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
                         return true;
                     }
                     $name = implode(" ", $params);
                     if (trim($name) === "") {
                         $sender->sendMessage(TextFormat::RED . "Usage: /npc create <name>");
                         return true;
                     }
                     $location = new Location($sender->getX(), $sender->getY(), $sender->getZ(), -1, -1, $sender->getLevel());
                     $npc = new NPC($this, clone $location, $name, $sender->getSkinData(), $sender->getSkinId(), $sender->getInventory()->getItemInHand());
                     $this->npc[$npc->getId()] = $npc;
                     foreach ($sender->getLevel()->getPlayers() as $player) {
                         $npc->spawnTo($player);
                     }
                     if ($this->getConfig()->get("save-on-change")) {
                         $this->save();
                     }
                     return true;
                 case "remove":
                 case "r":
                     if (!$sender->hasPermission("npc.command.npc.remove")) {
                         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
                         return true;
                     }
                     $id = array_shift($params);
                     if (!is_numeric($id)) {
                         $sender->sendMessage(TextFormat::RED . "Usage: /npc remove <id>");
                         return true;
                     }
                     foreach ($this->npc as $key => $npc) {
                         if ($id == $npc->getId()) {
                             $npc->remove();
                             unset($this->npc[$key]);
                             $sender->sendMessage("Removed NPC " . TextFormat::AQUA . $npc->getName());
                             if ($this->getConfig()->get("save-on-change")) {
                                 $this->save();
                             }
                             return true;
                         }
                     }
                     $sender->sendMessage("Could not find NPC " . TextFormat::RED . $id);
                     return true;
                 case "list":
                 case "ls":
                 case "l":
                     if (!$sender->hasPermission("npc.command.npc.list")) {
                         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
                         return true;
                     }
                     $page = array_shift($params);
                     if (!is_numeric($page)) {
                         $page = 1;
                     }
                     $max = ceil(count($this->npc) / 5);
                     $page = (int) $page;
                     $page = max(1, min($page, $max));
                     $output = "Showing NPC list (page {$page}/{$max}): \n";
                     $n = 0;
                     foreach ($this->npc as $id => $npc) {
                         $current = (int) ceil(++$n / 5);
                         if ($current === $page) {
                             $output .= "#" . $npc->getId() . " (" . round($npc->x, 2) . ":" . round($npc->y, 2) . ":" . round($npc->z, 2) . ":" . $npc->getLevel()->getName() . "): " . $npc->getName() . "\n";
                         } elseif ($current > $page) {
                             break;
                         }
                     }
                     $output = substr($output, 0, -1);
                     $sender->sendMessage($output);
                     return true;
                 case "message":
                 case "msg":
                 case "m":
                     if (!$sender->hasPermission("npc.command.npc.message")) {
                         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
                         return true;
                     }
                     $message = trim(implode(" ", $params));
                     $this->msgQueue[$sender->getName()] = $message;
                     $sender->sendMessage("Touch NPC you want to set message.");
                     if ($this->getConfig()->get("save-on-change")) {
                         $this->save();
                     }
                     return true;
                 case "command":
                 case "cmd":
                     if (!$sender->hasPermission("npc.command.npc.command")) {
                         $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
                         return true;
                     }
                     $this->cmdQueue[$sender->getName()] = trim(implode(" ", $params));
                     $sender->sendMessage("Touch NPC you want to set command.");
                     return true;
             }
     }
     return false;
 }
Пример #2
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch (strtolower($command->getName())) {
         case 'nothing':
             return true;
             break;
         case 'rca':
             if (count($args) < 2) {
                 $sender->sendMessage("Please enter a player and a command.");
             }
             $player = $this->getServer()->getPlayer(array_shift($args));
             if (!($player === null)) {
                 $this->getServer()->dispatchCommand($player, trim(implode(" ", $args)));
             } else {
                 $sender->sendMessage(TextFormat::RED . "Player not found.");
             }
             return true;
             break;
         case "slapper":
             if ($sender instanceof Player) {
                 if (!isset($args[0])) {
                     if ($sender->hasPermission("slapper.command") || $sender->hasPermission("slapper")) {
                         $sender->sendMessage($this->prefix . "Please type '/slapper help'.");
                         return true;
                     } else {
                         $sender->sendMessage($this->noperm);
                         return true;
                     }
                 }
                 $arg = array_shift($args);
                 switch ($arg) {
                     case "id":
                         if ($sender->hasPermission("slapper.id") || $sender->hasPermission("slapper")) {
                             $this->idSessions[$sender->getName()] = true;
                             $sender->sendMessage($this->prefix . "Hit an entity to get its ID!");
                             return true;
                         } else {
                             $sender->sendMessage($this->noperm);
                         }
                         return true;
                         break;
                     case "fixall":
                     case "updateall":
                     case "migrateall":
                         $server = $this->getServer();
                         $count = 0;
                         foreach ($server->getLevels() as $level) {
                             foreach ($level->getEntities() as $entity) {
                                 if ($entity instanceof SlapperEntity && $entity instanceof Entity) {
                                     $count++;
                                     if (!isset($entity->namedtag->Commands)) {
                                         $entity->namedtag->Commands = new Compound("Commands", []);
                                     }
                                     $oldCmds = $this->getConfig()->get($entity->getName());
                                     if ($oldCmds) {
                                         foreach ($oldCmds as $oldCmd) {
                                             $entity->namedtag->Commands[$oldCmd] = new String($oldCmd, $oldCmd);
                                         }
                                     }
                                 }
                                 if ($entity instanceof SlapperHuman) {
                                     if ($entity->getSkinName() === "") {
                                         $entity->setSkin($entity->getSkinData(), "Standard_Custom");
                                         $entity->despawnFromAll();
                                         $entity->spawnToAll();
                                     }
                                 }
                             }
                         }
                         $sender->sendMessage($this->prefix . "Updated " . $count . " Slapper entities.");
                         return true;
                         break;
                     case "version":
                         if ($sender->hasPermission("slapper.version") || $sender->hasPermission("slapper")) {
                             $desc = $this->getDescription();
                             $sender->sendMessage($this->prefix . TextFormat::BLUE . $desc->getName() . " " . $desc->getVersion() . " " . TextFormat::GREEN . "by " . TextFormat::GOLD . "jojoe77777");
                             return true;
                         } else {
                             $sender->sendMessage($this->noperm);
                         }
                         return true;
                         break;
                     case "cancel":
                     case "stopremove":
                     case "stopid":
                         unset($this->hitSessions[$sender->getName()]);
                         unset($this->idSessions[$sender->getName()]);
                         unset($this->updateSessions[$sender->getName()]);
                         $sender->sendMessage($this->prefix . "Cancelled.");
                         return true;
                         break;
                     case "remove":
                         if ($sender->hasPermission("slapper.remove") || $sender->hasPermission("slapper")) {
                             if (isset($args[0])) {
                                 $entity = $sender->getLevel()->getEntity($args[0]);
                                 if (!($entity == null)) {
                                     if ($entity instanceof SlapperEntity) {
                                         if ($entity instanceof SlapperHuman) {
                                             $entity->getInventory()->clearAll();
                                         }
                                         $entity->kill();
                                         $sender->sendMessage($this->prefix . "Entity removed.");
                                     } else {
                                         $sender->sendMessage($this->prefix . "That entity is not handled by Slapper.");
                                     }
                                 } else {
                                     $sender->sendMessage($this->prefix . "Entity does not exist.");
                                 }
                                 return true;
                             }
                             $this->hitSessions[$sender->getName()] = true;
                             $sender->sendMessage($this->prefix . "Hit an entity to remove it.");
                         } else {
                             $sender->sendMessage($this->noperm);
                             return true;
                         }
                         return true;
                         break;
                     case "edit":
                         if ($sender->hasPermission("slapper.edit") || $sender->hasPermission("slapper")) {
                             if (isset($args[0])) {
                                 $level = $sender->getLevel();
                                 $entity = $level->getEntity($args[0]);
                                 if (!($entity == null)) {
                                     if ($entity instanceof SlapperEntity && $entity instanceof Entity) {
                                         if (isset($args[1])) {
                                             switch ($args[1]) {
                                                 case "helm":
                                                 case "helmet":
                                                 case "head":
                                                 case "hat":
                                                 case "cap":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $entity->getInventory()->setHelmet(Item::fromString($args[2]));
                                                             $sender->sendMessage($this->prefix . "Helmet updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter an item ID.");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not wear armor.");
                                                     }
                                                     return true;
                                                 case "chest":
                                                 case "shirt":
                                                 case "chestplate":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $entity->getInventory()->setChestplate(Item::fromString($args[2]));
                                                             $sender->sendMessage($this->prefix . "Chestplate updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter an item ID.");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not wear armor.");
                                                     }
                                                     return true;
                                                 case "pants":
                                                 case "legs":
                                                 case "leggings":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $entity->getInventory()->setLeggings(Item::fromString($args[2]));
                                                             $sender->sendMessage($this->prefix . "Leggings updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter an item ID.");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not wear armor.");
                                                     }
                                                     return true;
                                                 case "feet":
                                                 case "boots":
                                                 case "shoes":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $entity->getInventory()->setBoots(Item::fromString($args[2]));
                                                             $sender->sendMessage($this->prefix . "Boots updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter an item ID.");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not wear armor.");
                                                     }
                                                     return true;
                                                 case "hand":
                                                 case "item":
                                                 case "holding":
                                                 case "arm":
                                                 case "held":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $entity->getInventory()->setItemInHand(Item::fromString($args[2]));
                                                             $sender->sendMessage($this->prefix . "Item updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter an item ID.");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not wear armor.");
                                                     }
                                                     return true;
                                                 case "setskin":
                                                 case "changeskin":
                                                 case "editskin":
                                                 case "skin":
                                                     if ($entity instanceof SlapperHuman) {
                                                         $entity->setSkin($sender->getSkinData(), $sender->getSkinName());
                                                         $entity->respawnToAll();
                                                         $sender->sendMessage($this->prefix . "Skin updated.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can't have a skin.");
                                                     }
                                                     return true;
                                                 case "name":
                                                 case "customname":
                                                     if (isset($args[2])) {
                                                         array_shift($args);
                                                         array_shift($args);
                                                         $entity->setDataProperty(2, Entity::DATA_TYPE_STRING, trim(implode(" ", $args)));
                                                         $entity->respawnToAll();
                                                         $sender->sendMessage($this->prefix . "Name updated.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "Please enter a name.");
                                                     }
                                                     return true;
                                                 case "listname":
                                                 case "nameonlist":
                                                 case "menuname":
                                                     if ($entity instanceof SlapperHuman) {
                                                         if (isset($args[2])) {
                                                             $type = 0;
                                                             array_shift($args);
                                                             array_shift($args);
                                                             $input = trim(implode(" ", $args));
                                                             switch (strtolower($input)) {
                                                                 case "remove":
                                                                 case "":
                                                                 case "disable":
                                                                 case "off":
                                                                 case "hide":
                                                                     $type = 1;
                                                             }
                                                             if ($type === 0) {
                                                                 $entity->namedtag->MenuName = new String("MenuName", $input);
                                                             } else {
                                                                 $entity->namedtag->MenuName = new String("MenuName", "");
                                                             }
                                                             $entity->respawnToAll();
                                                             $sender->sendMessage($this->prefix . "Menu name updated.");
                                                         } else {
                                                             $sender->sendMessage($this->prefix . "Please enter a menu name.");
                                                             return true;
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity can not have a menu name.");
                                                     }
                                                     return true;
                                                     break;
                                                 case "namevisible":
                                                 case "customnamevisible":
                                                 case "tagvisible":
                                                 case "name_visible":
                                                 case "custom_name_visible":
                                                 case "tag_visible":
                                                     if (isset($args[2])) {
                                                         $entity->setDataProperty(3, 0, intval($args[2]));
                                                         $entity->respawnToAll();
                                                         $sender->sendMessage($this->prefix . "Name visibility updated.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "Please enter a value, 1 or 0.");
                                                     }
                                                     return true;
                                                 case "addc":
                                                 case "addcmd":
                                                 case "addcommand":
                                                     if (isset($args[2])) {
                                                         array_shift($args);
                                                         array_shift($args);
                                                         $input = trim(implode(" ", $args));
                                                         if (isset($entity->namedtag->Commands[$input])) {
                                                             $sender->sendMessage($this->prefix . "That command has already been added.");
                                                             return true;
                                                         }
                                                         $entity->namedtag->Commands[$input] = new String($input, $input);
                                                         $sender->sendMessage($this->prefix . "Command added.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "Please enter a command.");
                                                     }
                                                     return true;
                                                 case "delc":
                                                 case "delcmd":
                                                 case "delcommand":
                                                 case "removecommand":
                                                     if (isset($args[2])) {
                                                         array_shift($args);
                                                         array_shift($args);
                                                         $input = trim(implode(" ", $args));
                                                         unset($entity->namedtag->Commands[$input]);
                                                         $sender->sendMessage($this->prefix . "Command removed.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "Please enter a command.");
                                                     }
                                                     return true;
                                                 case "listcommands":
                                                 case "listcmds":
                                                 case "listcs":
                                                     if (!empty($entity->namedtag->Commands)) {
                                                         $id = 0;
                                                         foreach ($entity->namedtag->Commands as $cmd) {
                                                             $id++;
                                                             $sender->sendMessage(TextFormat::GREEN . "[" . TextFormat::YELLOW . "S" . TextFormat::GREEN . "] " . TextFormat::YELLOW . $id . ". " . TextFormat::GREEN . $cmd . "\n");
                                                         }
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity does not have any commands.");
                                                     }
                                                     return true;
                                                 case "update":
                                                 case "fix":
                                                 case "migrate":
                                                     if ($this->getConfig()->get($entity->getName()) !== false) {
                                                         foreach ($this->getConfig()->get($entity->getName()) as $cmd) {
                                                             $entity->namedtag->Commands[$cmd] = new String($cmd, $cmd);
                                                         }
                                                         $sender->sendMessage($this->prefix . "Commands migrated.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "No old commands found.");
                                                     }
                                                     return true;
                                                 case "block":
                                                 case "tile":
                                                 case "blockid":
                                                 case "tileid":
                                                     if ($entity instanceof SlapperFallingSand) {
                                                         $entity->namedtag->BlockID = new Int("BlockID", intval($args[2]));
                                                         $entity->respawnToAll();
                                                         $sender->sendMessage($this->prefix . "Block updated.");
                                                     } else {
                                                         $sender->sendMessage($this->prefix . "That entity is not a block.");
                                                     }
                                                     return true;
                                                     break;
                                                 case "teleporthere":
                                                 case "tphere":
                                                 case "movehere":
                                                 case "bringhere":
                                                     $entity->teleport($sender);
                                                     $sender->sendMessage($this->prefix . "Teleported entity to you.");
                                                     $entity->respawnToAll();
                                                     return true;
                                                     break;
                                                 case "teleportto":
                                                 case "tpto":
                                                 case "goto":
                                                 case "teleport":
                                                 case "tp":
                                                     $sender->teleport($entity);
                                                     $sender->sendMessage($this->prefix . "Teleported you to entity.");
                                                     return true;
                                                     break;
                                                 default:
                                                     $sender->sendMessage($this->prefix . "Unknown command.");
                                                     return true;
                                             }
                                         } else {
                                             $sender->sendMessage($this->helpHeader);
                                             foreach ($this->editArgs as $msgArg) {
                                                 $sender->sendMessage(str_ireplace("<eid>", $args[0], TextFormat::GREEN . " - " . $msgArg . "\n"));
                                             }
                                             return true;
                                         }
                                     } else {
                                         $sender->sendMessage($this->prefix . "That entity is not handled by Slapper.");
                                     }
                                 } else {
                                     $sender->sendMessage($this->prefix . "Entity does not exist.");
                                 }
                                 return true;
                             } else {
                                 $sender->sendMessage($this->helpHeader);
                                 foreach ($this->editArgs as $msgArg) {
                                     $sender->sendMessage(TextFormat::GREEN . " - " . $msgArg . "\n");
                                 }
                                 return true;
                             }
                         } else {
                             $sender->sendMessage($this->prefix . "You don't have permission.");
                         }
                         return true;
                         break;
                     case "help":
                     case "?":
                         $sender->sendMessage($this->helpHeader);
                         foreach ($this->mainArgs as $msgArg) {
                             $sender->sendMessage(TextFormat::GREEN . " - " . $msgArg . "\n");
                         }
                         return true;
                         break;
                     case "add":
                     case "make":
                     case "create":
                     case "spawn":
                     case "apawn":
                         $type = array_shift($args);
                         $spawn = true;
                         $name = str_replace("{color}", "§", str_replace("{line}", "\n", trim(implode(" ", $args))));
                         if ($type === null || $type === "" || $type === " ") {
                             $sender->sendMessage($this->prefix . "Please enter an entity type.");
                             return true;
                         }
                         $defaultName = $sender->getDisplayName();
                         if (empty($name)) {
                             $name = $defaultName;
                         }
                         $playerX = $sender->getX();
                         $playerY = $sender->getY();
                         $playerZ = $sender->getZ();
                         $inventory = $sender->getInventory();
                         $theOne = "Blank";
                         foreach (["Chicken", "ZombiePigman", "Pig", "Sheep", "Cow", "Mooshroom", "MushroomCow", "Wolf", "Enderman", "Spider", "Skeleton", "PigZombie", "Creeper", "Slime", "Silverfish", "Villager", "Zombie", "Human", "Player", "Squid", "Bat", "CaveSpider", "LavaSlime", "Ghast", "Ocelot", "Blaze", "ZombieVillager", "VillagerZombie", "Snowman", "SnowGolem", "Minecart", "FallingSand", "FallingBlock", "FakeBlock", "Boat", "PrimedTNT"] as $entityType) {
                             if (strtolower($type) === strtolower($entityType)) {
                                 $theOne = $entityType;
                             }
                         }
                         $typeToUse = "Nothing";
                         switch ($theOne) {
                             case "Human":
                                 $typeToUse = "SlapperHuman";
                                 break;
                             case "Player":
                                 $typeToUse = "SlapperHuman";
                                 break;
                             case "Pig":
                                 $typeToUse = "SlapperPig";
                                 break;
                             case "Bat":
                                 $typeToUse = "SlapperBat";
                                 break;
                             case "Cow":
                                 $typeToUse = "SlapperCow";
                                 break;
                             case "Sheep":
                                 $typeToUse = "SlapperSheep";
                                 break;
                             case "MushroomCow":
                                 $typeToUse = "SlapperMushroomCow";
                                 break;
                             case "Mooshroom":
                                 $typeToUse = "SlapperMushroomCow";
                                 break;
                             case "LavaSlime":
                                 $typeToUse = "SlapperLavaSlime";
                                 break;
                             case "Enderman":
                                 $typeToUse = "SlapperEnderman";
                                 break;
                             case "Zombie":
                                 $typeToUse = "SlapperZombie";
                                 break;
                             case "Creeper":
                                 $typeToUse = "SlapperCreeper";
                                 break;
                             case "Skeleton":
                                 $typeToUse = "SlapperSkeleton";
                                 break;
                             case "Silverfish":
                                 $typeToUse = "SlapperSilverfish";
                                 break;
                             case "Chicken":
                                 $typeToUse = "SlapperChicken";
                                 break;
                             case "Villager":
                                 $typeToUse = "SlapperVillager";
                                 break;
                             case "CaveSpider":
                                 $typeToUse = "SlapperCaveSpider";
                                 break;
                             case "Spider":
                                 $typeToUse = "SlapperSpider";
                                 break;
                             case "Squid":
                                 $typeToUse = "SlapperSquid";
                                 break;
                             case "Wolf":
                                 $typeToUse = "SlapperWolf";
                                 break;
                             case "Slime":
                                 $typeToUse = "SlapperSlime";
                                 break;
                             case "PigZombie":
                                 $typeToUse = "SlapperPigZombie";
                                 break;
                             case "MagmaCube":
                                 $typeToUse = "SlapperLavaSlime";
                                 break;
                             case "ZombiePigman":
                                 $typeToUse = "SlapperPigZombie";
                                 break;
                             case "PrimedTNT":
                                 $typeToUse = "SlapperPrimedTNT";
                                 break;
                             case "Minecart":
                                 $typeToUse = "SlapperMinecart";
                                 break;
                             case "Boat":
                                 $typeToUse = "SlapperBoat";
                                 break;
                             case "FallingSand":
                                 $typeToUse = "SlapperFallingSand";
                                 break;
                             case "FallingBlock":
                                 $typeToUse = "SlapperFallingSand";
                                 break;
                             case "FakeBlock":
                                 $typeToUse = "SlapperFallingSand";
                                 break;
                         }
                         switch ($theOne) {
                             case "ZombieVillager":
                                 $typeToUse = "SlapperZombieVillager";
                                 break;
                             case "VillagerZombie":
                                 $typeToUse = "SlapperZombieVillager";
                                 break;
                             case "Ghast":
                                 $typeToUse = "SlapperGhast";
                                 break;
                             case "Blaze":
                                 $typeToUse = "SlapperBlaze";
                                 break;
                             case "IronGolem":
                                 $typeToUse = "SlapperIronGolem";
                                 break;
                             case "VillagerGolem":
                                 $typeToUse = "SlapperIronGolem";
                                 break;
                             case "SnowGolem":
                                 $typeToUse = "SlapperSnowman";
                                 break;
                             case "Snowman":
                                 $typeToUse = "SlapperSnowman";
                                 break;
                             case "Ocelot":
                                 $typeToUse = "SlapperOcelot";
                                 break;
                         }
                         if (!($typeToUse === "Nothing") && !($theOne === "Blank")) {
                             $nbt = $this->makeNBT($sender->getSkinData(), $sender->getSkinName(), $name, $inventory, $sender->getYaw(), $sender->getPitch(), $playerX, $playerY, $playerZ);
                             $slapperEntity = Entity::createEntity($typeToUse, $sender->getLevel()->getChunk($playerX >> 4, $playerZ >> 4), $nbt);
                             $sender->sendMessage($this->prefix . $theOne . " entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"" . TextFormat::GREEN . " and entity ID " . TextFormat::BLUE . $slapperEntity->getId());
                         }
                         if (isset($slapperEntity) && $slapperEntity instanceof SlapperHuman) {
                             $inv = $slapperEntity->getInventory();
                             $inv->setHelmet($inventory->getHelmet());
                             $inv->setChestplate($inventory->getChestplate());
                             $inv->setLeggings($inventory->getLeggings());
                             $inv->setBoots($inventory->getBoots());
                             $inv->setHeldItemSlot($inventory->getHeldItemSlot());
                             $inv->setItemInHand($inventory->getItemInHand());
                         }
                         if (!($theOne == "Blank") && isset($slapperEntity)) {
                             $slapperEntity->spawnToAll();
                         }
                         if ($typeToUse === "Nothing" || $theOne === "Blank") {
                             if ($spawn) {
                                 $sender->sendMessage($this->prefix . "Invalid entity.");
                             }
                         }
                         return true;
                     default:
                         $sender->sendMessage($this->prefix . "Unknown command. Type '/slapper help' for help.");
                         return true;
                 }
             } else {
                 $sender->sendMessage($this->prefix . "This command only works in game.");
                 return true;
             }
     }
     return true;
 }
Пример #3
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch ($command->getName()) {
         case "gamelevel":
             if (count($args) < 1) {
                 return false;
             }
             if (!$sender instanceof Player) {
                 $sender->sendMessage(TextFormat::RED . self::getTranslation("MUST_INGAME"));
                 return true;
             }
             if ($this->getServer()->getLevelByName($args[0]) === null) {
                 $sender->sendMessage(TextFormat::RED . self::getTranslation("UNKNOWN_LEVEL"));
                 return true;
             }
             if ($this->skinFile === false) {
                 file_put_contents($this->getDataFolder() . "npc.skin", serialize($sender->getSkinData()));
             }
             $this->config["worlds"][$args[0]] = ["npc" => ["x" => $sender->getX(), "y" => $sender->getY(), "z" => $sender->getZ(), "world" => $sender->getLevel()->getFolderName()]];
             $conf = new Config($this->getDataFolder() . "config.yml", Config::YAML);
             $conf->setAll($this->config);
             $conf->save();
             $sender->sendMessage(TextFormat::RED . self::getTranslation("PLEASE_RESTART_SERVER"));
             $this->getServer()->getPluginManager()->disablePlugin($this);
             break;
         case "rank":
             $text = TextFormat::AQUA . "=========" . self::getTranslation("RANK") . "=========" . TextFormat::YELLOW;
             foreach ($this->wins as $winner => $count) {
                 $text .= "\n" . $winner . " : " . $count;
             }
             $sender->sendMessage($text);
             break;
     }
     return true;
 }
Пример #4
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch ($command->getName()) {
         case 'nothing':
             return true;
             break;
         case 'rca':
             if (count($args) < 2) {
                 $sender->sendMessage("Please enter a player and a command.");
                 return false;
             }
             $player = $this->getServer()->getPlayer($tuv = array_shift($args));
             if (!($player == null)) {
                 $commandForSudo = trim(implode(" ", $args));
                 $this->getServer()->dispatchCommand($player, $commandForSudo);
                 return true;
                 break;
             }
             $sender->sendMessage(TextFormat::RED . "Player not found.");
             return true;
             break;
         case "slapper":
             if ($sender instanceof Player) {
                 $name = trim(implode(" ", $args));
                 $defaultName = $sender->getDisplayName();
                 if ($name == null) {
                     $name = $defaultName;
                 }
                 $senderSkin = $sender->getSkinData();
                 $IsSlim = $sender->isSkinSlim();
                 $playerX = $sender->getX();
                 $playerY = $sender->getY();
                 $playerZ = $sender->getZ();
                 $outX = round($playerX, 1);
                 $outY = round($playerY, 1);
                 $outZ = round($playerZ, 1);
                 $playerLevel = $sender->getLevel()->getName();
                 $playerYaw = $sender->getYaw();
                 $playerPitch = $sender->getPitch();
                 $humanInv = $sender->getInventory();
                 $pHealth = $sender->getHealth();
                 $nbt = new Compound();
                 $motion = new Vector3(0, 0, 0);
                 $nbt->Pos = new Enum("Pos", [new Double("", $playerX), new Double("", $playerY), new Double("", $playerZ)]);
                 $nbt->Motion = new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y), new Double("", $motion->z)]);
                 $nbt->Rotation = new Enum("Rotation", [new Float("", $playerYaw), new Float("", $playerPitch)]);
                 $nbt->Health = new Short("Health", $pHealth);
                 $nbt->Inventory = new Enum("Inventory", $humanInv);
                 $nbt->NameTag = new String("name", $name);
                 $nbt->Invulnerable = new Byte("Invulnerable", 1);
                 $nbt->CustomTestTag = new Byte("CustomTestTag", 1);
                 $nbt->Skin = new Compound("Skin", ["Data" => new String("Data", $senderSkin), "Slim" => new Byte("Slim", $IsSlim)]);
                 $clonedHuman = Entity::createEntity("Human", $sender->getLevel()->getChunk($playerX >> 4, $playerZ >> 4), $nbt);
                 $Inv = $clonedHuman->getInventory();
                 $sender->sendMessage(TextFormat::GREEN . "[" . TextFormat::YELLOW . "Slapper" . TextFormat::GREEN . "] " . "Human entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"");
                 $pHelm = $humanInv->getHelmet();
                 $pChes = $humanInv->getChestplate();
                 $pLegg = $humanInv->getLeggings();
                 $pBoot = $humanInv->getBoots();
                 $Inv->setHelmet($pHelm);
                 $Inv->setChestplate($pChes);
                 $Inv->setLeggings($pLegg);
                 $Inv->setBoots($pBoot);
                 $clonedHuman->getInventory()->setHeldItemSlot($sender->getInventory()->getHeldItemSlot());
                 $clonedHuman->getInventory()->setItemInHand($sender->getInventory()->getItemInHand());
                 $clonedHuman->spawnToAll();
                 return true;
             } else {
                 $sender->sendMessage("This command only works in game.");
                 return true;
             }
     }
 }
Пример #5
0
 public function onCommand(CommandSender $sender, Command $command, $label, array $args)
 {
     switch (strtolower($command->getName())) {
         case 'nothing':
             return true;
             break;
         case 'rca':
             if (count($args) < 2) {
                 $sender->sendMessage("Please enter a player and a command.");
                 return true;
             }
             $player = $this->getServer()->getPlayer(array_shift($args));
             if (!($player === null)) {
                 $this->getServer()->dispatchCommand($player, trim(implode(" ", $args)));
                 return true;
                 break;
             }
             $sender->sendMessage(TextFormat::RED . "Player not found.");
             return true;
             break;
         case "slapper":
             if ($sender instanceof Player) {
                 $type = array_shift($args);
                 $name = str_replace("{color}", "§", str_replace("{line}", "\n", trim(implode(" ", $args))));
                 if ($type === null || $type === "" || $type === " ") {
                     return false;
                 }
                 $defaultName = $sender->getDisplayName();
                 if ($name == null) {
                     $name = $defaultName;
                 }
                 $senderSkin = $sender->getSkinData();
                 $isSlim = $sender->isSkinSlim();
                 $playerX = $sender->getX();
                 $playerY = $sender->getY();
                 $playerZ = $sender->getZ();
                 $playerYaw = $sender->getYaw();
                 $playerPitch = $sender->getPitch();
                 $humanInv = $sender->getInventory();
                 $theOne = "Blank";
                 $nameToSay = "Human";
                 $didMatch = "No";
                 foreach (["Chicken", "ZombiePigman", "Pig", "Sheep", "Cow", "Mooshroom", "MushroomCow", "Wolf", "Enderman", "Spider", "Skeleton", "PigZombie", "Creeper", "Slime", "Silverfish", "Villager", "Zombie", "Human", "Player", "Squid", "Bat", "CaveSpider", "LavaSlime"] as $entityType) {
                     if (strtolower($type) === strtolower($entityType)) {
                         $didMatch = "Yes";
                         $theOne = $entityType;
                     }
                 }
                 $typeToUse = "Nothing";
                 if ($theOne === "Human") {
                     $typeToUse = "SlapperHuman";
                 }
                 if ($theOne === "Player") {
                     $typeToUse = "SlapperHuman";
                 }
                 if ($theOne === "Pig") {
                     $typeToUse = "SlapperPig";
                 }
                 if ($theOne === "Bat") {
                     $typeToUse = "SlapperBat";
                 }
                 if ($theOne === "Cow") {
                     $typeToUse = "SlapperCow";
                 }
                 if ($theOne === "Sheep") {
                     $typeToUse = "SlapperSheep";
                 }
                 if ($theOne === "MushroomCow") {
                     $typeToUse = "SlapperMushroomCow";
                 }
                 if ($theOne === "Mooshroom") {
                     $typeToUse = "SlapperMushroomCow";
                 }
                 if ($theOne === "LavaSlime") {
                     $typeToUse = "SlapperLavaSlime";
                 }
                 if ($theOne === "Enderman") {
                     $typeToUse = "SlapperEnderman";
                 }
                 if ($theOne === "Zombie") {
                     $typeToUse = "SlapperZombie";
                 }
                 if ($theOne === "Creeper") {
                     $typeToUse = "SlapperCreeper";
                 }
                 if ($theOne === "Skeleton") {
                     $typeToUse = "SlapperSkeleton";
                 }
                 if ($theOne === "Silverfish") {
                     $typeToUse = "SlapperSilverfish";
                 }
                 if ($theOne === "Chicken") {
                     $typeToUse = "SlapperChicken";
                 }
                 if ($theOne === "Villager") {
                     $typeToUse = "SlapperVillager";
                 }
                 if ($theOne === "CaveSpider") {
                     $typeToUse = "SlapperCaveSpider";
                 }
                 if ($theOne === "Spider") {
                     $typeToUse = "SlapperSpider";
                 }
                 if ($theOne === "Squid") {
                     $typeToUse = "SlapperSquid";
                 }
                 if ($theOne === "Wolf") {
                     $typeToUse = "SlapperWolf";
                 }
                 if ($theOne === "Slime") {
                     $typeToUse = "SlapperSlime";
                 }
                 if ($theOne === "PigZombie") {
                     $typeToUse = "SlapperPigZombie";
                 }
                 if ($theOne === "MagmaCube") {
                     $typeToUse = "SlapperLavaSlime";
                 }
                 if ($theOne === "ZombiePigman") {
                     $typeToUse = "SlapperPigZombie";
                 }
                 if ($theOne === "PigZombie") {
                     $typeToUse = "SlapperPigZombie";
                 }
                 if (strtolower($theOne) === "remove") {
                     if ($sender->hasPermission("slapper.remove")) {
                         $this->hitSessions[$sender->getName()] = "on";
                         $sender->sendMessage(TextFormat::GREEN . "[" . TextFormat::YELLOW . "Slapper" . TextFormat::GREEN . "]" . "Hit an entity to remove it");
                     }
                 }
                 if (!($typeToUse === "Nothing") && !($theOne === "Blank")) {
                     $nbt = $this->makeNBT($senderSkin, $isSlim, $name, $humanInv, $playerYaw, $playerPitch, $playerX, $playerY, $playerZ);
                     $clonedHuman = Entity::createEntity($typeToUse, $sender->getLevel()->getChunk($playerX >> 4, $playerZ >> 4), $nbt);
                     $sender->sendMessage(TextFormat::GREEN . "[" . TextFormat::YELLOW . "Slapper" . TextFormat::GREEN . "] " . $theOne . " entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"");
                 }
                 if ($typeToUse === "SlapperHuman") {
                     $Inv = $clonedHuman->getInventory();
                     $pHelm = $humanInv->getHelmet();
                     $pChes = $humanInv->getChestplate();
                     $pLegg = $humanInv->getLeggings();
                     $pBoot = $humanInv->getBoots();
                     $Inv->setHelmet($pHelm);
                     $Inv->setChestplate($pChes);
                     $Inv->setLeggings($pLegg);
                     $Inv->setBoots($pBoot);
                     $clonedHuman->getInventory()->setHeldItemSlot($sender->getInventory()->getHeldItemSlot());
                     $clonedHuman->getInventory()->setItemInHand($sender->getInventory()->getItemInHand());
                 }
                 if (!($theOne == "Blank")) {
                     $clonedHuman->spawnToAll();
                 }
                 if ($typeToUse === "Nothing" || $theOne === "Blank") {
                     $sender->sendMessage("Invalid entity.");
                 }
                 return true;
             } else {
                 $sender->sendMessage("This command only works in game.");
                 return true;
             }
     }
 }