Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PlayerJoinEvent HELP ME

Comments in 'Plugin Development' started by redstoned, Feb 13, 2016.

  1. redstoned
    Offline

    redstoned New Member

    Joined:
    Sep 18, 2015
    Posts:
    2
    Minecraft User:
    redstonealmeida
    how do I use PlayerJoinEvent and make the player being teleported between 4 worlds randomly?



    is correcty?


    if($number == 1){
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($world1));
    $sender->sendMessage("Teleported to Lobby1");
    }
    if($number == 2){
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($world2));
    $sender->sendMessage("Teleported to Lobby2");
    }
    if($number == 3){
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($world3));
    $sender->sendMessage("Teleported to Lobby3");
    }
    if($number == 4){
    $sender->getPlayer()->teleport(Server::getInstance()->getLevelByName($world4));
    $sender->sendMessage("Teleported to Lobby4");
    }
    }
    return true;
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    PHP:
    $number mt_rand(14);
    http://php.net/manual/en/function.mt-rand.php


    but your code is wrong:

    1- $sender->getPlayer() ?
    2- you can use Player->getServer() or PluginBase->getServer() instead of Server::getInstance()
    Last edited: Feb 14, 2016
    KubixQ, PocketKiller and Vaivez66 like this.
  3. redstoned
    Offline

    redstoned New Member

    Joined:
    Sep 18, 2015
    Posts:
    2
    Minecraft User:
    redstonealmeida

    $event->getPlayer()->teleport($this->getRandomLocation($event->getPlayer()->getLevel()->getName()));

    for move to random worlds
  4. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    1. What's $sender?
    2. Server::getInstance is a bad practice, instead use $this->getServer()
    3. In $teleport($position) $position should be a instance of Vector3 (Position class extends Vector3), with getSafeSpawn() you will get the spawn coordinates of the map in Vector3.
    4. Instead mt_rand, use array_rand, you'll be able to teleport they to a random level by names.
    PHP:
    public function OnJoin(PlayerJoinEvent $event)
    {
    $event->getPlayer()->teleport($this->getServer()->getLevelByName(array_rand(["world1name","world2name","world3name"]))->getSafeSpawn());
    }
    What is the point of teleport the player to his current map? Your code will only teleport player to a random position of his current map.
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You cant teleport players on PlayerJoinEvent, use PlayerLoginEvent
    Last edited: Feb 14, 2016
  6. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    $sender for commands


    $event for events ( PlayerJoinEvent , QuitEvent ... )
  7. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
  8. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    the opposite is correct. if you do that, server will crash.
  9. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    i can Use
    PHP:
    CommandSender $player,...
    and I Can use
    $sender = $event->getPlayer();
    Last edited: Feb 14, 2016
    Omar2s2 likes this.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use PlayerRespawnEvent for changing player spawn position.
  11. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    Yes but for basic
  12. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    PHP:
    public function e_onJoin(PlayerJoinEvent $sender){
    //CODE
    }
    he use like that
    Omar2s2 likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Nobody ever told you that there is scuh rule. I like calling $ev for events and $issuer for commands. Totally personal preference.
  14. XxD7omGamer
    Offline

    XxD7omGamer New Member

    Joined:
    Jun 28, 2015
    Posts:
    38
    Minecraft User:
    XxD7omGamer
    Ohh... sorry

Share This Page

Advertisement