Solved Workaround for playing falling after teleport when lagging

Discussion in 'Plugin Development' started by Yukari, Jul 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Yeah, that title is a bit confusing.

    I have a problem I've had players on my server complain about, basically players with high ping (live on other continent,) when they teleport, they will get stuck 1-3 blocks below the point they were supposed to teleport to.

    After a little testing, it appears to only happen to players who are lagging, and only when they are teleporting to an area their client doesn't have yet. Meaning teleporting to somewhere 1000 blocks away causes it to happen, because their client has to download that area from the server, but teleporting 5 blocks away it doesn't happen. I think what's happening is that they teleport there, and because it takes too long for them to get the area from the server, their client thinks they're falling, so they drop these 1-3 blocks before they receive the area, and then they potentially suffocate in the ground.

    I've tried just adding 1-2 blocks to the y coordinate of where they're teleporting, but it doesn't always work smoothly, and it causes problems for players who aren't lagging 100% of the time (as they end up a couple blocks further up.)

    The only solution I've gotten to work is to give them godmode for a second, and then add a delayed task that teleports them to the location again after the second is up, but I'd really like to not do this because it's really annoying if you're not lagging that you get bounced back a second after the teleport.

    I'm humbly asking you all if you can think of any brilliant solutions to this problem.
  2. Offline


    Even with lag players shouldn't be able to noclip through the ground - try adding NoCheatPlus with only movement being monitored, it'll prevent them from clipping through the ground.

    Some questions though:
    Does it happen when they respawn?
    Does it happen when they teleport to a different world? (It shouldn't)
  3. Offline


    I'm not going to add anticheat to solve a lag problem, that just seems like an unnecessary workaround.

    Yes it happens to different worlds.

    Yes it happens when you respawn, but it appears something then teleports you back up to the proper spawn place shortly after. (and to be clear, my plugin does not do anything to people respawning.)
  4. Offline


    i don't if this will work. (it's not compiled)
    1. @EventHandler
    2. public void onPlayerTeleport(PlayerTeleportEvent event){
    3. Player player = e.getPlayer();
    4. thread.sleep(1000); //1000 is 1 second
    5. int counter = 0;
    6. if(p.getLocation().getBlock().getType() != Material.AIR){
    8. while(true){
    10. if(player.getLocation().getBlock().getType() != Material.AIR){
    11. counter++;
    12. Block relative = player.getLocation().getBlock().getRelative(0,counter,0);
    13. if(relative.getType() == Material.AIR){
    14. player.teleport(relative.getLocation());
    15. break;
    16. }
    17. }
    18. }
    19. }
    21. }
  5. Offline


    You can also try setting the following to TRUE in the bukkit.yml
    use-exact-login-location: true
  6. Offline


    Asgernohns never ever use Thread.sleep in the main thread. Also that code could allow noclipping.
    Yukari try sending them the chunk before teleporting them there
    Yukari likes this.
  7. Offline


    fireblast709 Oh, good idea. Is that possible with bukkit or would I have to use NMS?

    The only function I could find that seems to remotely do that would be Player.sendBlockChange, or World.refreshChunk.
  8. Offline


    Yukari I don't know whether it is possible directly with Bukkit. To avoid direct NMS you could try plugins like ProtocolLib
  9. Offline


    At the very least, get the nearby chunks of the teleport location and load them into memory first.
  10. Offline


    Solved it now (at least no reports of it happening anymore) using player.sendBlockChange for just the block below where they playere is teleported to. So thanks for the suggestion fireblast709.

    In case anybody else is having this problem, here's my code, where loc is the location the player is being teleported to.

    1. Location fLoc = new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() );
    2. player.sendBlockChange(fLoc, fLoc.getBlock().getType(), fLoc.getBlock().getData() );
Thread Status:
Not open for further replies.

Share This Page