The Canary documentation tells us to call world.getTileEntity() on the block, and
then cast that using the cast operator (Sign) to make a proper sign. With the
sign variable in hand we can call the two Sign functions we need: setTextOnLine()
and update() .
setTextOnLine() puts a line of text on the sign at the given index (0 in this case),
and update() makes sure that the sign is redrawn in the client so you can see
the new text.
It might look like a fair bit of code, but if you look at each piece one at a time,
it's not so hard. In fact, now it's your turn to make some changes.
Try This Yourself
As we have it here, the plugin only sets the first line of the sign, but you can
have up to four lines per sign. Modify the plugin so that if the user types in
extra words, you'll pass each word to sign.setTextOnLine() . Remember: if it can
hold four lines, then they are numbered 0, 1, 2, and 3. We've got the setTextOn-
Line(msg,0) already, so you'll need to add the others if args is long enough.
In this chapter we've seen how to use a HashMap to keep track of important
game data by name or other object, and how to make functions private so that
other plugins can't access them, or public so that they can.
In the next chapter we'll do more than just respond to user commands. We'll
see how to listen to the Minecraft server and respond to game events as they
happen, and even create a few of our own.