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

Teleport player back

Comments in 'Plugin Development' started by Artide, Jul 23, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    How to teleport a player 2 blocks back when he's too close to a sign or door, please and thank you?
  2. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    I think just teleport them to the getFrom() position from PlayerMoveEvent
    PHP:
    public function onMove(PlayerMoveEvent $event){
    if(
    /*there are signs and doors*/){
      
    $event->setCancelled(true);
      
    $event->getPlayer()->teleport($event->getFrom());
    }
    }
  3. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    But what is "if there are signs and doors?"
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What about using $player->getBlocksAround()?
  5. Calrizer
    Offline

    Calrizer Active Member

    Joined:
    Jan 17, 2015
    Posts:
    102
    Minecraft User:
    callumdrain
    I know it sounds long and probably inefficient but you could use:
    PHP:
    if($player->getFloorX() === $signX && $player->getFloorY() === $signY && $player->getFloorZ === $signZ){
       
    $move = new  Vector3($newX$sameY$newZ);
       
    $player->teleport($move);
    }
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That only teleports to the X- Y- Z- corner of the block the Player is currently in.
  7. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Would this work?
    if($player->getBlocksAround() instanceof Sign or $player->getBlocksAround() instanceof IronDoor){}?
  8. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    No...
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    How do you use this? getBlocksAround()
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is a block array... Iterate through it.
    MCPEPIG and Xenturio like this.
  11. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    Use a task instead, listening to PlayerMoveEvent and calculating math is quite resource-consuming.

    For the code in the task:

    PHP:
    foreach ($player->getBlocksAround() as $block)
    {
        if (
    $block->getId() === Block::DOOR_BLOCK || $block->getId() === Block::SIGN_POST || $block->getId() === Block::WALL_SIGN)
        {
            
    // Get player's current motion
            
    $motion $player->getMotion();
            
    // Invert the motion
            
    $motion $motion->multiply(-2);
            
    // Set player's current motion
            
    $player->setMotion($motion);
        }
    }
    I type the code without an IDE so I don't know would the code work. Even though it works - bouncing the players back if they are close to signs or doors - still there is a possible flaw: when player is in an area full of signs, the player may glitch around.
    hoyinm14mc and PEMapModder like this.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or simply glitch over it with a mod.
    TigerHix likes this.
  13. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    i was having hard time figuring it out. thanks :D
    $motion = $p->getMotion();
    $motion->multiply(-2);
    $p->setMotion($motion);

Share This Page

Advertisement