Solved Casting block state to sign gives no lines

Discussion in 'Plugin Development' started by SaxSalute, May 4, 2014.

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

    SaxSalute

    In my event for SignChangeEvent, I have no problem getting the lines of a sign from event.getLine(int lineNum). However, later I need to get the sign by the block location. When I try to get the text that way in the same exact event handler, it comes back as a blank sign. To be clear, within the same method or in different methods, this:

    Code:java
    1. System.out.println("First line in addRatingBoard by block: " + ((Sign) event.getBlock().getState()).getLine(0));


    Will give me a valid sign, but that string is empty. However, this:

    Code:java
    1. System.out.println("First line from event.getLine(0): " + event.getLine(0));


    Will give the correct line. How can I get the text from the block itself?
     
  2. Offline

    Esophose

    SaxSalute
    Try making a sign variable and casting the block to a sign in that, then check the line. Something along the lines of this.
    Code:java
    1. Sign sign = (Sign) e.getBlock();
    2. System.out.println("First line in addRatingBoard by block: " + sign.getLine(0));
     
  3. Offline

    SaxSalute

    Am I supposed to cast the block to a sign or the block state to a sign?

    EDIT: Only the block state can be cast to a sign.

    Esophose I tried your example but with e.getBlock().getState() and it still gives a blank sign.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  4. Offline

    Esophose

    SaxSalute
    The second line of code you have in the original post should work fine. If it isn't doing what you want, what do you want?
     
  5. Offline

    SaxSalute

    I need to pull and set data from signs at stored locations. Those locations are stored by the SignChangeEvent if the first line fits the proper criteria. When I go to update the signs, all I have is a location of where the sign is so I need to be able to use the first method, though in practice it would be:

    Code:java
    1. System.out.println("First line in addRatingBoard by block: " + ((Sign) loc.getBlock().getState()).getLine(0));
     
  6. Offline

    Plo124

    SaxSalute
    Since this is a SignChangeEvent, you dont have to do the getBlock.getState stuff.
    That stuff is for the PlayerInteractEvent or any other block event which gets the sign like that.
     
  7. Offline

    SaxSalute

    What I'm saying is that I need to do it outside of the SignChangeEvent and I put my test code both in and out of the SignChangeEvent to try to find where the problem is with the code that needs to run outside. The intended location for this code is in a completely adjunct method that needs to be run on a scheduler or on a command.

    Ok, so I figured it out and it's incredibly weird. For some reason when I was calling my updateRating() function, the text hadn't been put on the sign yet but the event knew what text was going to go on the sign in nanoseconds. I fixed the problem by having the function run through a task on a 1 tick delay. Very strange.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page