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

Check Teleport

Comments in 'Plugin Development' started by JackboyPlay, Jun 5, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hello exists an event that checks teleportation of a player? PS: EntityTeleportEvent doesnt work!
  2. udwarf
    Offline

    udwarf Active Member

    Joined:
    Apr 17, 2016
    Posts:
    61
    Minecraft User:
    1Zaza
    There is no such event
    May be you can use onPlayerMove, but not sure
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Primus likes this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    EntityTeleportEvent does exist and it gets triggered inside of Entity class but as Player class overwrites the Entity::teleport() method, the event is no longer called. May it be a bug? @Intyre knows. If it's not then why other entity events affect player? (EntityDamageEvent etc.)

    After little investigation it seems there is no event, to detect player teleportation but there is one *hack*
    PHP:
    private $lastPos = [];

    // Problems: If player does actually teleport, this code won't tell anyone until player moves.
    // If you are teleported away but inside 5 block radius from last position, this code won't know it
    public function onPlayerMove(PlayerMoveEvent $event){
           
    $p $event->getPlayer();
           
    $lastPos = new Vector3($p->lastX$p->lastY$p->lastZ);
           if(!isset(
    $this->lastPos[$p->getName()])){
             
    $this->lastPos[$p->getName()] = $lastPos;
             return;
           }
           
    $from $event->getFrom();
           
    $to $event->getTo();

           
    // We have to add more conditions to check if player doesn't have speed potion
           // or he isn't falling, also this can be true on high ping but probably not
           // because pm source will knock player back before calling move event
           
    if($to->distance($this->lastPos[$p->getName()]) > 5){
             
    $this->getLogger()->info("Player teleported");
           }

    I suggest to not use this code.

    You can also edit source code (Player.php) and add these lines inside Player::teleport() method
    PHP:
    $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this$from$to));
    if(
    $ev->isCancelled()){
      return 
    false;  
    }
    PocketMine source code isn't well commented :/
    Last edited: Jun 5, 2016
    JackboyPlay likes this.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Okay thanks hopefully a event like this will be added
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    @Intyre add an event like this, please!
    Primus likes this.

Share This Page

Advertisement