Since player.isOnGround is deprecated now, what do I use? Also, is there a way to do like player.hasFlyEnabled or something like that?
Code: if(player.getLocation().getBlock().getRelative(BlockFace.SOUTH).getType() != Material.AIR) { //whatever } Then to see if they have fly: Code: if(player.getAllowFlight()) { //whatever }
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 Entity playerEntity = (Entity) player;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 player.isFlying();
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.
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)
MrSnare Eh. How? Would you say the player is on the ground if they are hovering two blocks above it? I wouldn't
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).