Solved Check if sign is Placed on Chest

Discussion in 'Plugin Development' started by Gigi10012, Jun 22, 2013.

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

    Gigi10012

    Hi
    I want to Check if sign is Placed on Chest
    Code:java
    1. @EventHandler
    2. public void onSignPlace(SignChangeEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. //if(Sign Placed on Chest)
    6. //{
    7. // Bukkit.broadcastMessage("Chest");
    8. //}
    9. }

    How to do this?
     
  2. Offline

    Tzeentchful

    Gigi10012
    Well first off you are going to want to get the sign's data and find what block face it's attached to. Then get the block relative to the face it's attached and check if it's a chest.

    Code:java
    1. @EventHandler
    2. public void onSignPlace(SignChangeEvent event) {
    3. Sign sign = (Sign) event.getBlock().getState().getData();
    4. Block attached = event.getBlock().getRelative(sign.getAttachedFace());
    5. if(attached.getType() == Material.CHEST) {
    6. //Do stuff
    7. }
    8. }
     
  3. Offline

    Gigi10012

    thanks

    Why I'm Getting Error on this:
    Code:java
    1. Block attached = event.getBlock().getRelative(sign.getAttachedFace());


    Why I'm Getting Error in Eclipse? How to fix that?

    I fixed it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page