SignChangeEvent getting the sign & assigning Metadata

Discussion in 'Plugin Development' started by CoderMusgrove, Jan 2, 2014.

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

    CoderMusgrove

    I'm working on a simple little minigame, and I have all of the arena stuff set up. Now at this point I want to implement signs to handle joining the minigame arenas as well.

    I have given some thought into how other gamemodes or minigames handle their signs, how when a player joins, the player count updates [ 0/12 players -> *joins* -> 1/12 players ]; So when I put it into thought on how to track the signs, and for when the server starts up and to set up the signs, why not use some Metadata?

    The problem is I have no idea how to get the sign in a SignChangeEvent. I see that it offers the getBlock() method, but that retrieves the block it is on (the WALL_SIGN at least, not sure about plain SIGN_POSTs) but there isn't a very easy way to get the sign that is placed, and has the custom text on it.

    I have a few parts to my question:
    1.) How would I get the sign involved in a SignChangeEvent?
    2.) Would it be good to use Metadata for arena signs (joining, amount of players, etc.)
    3.) If I shouldn't use Metadata, what should I use instead? Would you be able to provide an example?
     
  2. Offline

    Stealth2800

    You don't have to use a SignChangeEvent to change the contents of a sign. I have a class called 'BetterSign' in my library plugin, StBukkitLib, that makes it easier to deal with signs - setting lines and setting the orientation. Take a look at the source I linked.

    Basically, to edit a sign's lines outside of a SignChangeEvent, I:
    1) Get the block state
    2) Change the lines
    3) Update the block state

    Code:java
    1. org.bukkit.block.Sign sign = (Sign) block.getState(); //obviously check to see if the block is a sign first
    2. sign.setLine(0, "players"); //Set a line (or multiple, whatever you want)
    3. sign.update(); //update the BlockState to reflect changes
     
    McMhz likes this.
Thread Status:
Not open for further replies.

Share This Page