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

Teleport players to level spawn when fall to void

Comments in 'Plugin Development' started by TonyDroidd, Mar 28, 2015.

  1. TonyDroidd
    Offline

    TonyDroidd Active Member

    Joined:
    Sep 6, 2014
    Posts:
    180
    Minecraft User:
    TonyDroidd
    Tittle say all, i try using

    public function onVoidLoop(PlayerMoveEvent $event){
    if($event->getTo()->getFloorY() < 1){
    $event->setCancelled(true);
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());

    But, does not work .-.
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    That is a glitch in the way teleport works. My ManyWorlds plugin has a workaround for that.

    You can use that workaround in your own plugin. I use this code:

    PHP:
        if (($mw $this->getServer()->getPluginManager()->getPlugin("ManyWorlds"))  != null) {
          
    // Using ManyWorlds for teleporting...
          
    $mw->teleport($event->getPlayer(),$level);
        } else {
          
    $world $this->getServer()->getLevelByName($level);
          
    $event->getPlayer()->teleport($world->getSafeSpawn());
    }
    PEMapModder likes this.
  3. TonyDroidd
    Offline

    TonyDroidd Active Member

    Joined:
    Sep 6, 2014
    Posts:
    180
    Minecraft User:
    TonyDroidd
    Would use manyWorlds plugin to use that code?
    Hiw i can implement in my own plugin?
    Last edited: Mar 28, 2015
  4. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You can call the ManyWorlds plugin (so that would become an optional dependency for your plugin). On the other hand, that functionality is in a single file TeleportManager.php

    Keep in mind that I am using a GPL license, so if you include this, then your plugin becomes GPL.

    If you know how to recreate the bug, make sure that ManyWorlds does indeed solve your problem (mw has a teleport command). Otherwise you would spending your time for nothing.
  5. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    of cause it not working, try this:

    public function onVoidLoop(PlayerMoveEvent $event){
    if($event->getTo()->getFloorY() < 1){
    $event->getPlayer()->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
    TonyDroidd likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why of course not? It just calls another plugin's API function.
    TonyDroidd likes this.
  7. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    After looking at his code, I don't think this would work. Or if it does, it will not very reliable.

    You have a race condition. The client moves the player and sends the move event to the server. The server then have to make sure that it cancels the move before the client completes the client move and drops the player to the void. If the server is a bit over loaded, the move cancel may happen after the player drops to the void.

    Perhaps you should change your condition:

    PHP:
    if($event->getTo()->getFloorY() < 1){
    To some value other than 1 (to give the server some time to send the cancel).
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Which is not possible for servers that have the ground at y=2.
    TonyDroidd likes this.
  9. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    because when i setCancelled, it will not tp to the spawn anymore
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't teleport a player in a cancelled PlayerMoveEvent. EITHER teleport one tick later OR just don't cancel the PlayerMoveEvent.
  11. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Sorry but I couldn't resist replying to this thread (I'm searching for something ;P)
    PHP:
    $event->setTo($pos);
    Legoboy0215 likes this.

Share This Page

Advertisement