player.isOnGround

Discussion in 'Plugin Development' started by Blah1, Sep 30, 2013.

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

    Blah1

    Since player.isOnGround is deprecated now, what do I use?
    Also, is there a way to do like player.hasFlyEnabled or something like that?
     
  2. Offline

    BurnBlader

    Code:
    if(player.getLocation().getBlock().getRelative(BlockFace.SOUTH).getType() != Material.AIR) {
    //whatever
    }
    
    Then to see if they have fly:
    Code:
    if(player.getAllowFlight()) {
    //whatever
    }
    
     
  3. Offline

    Blah1

    I like player.isOnGround more... Lol thanks!
     
  4. Offline

    Compressions

    Blah1 Just because it's deprecated does not mean it doesn't work :p
     
  5. Offline

    xTrollxDudex

  6. Offline

    Quantix

    You can cast the Player object to an Entity and use the onGround() boolean which isn't deprecated for Entities (the deprecated onGround() method inside the Player class is inherited from the Entity class).
    Code:java
    1. Entity playerEntity = (Entity) player;
    2. boolean isOnGround = playerEntity.isOnGround();

    BurnBlader 's replacement for the onGround() check won't work. Whether a player is on the ground or not is not simply a question of whether there is an air block underneath him (it's more complex than that, look at the g value in the debug menu when standing on the edge of a block). Despite all that, even the internal onGround() method is still not very reliable as the server itself doesn't determine whether a player is on the ground. Instead, the client tells the server if the player is on the ground regardless of whether he is actually really on the ground. To check if a player is in creative fly mode use:
    Code:java
    1. player.isFlying();
     
    au2001 and Blah1 like this.
  7. Offline

    Rocoty

    Quantix
    You're kidding right? You'd still be calling the method from the Player object. Because no matter how much you cast it to another type it is still a Player object.
     
  8. Offline

    frymaster

    It's deprecated but still works as well as it ever did. Which is "not very".

     
  9. Offline

    MrSnare

    Get the location of the block below the player. If It is not air, player is on the ground.
     
    Rocoty likes this.
  10. Offline

    Rocoty

    This is not entirely accurate. What if the player is hovering less than a block above ground? I would suggest checking if the player's y position is an integer as well (y % 1 == 0)
     
  11. Offline

    MrSnare

    Check the block below the player, If that is air, check the block below that. This works.
     
  12. Offline

    Rocoty

    MrSnare Eh. How? Would you say the player is on the ground if they are hovering two blocks above it? I wouldn't
     
  13. Offline

    MrSnare

    My first answer works most of the time, that is just a check in case they are on a half slab
     
  14. Offline

    Quantix


    Yes, you're using the method from the Entity class which the Player class inherits so they are the pretty much the same. By casting the Player to an Entity you won't need to use @SupressWarnings("deprecation");


    As I said in my original post, the onGround() is more complex than that. What if the player is standing on the edge of a block with the middle of the Player's bounding box already above an air block? If you were to simply check if the block directly below the player is air and you were to code a fly detection using that method, it would produce a significant amount of false positives. To test this you could use both the Bukkit onGround() method and yours and see if they always match (they won't).
     
Thread Status:
Not open for further replies.

Share This Page