[Solved] Sign : CraftBlockState cannot be cast

Discussion in 'Spigot Plugin Development' started by to175, Jul 13, 2015.

  1. Hi, help please :p
    Code (Text):
    Sign sign = (Sign) event.getClickedBlock().getState();
    Gives me this error :
     
  2. Are you sure you're interacting with à sign?
    You should check if the clicked block is an instance of a Sign. ;)
     
  3. Ho you are right :/
    I'm just checking :
    Code (Text):
    if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){...}
    I will add :
    Code (Text):
    &&event.getClickedBlock() instanceof Sign
     
  4. Help :
    I have a wall sign that I'm trying to get but error :
    "org.bukkit.craftbukkit.v1_7_R4.block.CraftBlockState cannot be cast to org.bukkit.block.Sign"

    Code :
    Code (Text):
    Sign sign = (Sign) location.getBlock().getState();
     
  5. I think the state has to be instance of sign and not the block itself .
    Anyway, you could use this . It should work (without checking if istanceof).
    Code (Text):

    if ((event.getClickedBlock().getType() == Material.SIGN_POST) || (event.getClickedBlock().getType() == Material.WALL_SIGN)) {
        Sign s = (Sign)event.getClickedBlock().getState();
     
     
  6. Event.getClickedBlock().ggetState instanceof Sign

    Try that because you cannot check if a block is an instance of something getting the type should fix it
     
  7. I forgot to update :D