Java Reference
In-Depth Information
Location loc = signs.get(name);
World world = loc.getWorld();
Sign sign = (Sign)world.getTileEntity(world.getBlockAt(loc));
sign.setTextOnLine(msg, 0);
sign.update();
}
@Command(aliases = { "signs" },
description = "Create and name signposts" ,
permissions = { "" },
toolTip = "/signs new name, or /signs set name message" )
public void signsCommand(MessageReceiver caller, String[] args) {
if (caller instanceof Player) {
Player me = (Player)caller;
parseArgs(me, args);
}
}
}
There's a lot of code here, but it's really just a handful of simple parts and
things we've seen already. These are the major pieces:
•A private static HashMap at .
•A private helper function that returns nothing ( void ) at . This function
prints a usage message to the player. We'll call it if we find out the player
didn't type in the command correctly.
•A private helper function at . This function will create new signs.
•A private helper function at . This function will change the name on
existing signs.
•A check of the length of the args array on the lines at and . Since the
user may not have typed in enough words for us to use, we have to check
that the length is long enough and indicate an error otherwise.
•A wee bit of magic at . This is how the Canary docs say to get a Sign
object from a Block .
That's the gist of it. Now let's go through each of those pieces in detail.
The signs HashMap
First off, we set up a HashMap named signs to keep track of Locations by name (a
String ). When we're creating a new sign, we'll stuff its location in the hash,
using the name the user gave us. When we go to set text on a sign, we'll get
the sign's location back out of the hash by using the name.
 
 
Search WWH ::




Custom Search