Guys,can someone help me pls with something?I want to tp players to a second lobby if first lobby reach max limit of players,I mean if for example there are already 40 players on lobby1, player will be tped to lobby2,which is a different world and I tested many times my codes and I had errors and I fixed them,but tp doesn't work,idk what is wrong,my codes are used on EntityLevelChangeEvent :: (also a player who has a certain permission can join on lobby1): PHP: if ($ev->getTarget()->getName() === "hypixel1" && count(Server::getInstance()->getLevelByName("hypixel1")->getPlayers()) > 0) { if($ev->getEntity()->hasPermission("mvp.perm") == true) { $ev->setCancelled(); } else { if (Server::getInstance()->isLevelLoaded("hypixel1lb2") === false) { Server::getInstance()->loadLevel("hypixel1lb2"); } $player = $ev->getEntity(); $player->teleport(Server::getInstance()->getLevelbyName("hypixel1lb2")->getSafeSpawn()); } } You may saw those codes on discord too,but I posted it here with the hope I'll get help,because no one on discord helps me with my codes at the most of times.
It seems like my code does not execute,I can't understand why does this happen or if I did something wrong.
So, you are a normal player, without the mvp.perm permission in a random world, you use a plugin of choice to warp to the level "hypixel1", one other player is already in that level, right? And what you expect to happen is that you're warped to "hypixel1lb2", but what actually happens in that you land in "hypixel1" with the pother player, right? (btw, I think using that name is just a little bit trademark infringing)
Look,my codes actually should do this:Lets say there is a normal player joining in the server,if this player goes on "hypixel1" world and its full of a certain amount players,that player should be quickly moved to "hypixel1lb2" world,except in the case that he has the "mvp.perm",then he will stay to "hypixel1",so he won't be teleported. About that "but what actually happens in that you land in "hypixel1" with the pother player, right?" hm idk,player will be probably visible to all players for some seconds,until he "goes" to the second world. And yes the map I'm using is hypixel styled,so thats the reason,I may change it if something happen,anyway.
Well I think that when I removed $event->setCancelled() it fixed my issue,because it works as I want now.Anyway if someone wants to use it,use this example: PHP: if ($ev->getTarget()->getName() === "hypixel1" && count(Server::getInstance()->getLevelByName("hypixel1")->getPlayers()) > 0) { if($ev->getEntity()->hasPermission("mvp.perm") == true) { } else { if (Server::getInstance()->isLevelLoaded("hypixel1lb2") === false) { Server::getInstance()->loadLevel("hypixel1lb2"); } $player = $ev->getEntity(); $player->teleport(Server::getInstance()->getLevelbyName("hypixel1lb2")->getSafeSpawn()); } }
I suggest you using this code though, it's the same as yours above but better PHP: /*** @param PlayerLoginEvent $event*/public function onJoin(PlayerLoginEvent $event): void { $player = $event->getPlayer(); $server = Server::getInstance(); $firstLobbyName = "hypixel1"; $secondLobbyName = "hypixel1lb2"; $server->loadLevel($firstLobbyName); $server->loadLevel($secondLobbyName); $firstLobby = $server->getLevelByName($firstLobbyName); if(count($firstLobby->getPlayers()) < 40 or $player->hasPermission("mvp.perm")) { $player->teleport($firstLobby->getSafeSpawn()); return; } $player->teleport($server->getLevelByName($secondLobbyName));}
Ok thanks,its better I think because of variables,like: $firstLobbyName = "hypixel1"; $secondLobbyName = "hypixel1lb2"; I may use it in future but I'm ok for now.