Solved Help getting block above player

Discussion in 'Plugin Development' started by Joseph_Gappy, Feb 7, 2016.

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

    Joseph_Gappy

    Hello iam just wondering how to check if there is a block above player

    "if(there is block above player head){
    sendmessage
    }

    if(there is no any block above player){
    sendmessage
    }

    i used "getHighestBlockAt" "player.getlocation"
    but dont know how to check if there is air or block is null idk i tried everything but didnt work
    something like this
    Code:
                Block b = p.getWorld().getHighestBlockAt(p.getLocation());
                if (b.getType() != Material.AIR) {
                    e.setCancelled(true);
                    p.closeInventory();
                    p.sendMessage(getConfig().getString("above-error").replaceAll("&", "ยง"));
                    return;
                }
    
     
    Last edited by a moderator: Feb 7, 2016
  2. Offline

    Xerox262

    @Joseph_Gappy If you're using getHighestBlock the odds are that it isn't null because it will get the block that has no blocks above it, assuming your players can't break bedrock then it could return that if it's the highest block.

    Use
    Code:
    if (block.getLocation().getY() > player.getLocation().getY()) // This will be true if there is a block above the player, otherwise there is no block above the player.
     
  3. Offline

    Joseph_Gappy

    is it getting block above player like p.getlocation + 1 or like more higher
     
  4. Offline

    Xerox262

    What getHighestBlock(); does is it goes from 256 all the way down to 0, the first block it hits is the highest block, even if that block is at level 0, regardless of what the player's y is. So all you have to do is check if the block's y is higher than the player's y, if it is then the block is above them, if it's not then the block is below them.
     
  5. Offline

    Joseph_Gappy

    i want to get the location from player's location to up up like above player (every plugin is above player) i want to like drop something from above like supply drop to a player but i want nothing be above player to get the supply drop
     
  6. Offline

    JoaoBM

    @Joseph_Gappy Then you don't want the block above the Player. What if they are in a Cave? You would have alot of Blocks above the Player. Or will the supply box spawn 2 blocks above?
     
  7. Offline

    Joseph_Gappy

    Supply drop comes from air and i dont want any block above plugin and for example block opening supply box in cave
     
  8. Offline

    Xerox262

    @Joseph_Gappy I've told you twice now how to check if there's a block above the player, get the highest block, then get it's location and check if it's above the player or below them.
     
  9. Offline

    Joseph_Gappy

    if (<block??>.getLocation().getY()
     
  10. Offline

    Xerox262

  11. Offline

    Joseph_Gappy

    oh thanks.
     
  12. Offline

    GetSomePanda

    Here is how to see if there is a block above someones head, the block can be at any height and it will be found :)
    This should work nicely for your supply drop plugin.

    Code:
    if (player.getLocation().getBlockY() + 1 > player.getWorld().getHighestBlockYAt(player.getLocation())) {
                            //Theres a block above my head.
                        } else {
                            //Nothing above my head.
                        }
    
    Hopefully this works, good luck.
     
  13. Offline

    Joseph_Gappy

    thanks. solved
     
Thread Status:
Not open for further replies.

Share This Page