Trouble updating signs

Discussion in 'Plugin Development' started by Bobcat00, Apr 15, 2014.

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

    Bobcat00

    I'm having trouble updating signs. It works 99% of the time, but sometimes the sign isn't updated. In the following code, line1, etc, are the lines on the sign, and arg[1], etc, are the sign's location. I dump out line and arg, and they're all correct. The calls to block.getType work, so it must be finding the sign correctly. The call to sign.update returns true. I can check the sign with another client, so it's not a client issue.

    So am I doing something wrong? Is this the correct way to update a sign? Is block.getState what I should be using?

    Code:
    Location loc = new Location(plugin.getServer().getWorld(arg[1]),
                                Double.valueOf(arg[2]),
                                Double.valueOf(arg[3]),
                                Double.valueOf(arg[4]));
     
    World world = loc.getWorld();
    Block block = world.getBlockAt(loc);
     
    if(block.getType() == Material.SIGN_POST ||
       block.getType() == Material.WALL_SIGN)
    {
        Sign sign = (Sign)block.getState();
        sign.setLine(0, line1);
        sign.setLine(1, line2);
        sign.setLine(2, line3);
        sign.setLine(3, line4);
        sign.update();
    }
    
     
  2. Should be working correctly, did you really double-checked all Parameters?
     
  3. Offline

    Bobcat00

    Johnny Crazy Yup I checked everything I mentioned, by dumping to the chat window and or the console:
    • sign lines (line...)
    • sign location (arg[])
    • the if statement works (is true)
    • sign.update returns true
    all correct even when the sign doesn't get updated.

    I'll keep looking at it in case I missed something. If anyone else has suggestions, let me know.

    It looks like it may be related to chunk loading/unloading. If I park a second player near the sign so the chunk stays loaded, the problem doesn't occur.

    This doesn't make a lot of sense to me, because the check for the block material is working. If the chunk wasn't loaded, how could that pass?

    In any case, how would I modify the above code to ensure the chunk is loaded? I'm not sure what methods to call.

    EDIT: Added calls to loc.getChunk and chunk.load, but it didn't help.

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

Share This Page