[Finally solved] Sign cast error

Discussion in 'Spigot Plugin Development' started by gartenzaun, Jun 4, 2015.

Thread Status:
Not open for further replies.
  1. Hey guys,

    Code (Text):
                BlockState sign = p.getWorld().getBlockAt(signLocation).getState();
                Sign thisSign = (Sign) sign;
    This is my code for getting the sign at the location signLocation. If I execute the code, it says that I can't cast the BlockState to my sign thisSign. Did I do anything wrong? Thanks for your answers!
     
  2. Do:
    Code (Text):
    Sign sign = (Sign) signLocation.getBlock().getState();
     
    • Like Like x 1
  3. I had that too and got exactly the same error. Now it's gone! Thank you for your help!
     
  4. Now I want to execute this:
    Code (Text):
    Sign thisSign = (Sign) signLocation.getBlock().getState();
    Same error as above: can't cast the BlockState to my sign thisSign :(
     
  5. Where do you get an error?
    Eclipse or if you run it? (Logs?)
     
  6. When I run the code then there's that error:
    Code (Text):
    [09:04:52] [Server thread/ERROR]: Error occurred while disabling myPlugin v0.1 (Is it up to date?)
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
        at gartenzaun.myPlugin.onDisable(myPlugin.java:130) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:323) ~[spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:359) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:424) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:417) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.disablePlugins(CraftServer.java:335) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at net.minecraft.server.v1_8_R2.MinecraftServer.stop(MinecraftServer.java:458) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:590) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
     
    #7 gartenzaun, Jun 4, 2015
    Last edited: Jun 4, 2015
  7. Please show your imports! (Top of your clazz)
     
    • Agree Agree x 1
  8. Code (Text):
    package gartenzaun;

    import java.util.ArrayList;

    import net.md_5.bungee.api.ChatColor;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
  9. Please remove all your imports, try this:
    Code (Text):
    Block block = signLocation.getBlock();
    BlockState state = block.getState();
    Sign thisSign = (Sign) state;
    ... and import all again...
    (Just FYI: It looked like, you imported NMS, but you didn't..)
     
    #10 dommi2212, Jun 4, 2015
    Last edited: Jun 4, 2015
    • Winner Winner x 1
  10. You're a hero!!! Thanks a lot
     
  11. No problem :D
     
  12. I'm totally confused... Same error again! :confused:

    Code:
    Code (Text):
                        Block block = signLocation.getBlock();
                        BlockState state = block.getState();
                        Sign thisSign = (Sign) state;
    Error:
    Code (Text):
    [10:51:52] [Server thread/ERROR]: Error occurred while disabling myPlugin v0.1 (Is it up to date?)
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.block.CraftBlockState cannot be cast to org.bukkit.block.Sign
        at gartenzaun.myPlugin.onDisable(myPlugin.java:130) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:323) ~[spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:359) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:424) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:417) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.disablePlugins(CraftServer.java:335) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at net.minecraft.server.v1_8_R2.MinecraftServer.stop(MinecraftServer.java:458) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:590) [spigot.jar:git-Spigot-2f787bd-ea28011]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Imports:
    Code (Text):
    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.Sign;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    I don't know whats going on here... :/
     
  13. There are two classes called "Sign." You simply need to make sure you import the correct one. When the error occurs, remove the imports to any class called "Sign." Then, re-import the Sign class.
     
    • Agree Agree x 1
  14. What did you change?
     
    • Agree Agree x 1
  15. Nothing...

    When I import import org.bukkit.material.Sign; then I can't set lines on the signs.
     
  16. I can't believe, it just stopped working...

    It's org.bukkit.block.Sign!

    Edit: Did you change the block? (Ingame)
     
  17. Now imported org.bukkit.block.Sign but the error is still there...

    And I didn't edit any block :/
     
  18. Did you change another part of the code?
     
  19. Make sure the block at signLocation is actually a sign. How do you get that location?
     
Thread Status:
Not open for further replies.