Do not teleport players into a block.

Discussion in 'Plugin Development' started by Staartvin, Aug 19, 2013.

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

    Staartvin

    Hello developers,

    I've created a plugin: Scroll Teleportation.
    It allows you to teleport to a set destination with a 'scroll'. (Piece of paper)

    I have implemented methods that check if you will be teleported into a wall, and if you will, it will get a new location that is safe.

    See this snippet:

    Code:java
    1. private Location secureLocation(Location oldLocation, Player player) {
    2. World world = oldLocation.getWorld();
    3. int x = oldLocation.getBlockX(),y = oldLocation.getBlockY(), z = oldLocation.getBlockZ();
    4.  
    5. // Block for feet
    6. Block blockOnY = world.getBlockAt(x, y, z);
    7. // Block for head
    8. Block blockOnY2 = world.getBlockAt(x, (y + 1), z);
    9. // Block below feet
    10. Block blockOnY3 = world.getBlockAt(x, (y - 1), z);
    11.  
    12.  
    13. Location safeLocation = null;
    14. // Player would suffocate or fall down
    15. if (!blockOnY.getType().equals(Material.AIR) || !blockOnY2.getType().equals(Material.AIR) || blockOnY3.getType().equals(Material.AIR)) {
    16. // Determine a new safer place to teleport to.
    17. int safeY = oldLocation.getWorld().getHighestBlockYAt(x, z);
    18. safeLocation = new Location(world, x, safeY, z);
    19. } else {
    20. safeLocation = oldLocation;
    21. }
    22. return safeLocation;
    23. }



    However, some users report that it's still not working. They've said that players still get teleported into blocks.

    Does anybody know why?
     
  2. Offline

    Lactem

    I will make an API for this right now.
     
  3. Offline

    xTrollxDudex

    Staartvin
    I usually don't use getBlockAt(), I construct a new location and getBlock() on it
     
    tommycake50 likes this.
  4. Offline

    Staartvin



    Why exactly?

    Thanks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  5. Offline

    xTrollxDudex

  6. Offline

    Lactem

  7. Offline

    Staartvin

  8. Offline

    Lactem

    Oh. I didn't even read your code. You posted in the wrong section. I thought you needed help with something.
     
  9. Offline

    Staartvin


    Oh, sorry. What section should I post it in then?
     
  10. Offline

    Lactem

Thread Status:
Not open for further replies.

Share This Page