1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to change gamemode when tp'ing to other worlds

Discussion in 'Help' started by Destroyer57, Aug 9, 2018.

  1. Destroyer57

    Destroyer57 Zombie

    Messages:
    275
    The title says all
     
  2. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    https://github.com/pmmp/PocketMine-...56f7a97c39410/src/pocketmine/Player.php#L1282
    https://github.com/pmmp/PocketMine-...tmine/event/entity/EntityLevelChangeEvent.php

    The api says all

    Joke aside:

    PHP:
    public function onEntityLevenChange(EntityLevelChangeEvent $event): void{
        if(
    $event->getEntity() instanceof Player){
            if(
    $event->getTarget()->getFolderName() === "ExampleWorld"){
                
    $event->getEntity()->setGamemode(Player::SURVIVAL);
            }
        }
    }
    (Assuming this is used in a registered listener and all needed classes are imported)
     
    corytortoise and Muqsit like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.