Solved Find block above the event block in BlockBreakEvent

Discussion in 'Plugin Development' started by KittyKatt, Apr 12, 2013.

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



    I'm trying to make lamp plugin, if you destroy a block in BlockBreakEvent and there is a glowstone 5 blocks over that block, it should change to something else.

    Guess I have to do something with event.getBlock().getLocation() ? Not sure how I would check 5 blocks over and if its a glowstone. Help please? =)))
  2. event.getBlock() returns a Block object.

    Block has a getRelative(BlockFace face) that returns a Block.

    Thus, event.getBlock().getRelative(BlockFace.UP) will give you the block one block above that.

    There is also getRelative(BlockFace face,int x) that gets the block x away in the blockface's direction.
    Information on the Block object, such as methods that let you get the type of block and such.
  3. Offline


    One way to do this would be

    2. Block brokenBlock = event.getBlock()
    3. Block lampBlock = brokenBlock.getWorld().getBlockAt(brokenBlock.getX(), brokenBlock.getY + 5, brokenBlock.getZ());
    4. if (lampBlock != null && lampBlock.getType() == Material.GLOWSTONE) {
    5. //your codde
    6. }

    regards, mcoder
    KittyKatt likes this.
  4. Offline


            Material lamp = event.getBlock().getWorld().getBlockAt(event.getBlock().getLocation().add(0,5,0)).getType();
            if(lamp == Material.GLOWSTONE)
                Bukkit.broadcastMessage("GLOWSTONE FOUND!");
Thread Status:
Not open for further replies.

Share This Page