Hey I have this code: PHP: public function onCommand(CommandSender $player, Command $command, $label, array $args): bool{ switch($command->getName()){ case "sg": if(!empty($args[0])){ switch($args[0]){ case "make": if($player->isOp()){ if(!empty($args[1])){ if(file_exists($this->getServer()->getDataPath() . "/worlds/" . $args[1])){ $this->getServer()->loadLevel($args[1]); $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ()); array_push($this->arenas, $args[1]); $this->currentLevel = $args[1]; $this->mode = 1; $player->sendMessage("§eYou are now in §6SETUP MODE§r§e. Tap a block to set the first spawn point."); $player->setGamemode(1); $player->teleport($this->getServer()->getLevelByName($args[1])->getSafeSpawn(), 0, 0); }else{ $player->sendMessage("§c[ERROR] §7Couldn't find a world with this name"); } }else{ $player->sendMessage(TextFormat::YELLOW . "/sg make <world> §7make an sg arena"); } }else{ $player->sendMessage("§c[ERROR] You don't have permission to use this command."); } break; case "join": if(!empty($args[0])){ if(!empty($args[1])){ if(file_exists($this->getServer()->getDataPath() . "/worlds/" . $args[1])){ $this->getServer()->loadLevel($args[1]); $this->getServer()->getLevelByName($args[1])->loadChunk($this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorX(), $this->getServer()->getLevelByName($args[1])->getSafeSpawn()->getFloorZ()); array_push($this->arenas,$args[1]); $this->currentLevel = $args[1]; $this->mode = 1; $level = $this->getServer()->getLevelByName($this->currentLevel); $levelArena = $level; $playersArena = $levelArena->getPlayers(); $gamecount = count($this->getServer()->getLevelByName($this->currentLevel)->getPlayers()); $this->currentLevel = $level; $player->setFood(20); $player->setHealth(20); $player->setGamemode(0); $level = $this->currentLevel; $x = -963; $y = 33; $z = 837; $pos = new Vector3($x,$y,$z); $player->teleport($level->getSafeSpawn($pos)); $levelArena = $level; $playersArena = $levelArena->getPlayers(); $gamecount = count($this->getServer()->getLevelByName($args[1])->getPlayers()); foreach($playersArena as $pl) $pl->sendMessage(TextFormat::YELLOW . $player->getNameTag() . TextFormat::YELLOW . " joined the game. (" . TextFormat::AQUA . $gamecount . TextFormat::RESET . TextFormat::AQUA . "/24" . TextFormat::YELLOW . ")"); } }else{ $player->sendMessage(TextFormat::YELLOW . "/sg join <world> §7join and sg game"); } }else{ $player->sendMessage(TextFormat::YELLOW . "/sg make <world> §7make an sg arena"); $player->sendMessage(TextFormat::YELLOW . "/sg join <world> §7join an sg game"); } break; } } } return true; } (/sg join is incomplete) Everything works fine. however, when the player types /sg I want it to show those last 2 messages in the code. but it won't show anything.
To start you should clean up your code because that is not understandable (at least for me). Too many else loops there
If the command is long like that, I prefer to use PHP: YourCommandClass extends Command{ public function __construct(){ parent::__construct("command", "description", "usage", ["aliases"]); } public function execute(CommandSender $sender, string $label, array $args){ // Your command code here // Also for args, use switch($args[1]){ // body } }} Now register the command so it can be used PHP: $this->getServer()->getCommandMap()->register("Your_command_name", new YourCommandClass());
Depends on what you want to do... but pmmp registers plugin commands similar to that...Just a short cut...