I don't understand why the sign's lines are empty...

Discussion in 'Spigot Plugin Development' started by HorrendousEntity, Apr 18, 2019.

  1. The following code is supposed to the sign's second line to "Hello from" and print it to the console,
    But in reality the sign is never changed and [, ,] is printed to the console.. The thing is that I have to save the sign object in order to chage in the future.. what to do?
    Code (Java):

    private Sign mySign;

    public void arenaSignPlace(SignChangeEvent event)
            if(event.getBlock().getType() == Material.WALL_SIGN)
                    Sign sign = (Sign) event.getBlock().getState();
                    this.mySign = sign;
                    sign.setLine(1, "Hello from");
  2. Are you sure you’ve registered the listener, and that it’s a WALL sign.

    Iirc there are two types of sign: WALL_SIGN and SIGN_POST or something.
  3. as I said [, ,] is printed to the console so nothing is wrong with my code, I know I can change the sign using the event's setLine() and getLine but as I said I need the sign object... why the .setLine() in the sign object does nothing?
  4. Oh I thought you said it never printed. I would suggest making sure you have the correct imports. - I’ve had issues with them before.
  5. I imported the the correct class which is org.bukkit.block.Sign :/
  6. Okay I think the event is overriding what you’ve sent to be changed. The event actually has a method itself to set lines, use that instead.

    If that doesn’t work try sign#update(true) and also delaying your original code by 40 ticks or so.
  7. In the 2th time, I need to save the sign object to update it later.. the sign.setLine() was just to check that it works.
    Besides, the sign.getLines() returns an empty array... what could be the reason?

    * the delay idea is reasonable, I'm gonna check that rn and return with an update
  8. You can use the event method, and still save the sign into your object.
  9. So you were right... kinda.

    Very weird.. doesn't matter what I put to event.setLine(), It completely resets the sign and sign.only update() shows it.
    In contrast to that, updating the sign manually using sign.setLine() does update the line but deletes every other line..

    so if the sign is:

    First Line: A
    Second: B
    Third: C
    Fourth: B

    It will become to:

    First Line:
    Second: line test
    Third: C
  10. The event is run before the lines are actually set to the sign. Thus you should use the event for getting and setting the lines instead of getting the sign and then getting the lines from there.
  11. look 1 message above :)
  12. Can you provide us with code sample on how you use event#setLine and event#getLine?
  13. Those are the codes that I used:

    Sign manual change code: https://pastebin.com/HGF9yyyY
    Event change code: https://pastebin.com/pZFhv9cn

    and here are what they yielded to:

    Manual change before the task(the 3 seconds task): http://prntscr.com/ndquew
    Manal change after 3 seconds: http://prntscr.com/ndqujo

    Event change before the task: http://prntscr.com/ndqu19
    Event change after the task: http://prntscr.com/ndqu6k
  14. Remove the delay when using the event#setLine
  15. yeah that worked like magic.. but still there's a problem with this code: https://prnt.sc/ndr3f0

    after the task is executed, this is literally the result: http://prntscr.com/ndr3uc
    it did add the second line as requested, but deleted all of the other lines..
  16. Only use event#setLine, don't use sign#setLine anymore and don't update the sign.
  17. why is it bugged? I mean I am gonna have to change the sign's lines in the future - that's precisely the reason why I save the sign's object..
  18. Huh? Just set lines using the event#setLine method. get rid of the scheduler.
  19. You didn't understand me.. My question is why I should never, in any case, change the sign line's outside of that event?
    My plugin has the task to update existing signs some-when, How is it supposed to do that then?That's why I save my signs and when needed I update the desired one.. so how am I supposed to do that?
  20. You don't do that because that overrides the event by scheduling it *after* the event has taken place, any changes made will be reverted.

Share This Page