[SOLVED]Block cast bug

Discussion in 'Plugin Development' started by Ribesg, Oct 11, 2011.

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

    PHP:
    org.bukkit.material.Sign signMaterial = (org.bukkit.material.Signevent.getBlock().getState();
    Raise a ClassCastException.
    Why ?
    Thanks.

    I thought it was something obvious and somebody respond quickly...
    So, obviously, it's in the onSignChange() method in my BlockListener. This worked in 1240 but now with the 1317...

    Code:
    [SEVERE] Could not pass event SIGN_CHANGE to myPlugin
    java.lang.ClassCastException: org.bukkit.craftbukkit.block.CraftSign cannot be cast to org.bukkit.material.Sign
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  2. Offline

    stelar7

    would this work?
    Sign s = (Sign) event.getBlock().getState();
     
  3. I need
    org.bukkit.material.Sign and
    org.bukkit.block.Sign
    in my plugin
    Because you can't import both, I choose to import the one I use many times.
    I only use this line one time in tje class...
     
  4. Right, stelar7's suggestion is just a shorter version.

    Isn't it an org.bukkit.block.Sign ?
    (instead of org.bukkit.material.Sign)

    Wait, you should just write this, no?

    org.bukkit.craftbukkit.block.CraftSign signMaterial = (org.bukkit.craftbukkit.block.CraftSign) event.getBlock().getState();

    Why typecast?
    Do you really need a org.bukkit.material.Sign ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  5. You shouldn't need a org.bukkit.material.Sign
     
  6. Oh, sorry... You obviously need to know this :D :
    I need to use the getAttachedBlock() method of the org.bukkit.material.Sign class !

    It's about [Protection] signs, I want to disallow them to be attached to sand & gravel blocks. Here is the code :
    PHP:
    if (block.getRelative(signMaterial.getAttachedFace()).getType()
                            .
    equals(Material.GRAVEL)
                            || 
    block.getRelative(signMaterial.getAttachedFace())
                                    .
    getType().equals(Material.SAND)) {
    <Do 
    things>
    }
     
  7. But, this here:
    event.getBlock().getState()


    returns a org.bukkit.block.Sign right?

    I think you might have to use the Block class.
    event.getBlock() returns a Block.

    The Block class has some getFace() method (maybe more) to get the neighbor-blocks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  8. I still don't think you want material.Sign...
     
  9. So why did I use the getAttachedBlock() method before and now it doesn't work anymore ?
     
  10. You need to cast event.getBlock().getState().getData() to org.bukkit.material.Sign if you want the sign.
     
    IconByte and Mtihc like this.
  11. Aahh that's the one, huh. :p
     
  12. Thank you !
    I don't know when I removed it, but I removed it.
    Or Enderman took it...
     
Thread Status:
Not open for further replies.

Share This Page