Solved Sign Casting Problem

Discussion in 'Plugin Development' started by icomputertinker, Dec 11, 2013.

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

    icomputertinker

    Hi, I have a problem with casting a block to a sign, even though that block *should* be a sign. Here's the trouble bit:

    Code:java
    1. if (w.getBlockAt(location).getState() instanceof Sign) {
    2. Sign s = (Sign) w.getBlockAt(location); //This is line 48 in my class.
    3. for (Location loc : signLoc) {
    4. if (s.getLocation() == loc) {
    5. if (signPlacer.get(signLoc.indexOf(loc)) != p || p.hasPermission("[Permission Omitted]") {
    6. p.sendMessage(ChatColor.DARK_RED + "[Message Omitted]");
    7. e.setCancelled(true);
    8. } else {
    9. remove = true;
    10. removeLocation = loc;
    11. }
    12. }
    13. }
    14. }
    15.  


    If you'd like, I have a Gist set up which also includes the stack trace:
    gist.github.com/icomputertinker/7921748


    Thanks.
     
  2. Offline

    ninja_ace202

    Sign s = (Sign) w.getBlockAt(location).getState();

    You have to .getState() to cast to signs. Weird. This is also the case for some other blocks. I want to say things like furnaces/crafting tables, but I may be wrong. I know you have to use .getState for a few different casts.
     
  3. Offline

    icomputertinker

    ninja_ace202
    This seems to work, but I can't be sure because I have some other stupid error (Who's stacktrace won't give me a line number) and I'm not sure if anything works. :eek:
     
  4. Offline

    ninja_ace202

    icomputertinker
    Just paste the stack trace here and see if anyone can help.

    As a random guess I would say check which Sign you're using. Make sure it NOT org.bukkit.material.Sign for your purposes you're likely looking for org.bukkit.block.Sign

    You may actually want to just mark this thread as solved and make a new thread about this new error.
     
  5. Offline

    icomputertinker

    ninja_ace202
    This is a completely different error from what I mentioned earlier. ;) It has nothing to do with signs, but some other aspect of my class. Thanks anyway, I'll go ahead and mark the thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page