Advertisement
LA_

Untitled

LA_
May 12th, 2024
681
0
2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. namespace plugin\command;
  4.  
  5. use plugin\entity\type\DinosaurEntity;
  6. use pocketmine\command\Command;
  7. use pocketmine\command\CommandSender;
  8. use pocketmine\command\utils\InvalidCommandSyntaxException;
  9. use pocketmine\permission\DefaultPermissions;
  10. use pocketmine\player\Player;
  11. use pocketmine\Server;
  12.  
  13. class EntityCommand extends Command
  14. {
  15.     public function __construct()
  16.     {
  17.         parent::__construct("entity", "Spawns or delete new dinosaur entity", "/entity (spawn/delete)");
  18.         $this->setPermission(DefaultPermissions::ROOT_USER);
  19.     }
  20.  
  21.     public function execute(CommandSender $sender, string $commandLabel, array $args): void
  22.     {
  23.         assert($sender instanceof Player);
  24.  
  25.         if(count($args) < 1) throw new InvalidCommandSyntaxException();
  26.  
  27.         switch($args[0])
  28.         {
  29.             case "spawn":
  30.                 $entity = new DinosaurEntity($sender->getLocation());
  31.                 $entity->spawnToAll();
  32.                 break;
  33.             case "delete":
  34.                 foreach(Server::getInstance()->getWorldManager()->getWorlds() as $world){
  35.                     foreach($world->getEntities() as $entity){
  36.                         if($entity instanceof DinosaurEntity){
  37.                             $entity->flagForDespawn();
  38.                         }
  39.                     }
  40.                 }
  41.                 break;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement