Solved Check if block is sign

Discussion in 'Plugin Development' started by TFOXTom, Sep 28, 2018.

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

    TFOXTom

    I'm trying to check if a sign is under a cart.
    So I'm using an if statement that checks if the blocktype is a sign(using the .equals method as wel as simple ==)
    This returns false, but when I check the block with a simple console message( block.toString() ), it says the type is SIGN. No errors are shown to the console....
    EDIT: Forgot to say I got the block from a MinecartGroup, which comes from the traincarts api :)

    Does anyone know a solution? Thanks in advance!

    P.s. did not add the code, because it's literally an if statement described above.
     
    Last edited: Sep 28, 2018
  2. Online

    KarimAKL

    @TFOXTom Have you tried something like this?
    Code:Java
    1. if (block instanceof Sign)

    I don’t remember if you have to check the block state, you can try both.
     
  3. Offline

    TFOXTom

    Tried, both do not work, blockstate gives me ClassCastException, normal blockgives no error. Thanks for suggesting this as I totally forgot that was also an option!
     
  4. You should look closely at the classes of the things you compare. Try printing the class of both of them.

    I think you should do something like block.getType() == Material.SIGN, but I don't know the exact context.
     
  5. Offline

    TFOXTom

    @knokko sorry for the late reply, was away for a day.
    Well that's the problem. I've already done that, and tried what you said, but it still doesn't work.
    Don't know how to proceed :(
     
  6. Offline

    The_Spaceman

    Code:java
    1.  
    2. BlockState blockState = block.getState();
    3. if (blockState instanceof org.bukkit.block.Sign) {
    4. org.bukkit.block.Sign s = (org.bukkit.block.Sign) blockState;
    5. //do something
    6. s.update();
    7. }
    8.  

    where 'block' is your block
     
  7. You should print the class of the block and you should print the value of block.getType().

    And share the results with us if you still can't figure it out.
     
  8. Offline

    TFOXTom

    @The_Spaceman thanks, it works(while I tried it before and it didn't work then)!
     
  9. Online

    KarimAKL

    @TFOXTom I guess you made a little mistake that you didn't notice the first time, anyway i'm glad you got it working. :)
     
  10. Offline

    The_Spaceman

    what is the fex then? because it has worked. I used this from an older plugin i once made
     
Thread Status:
Not open for further replies.

Share This Page