Java Reference
In-Depth Information
Don't be discouraged if this looks like space-alien speech or Elvish right now.
We'll make sense out of it over the next several chapters. Instead focus on
what is familiar: there are some English words in there, like “import” and
“public” and “return,” and what might be sentences or statements of some
kind, which all end with semicolons (“;”). There are also some strange charac-
ters like “{” and “}” that seem to be important.
What does it all mean? Well, this plugin implements a user command, /hello ,
which will broadcast the traditional creeper greeting, “That'sss a very niccce
EVERYTHING you have there…” to all online players in Minecraft.
Notice that the name of this plugin is declared as public class HelloWorld on the
line at . That's the same name as the file name that contains this code:
HelloWorld.java . This piece of code is also set up to be in a package —that is, a
group of related files—using the same name on the line at . The package
name is all lowercase, and it's also the directory name where our Java source
code file lives, under src/ in helloworld/HelloWorld.java .
It's important that the names in all of these places match; a typo on one of
them can lead to strange errors.
You use import statements (you'll see these beginning on the line at ) to get
access to other things that you need in your plugin, like parts of the Canary
library and other Java libraries. If you forget to include an import for something
you need, you'll get an error that says “cannot find symbol” because Java
doesn't know what you mean. For your convenience, I've included a list of all
the imports we're using in Appendix 7, Common Imports , on page 253 .
The code for our plugin starts at , and there's this funny @Command annota-
tion (a kind of a tag, not actual code) at that describes the command itself.
Finally, the code for that command starts at .
We'll look at all that and more later, but first, we need to let the server know
that we've got a plugin for it to load.
Configure with Canary.inf
This source code alone isn't enough; you also need a configuration file so that
Minecraft can find and launch your plugin. The configuration file is named
Canary.inf and looks like this:
HelloWorld/Canary.inf
main-class = helloworld.HelloWorld
name = HelloWorld
author = AndyHunt, Learn to Program with Minecraft Plugins
version = 1.0
 
 
Search WWH ::




Custom Search