Changing text on a sign

Discussion in 'Plugin Development' started by eisental, Jan 21, 2011.

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

    eisental

    Hi,
    I'm trying to change a sign text in my print circuit (the problem is in updateSign() method ).
    First I get the Sign object from the block, then I use a bunch of Sign.setText() calls and finally do a Sign.update(true) to supposedly force a block update.

    The sign text doesn't change. I can see the new text only after a client server restart.
    Am I missing something? Is sign updating not supported yet?

    If anybody managed to do that, please tell me how...

    Bump... Anyone? [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 6, 2016
  2. Offline

    neron

    Indeed, sign update does not work.

    You can use
    Code:
    signBlock.setData(signBlock.getData());
    as a workaround.
     
  3. Offline

    eisental

    Thanks for the reply. I tried it with no luck...
    Basically what I do is this:

    Code:
    BlockState state = outputBlock.getState();
    if (state instanceof Sign) {
         Sign outputSign = (Sign)state;
          outputSign.setLine(0, "some text");
          outputSign.update(true); // force update
          outputBlock.setData(outputBlock.getData()); // your workaround
          // or
          outputSign.setData(outputSign.getData());
    }
    
    Is that what you mean? I tried a few other combinations, moving the update and setData lines around.
     
  4. Offline

    neron

    Now after trying again, I can't reproduce this at all. I guess this was caused by client mods (I was using Zan's Minimap).

    With a plain 1.2_02 client this code works.

    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
      Player player = event.getPlayer();
      String[] args = event.getMessage().split(" ");
    
      if (args[0].equalsIgnoreCase("/testsign")) {
        Block outputBlock = player.getWorld().getBlockAt(player.getLocation().getBlockX(),
            player.getLocation().getBlockY(),
            player.getLocation().getBlockZ());
    
        outputBlock.setType(Material.SIGN_POST);
    
        BlockState state = outputBlock.getState();
    
        if (state instanceof Sign) {
          Sign outputSign = (Sign)state;
          outputSign.setLine(0, "some text");
          //outputSign.update(true); // force update
          //outputBlock.setData(outputBlock.getData()); // your workaround
        }
      }
    }
    Note: Both updates are commented out and still the text is visible.

    Will try to reinstall the Minimap later.
     
  5. Offline

    eisental

    Thanks for digging into this.
    I tried your example and indeed the sign is placed with the text but when i changed the setLine to
    Code:
    outputSign.setLine(0, "some text"+Math.random())
    , calling the command a second time on the same block would not change the text to a new random number until I reconnect to the server.
    Very weird...
     
  6. Offline

    Chuck Lieb

    Have you tried unloading and reloading the chunk?

    Unless that works, a temporary workaround might be to remove and replace the sign, with the new text.
     
  7. Offline

    eisental

    Thanks, but I couldn't find any way to reload a chunk. Is that even possible?
     
  8. Offline

    neron

    Well, this just works with the latest Git build.

    Code:
            if (args[0].equalsIgnoreCase("/testsign")) {
                Block signBlock = player.getWorld().getBlockAt(player.getLocation().getBlockX(),
                    player.getLocation().getBlockY(),
                    player.getLocation().getBlockZ());
    
                signBlock.setType(Material.SIGN_POST);
    
                BlockState state = signBlock.getState();
    
                if (state instanceof Sign) {
                  Sign sign = (Sign)state;
                  sign.setLine((int)(Math.random() * 3), "some text" + Math.random());
                  //sign.update(true);
                  //signBlock.setData(signBlock.getData());
                }
              }
    Placed 5 signs and all of them instantly show the random text.

    The only glitch is, because the text is too long, it sticks over the borders of the sign. As soon as you reconnect the text will be cut but that is not really a problem as we should be aware of how many letters it can hold.

    I'm more interessted into a way to hook up when a sign is being placed by the player. It seems onBlockPlace() is not called for signs and if you use onBlockRightClick() you can't access the sign either, as it is placed after that event has been processed.
     
  9. Offline

    eisental

    Hmmm, I didn't test the code above again, but I found that my circuit works most of the time if I use a redstone torch to tell the plugin to update the text instead of a lever or button.
    This is getting weird :) but I guess it has to do with some bukkit bugs so I'm gonna leave it for the time being. I would file a bug report if I had any idea what was the problem
    Thanks anyway...
     
  10. Offline

    Chuck Lieb

    Previously, if you had more than 15 characters on a sign (including invisible characters like color codes), it would crash clients. This means that you couldn't even log in to remove the effected sign, as you would crash as soon as the sign loaded. While it would seem that Bukkit handles this better than hMod did, I would strongly suggest that you have a catch all plugin that removes any excess. Or, do as I did, and replace the entire line with a red "TOO LONG!"

    I had mine hooked into onSignShow, but, as there is no equivalent in Bukkit, yet, I don't know where you might put it.
     
  11. Offline

    eisental

    Don't worry, in my actual code I have many lines of code dealing with the the line formatting. I'm setting the max line length to 12 to make it look nice.
     
  12. Offline

    neron

    This keeps me bugging. It seemed to work in the local sandbox but on a server there are places where the sign just wont update (change only visible after reconnect), while at the same time if you move to a different place, it will update just fine.
     
  13. Offline

    mjmr89

    I'm having the same sort of problem as Neron. And when I update by either of the methods above, it somehow creates an infinite loop in my program, but I think thats because my code is a bit funky right now.
     
Thread Status:
Not open for further replies.

Share This Page