Check if there is a block above a player

Discussion in 'Plugin Development' started by xX4w3s0m3Xx, Jun 10, 2017.

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

    xX4w3s0m3Xx

    So I want to check if there is a block above the player and if so, then set him on fire, but at the moment it doesn't do anything and it sends these messages:
    [​IMG]
    Code:
    @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player player = e.getPlayer();
            Location location = player.getLocation();
            for (int i = 0; i < 255 - location.getY(); i++) {
                location.add(0, 1, 0);
                player.sendMessage(location.getBlock() + "");
                if (location.getBlock().getType() == Material.AIR) {
                    blockAbovePlayer.put(player, true);
                    player.sendMessage(ChatColor.RED + "There is a block above you!");
                    break;
                }
            }
            blockAbovePlayer.put(player, false);
            player.sendMessage(ChatColor.GREEN + "There isn't a block above you!");
            if (blockAbovePlayer.get(player).equals(true)) {
                player.setFireTicks(60);
            }
        }
     
  2. Use world#getHighestBlockYAt(location)
    Then you can easily check if it's above the player: blockY >= playerY + 2
     
    xX4w3s0m3Xx likes this.
  3. Offline

    xX4w3s0m3Xx

    Ah, I didn't know that method existed, Thank you! I got it working now!
     
Thread Status:
Not open for further replies.

Share This Page