[SOLVED] Get second block of the placed bed

Discussion in 'Plugin Development' started by Seadragon91, Jan 31, 2012.

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

    Seadragon91

    I try to get the second block of the bed, if the bed is placed. For that I use the event BlockPlaceEvent.

    With that code I lopping around the placed block to get the other bed part:
    Code:java
    1. private Block getOtherBedBlock(Block b1) {
    2. for (int x = -1; x <= 1; x++) {
    3. for (int z = -1; z <= 1; z++) {
    4. Block b2 = b1.getRelative(x, 0, z);
    5. if (!(b1.getLocation().equals(b2.getLocation()))) {
    6. if (b2.getType().equals(Material.BED_BLOCK)) {
    7. return b2;
    8. }
    9. }
    10. }
    11. }
    12. return null;
    13. }


    Problem is in the moment where the event is called, the other bed block is not placed. And a other problem, if that would be work, it can happens, that I get a other block from a other bed, because its possible to place beds abreast.

    A other idea was that I only save the block of the bed that is placed, and use BlockBreak but the problem is that the player could break the part of the bed from that I haven't saved the location, then that does not work too.
     
  2. Offline

    Seadragon91

    Ty very much, it works :)
     
Thread Status:
Not open for further replies.

Share This Page