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

Solved Player on First Join will spawn in another world.

Discussion in 'Development' started by Daniel Pereira, Mar 5, 2018.

  1. Daniel Pereira

    Daniel Pereira Silverfish

    Messages:
    22
    GitHub:
    Undentified
    Hello fellows!
    I'm Building a Tutorial for an Original Game for Minecraft: Pocket Edition under the title "Swords & Castles" where I'm learning a bit how to program some basic plugins.
    Well, I've learned how to create the playerJoinEvent thanks to my old thread where some good lads helped !

    My small problem now is that I can't figure out how I will make the player spawn in another world rather then the default one IF the player as never joined so he can get teleported to the "Tutorial Island" World! (best name lol)

    Here's the code I have so far thanks to @Teamblocket and @Nathaniel Fredericks

    PHP:
    namespace learning;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\plugin\PlayerJoinEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;

    class 
    learning extends PluginBase implements Listener {

                public function 
    onEnable {
                  
    $this-getServer()->getPluginManager()->registerEvents($this$this);
                  
    $this->getLogger()->Info("Plugin Enabled. OMG!");
                }
                public function 
    onDisable {
                  
    $this->getLogger()->Info("Plugin Disabled. Bai!");
                }

                public function 
    playerJoinEvent(PlayerJoinEvent $event) {
                  
    $player $event->getPlayer();

                  if(
    $player->hasPlayedBefore() == true) {
                    
    $player->sendMessage("Welcome back, " $player-getName());
                  } else {
                    
    // It's probably here where I will put the code that I need. But how is it?
                    
    $player->sendMessage(TextFormat::GOLD "Welcome to the Swords & Castles ! Let's start with a Tutorial.");
                  }
                }


    }

    Note : I do know that the Event can be made in other ways that for a lot of you it's more simple but in my head this way makes more sense to me and readable.

    Thanks everyone that reply here! Have a good day. :)
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    $world $this->getServer()->getLevelByName("world");
    $player->teleport($world);
     
    Daniel Pereira likes this.
  3. Daniel Pereira

    Daniel Pereira Silverfish

    Messages:
    22
    GitHub:
    Undentified
    wow..
    lol.

    that's uh.. simple.
    I get the server so I can get the Level and store it in the $world variable. Then I teleport the player to the $world with the teleport function! lmao so simple. XD

    Thanks @xXNiceAssassinlo YT for the brief but effective help.
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    You don’t really need $world variable you change it to whatever you.
    - xXNiceYT
     
    Daniel Pereira likes this.
  5. Daniel Pereira

    Daniel Pereira Silverfish

    Messages:
    22
    GitHub:
    Undentified
    Yes I know, it can even be $somethingblabla but thanks again!
     
    xXNiceAssassinlo YT likes this.
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    No problem!
     
  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.