Change a sign contents after obtaining Location?

Discussion in 'Plugin Development' started by Ninjasylaz, May 13, 2011.

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

    Ninjasylaz

    Title says it all, I'm fairly new to the Bukkit API(First plugin I'm working on). Though I can't seem to figure out how to change the contents of a Sign after obtaining it's Location and CraftBlock... I figured you would just be able to cast a CraftBlock to Sign but it cannot be done.

    Does anyone know how to do this?
     
  2. Offline

    Thomas Tan

    I'm guessing you're using onBlockPlace. Then you'll just take the BlockPlaceEvent and find the .getBlockPlaced().getState() and cast it to a (Sign), then getLine or getLines or setLine.
     
  3. Offline

    Ninjasylaz

    Ahh ok thanks. I tried making artificial event but it failed =(.

    Also I'm not using it from onBlockPlace, its a piece of code which can be called from wherever. It searches for signs(within certain areas) and then grabs the block from the World. But thanks for that, my mistake was not putting a getState() in when trying to cast.

    EDIT: Ok now just one more thing, how do I make the sign be updated to the players clients once the modifications are done? At current you can only see changed text once you relog.
     
  4. Offline

    Thomas Tan

    :) You obviously know more than me. I only checked the JavaDoc. Start from somewhere and just keep clicking.
     
  5. Offline

    Ninjasylaz

    If anyone could answer question in my second posts edit would be great =)
     
  6. Offline

    Thomas Tan

  7. Offline

    Ninjasylaz

    What u need help with? Got msn or skype?

    Well, I wasn't doing anything for a while. But World.refreshChunk(Block.getChunk().getX(), Block.getChunk().getZ()) seems to work, though I think it's an inefficient way of doing things. (Don't get me wrong it could be right.)
     
  8. Offline

    Thomas Tan

    Edited the post. I need help with finding if the damager is a player. What I want to do is record all damaging activity so if there is also another way to do it pleaase tell me.

    EDIT: Randy replied!
     
  9. Offline

    Ninjasylaz

    I think my way is a bit more clearer =s but I posted anyway
     
  10. Offline

    Shamebot

    ok i think it's
    Code:
    EntityPlayer ep = ((CraftPlayer)player).getHandle();
    ep.netServerHandler.sendPacket(new Packet130UpdateSign(x, y, z,astring));
    Where player is a Player object and astring a String[], x,y and z should be self speaking :D.
    You need to include the craftbukkit jar and maybe the minecraft_server.jar
     
  11. Offline

    nisovin

    You shouldn't need to use any CraftBukkit references for this... just send Sign.update(). It's always worked for me.
     
  12. Offline

    Shamebot

    Did it ? Because this indicates the server isn't sending the packet on its own:
    And I think both SimpleSignEdit and SpeedSign are sending it too.
     
  13. Offline

    nisovin

    Here's the code I'm using:
    Code:
            public void updateSign(Location loc, String[] lines) {
                    Material mat = loc.getBlock().getType();
                    if (mat == Material.SIGN_POST || mat == Material.WALL_SIGN) {
                            Sign sign = (Sign)loc.getBlock().getState();
                            for (int i = 0; i < lines.length; i++) {
                                    sign.setLine(i, lines[i]);
                            }
                            sign.update();
                    }
            }
    
    And that seems to work fine for me.
     
  14. Offline

    Shamebot

    Yeah, but I think his code should be similar, if he would't use Sign.update() the text wouldn't get applied and rejoining wouldn't help.
    You aren't using it in a sign update event, do you? Edit: Doesn' make a difference.
    Hmm maybe it depends on the craftbukkit version?
    Though I didn't see a commit related to signs lately, mabey I missed something.
     
  15. Offline

    nisovin

    That code is run from a Runnable, not an event. Also, I just checked SimpleSignEdit's source, and it is also just using sign.update().
     
  16. Offline

    Shamebot

    Ok THAT seems to make a difference: http://forums.bukkit.org/threads/the-sign-update-bug-continued.3819/#post-49426 (at least if your running it from the bukkit scheduler).

    Edit looks like the packet was removed from SimpleSignEdit, but there's still an import:
    "import net.minecraft.server.Packet130UpdateSign;"
    And he's using a runnable too.
     
Thread Status:
Not open for further replies.

Share This Page