Solved convert blockstate to sign

Discussion in 'Plugin Development' started by Kyorax, Jan 19, 2014.

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

    Kyorax

    Hi everyone,
    even after spending a lot of time googling,
    I still couldn't solve my problem.

    I want to check if a sign contains a text when someone rightclicks it.
    But it always says it couldn't convert BlockState to Sign.
    This is my code:

    Code:java
    1.  
    2. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    3. BlockState state = event.getClickedBlock().getState();
    4. if (state instanceof Sign) {
    5.  
    6. Sign sign = (Sign) state;
    7.  
    8. if(sign.getLine(1).contains("[HELLO-SIGN]")) {
    9. p.sendMessage("Hello.");
    10. }
    11. } }


    Thanks in advance.
     
  2. Offline

    xMrPoi

    You check for line 1 on your sign. Remember, in java, things tend to start with 0. So line 1 would actually be the second line of the sign.
     
    Kyorax likes this.
  3. Offline

    Chinwe

    Make sure you're casting it to org.bukkit.block.Sign instead of org.bukkit.material.Sign :)
     
Thread Status:
Not open for further replies.

Share This Page