Java Reference
In-Depth Information
getServer()
call returns something (it's actually a
Server
). Once we have that, we
can then call any of the
Server
's functions. In this case, we're calling the
Server
's
broadcastMessage()
function, passing in a string argument named
msg
. Take a
look at this line in action:
Canary.instance().getServer().broadcastMessage(msg);
Canary.instance()
.getServer()
instance
.broadcastMessage(msg);
server
To make it clearer, you could break up this chain of function calls into sepa-
rate pieces, which would look something like this:
instance = Canary.instance();
server = instance.getServer();
server.broadcastMessage(msg);
See? It's just a set of function calls. With me so far?
You can define a function yourself. Here's an example that defines a new
function named
castIntoBlackHole
. Watch closely, because you'll be doing this
on your own next.
public static void
castIntoBlackHole(
String
playerName)
{
// Do something interesting with the player here...
}
There is a bit more noise here than in the cake example. Let's see what all
this stuff means.
•
public
means that any other part of the program can use it, which for now
you want to be the case.
•
static
means you can call this function all by itself (not like a plugin; we'll
see the difference and what that means in the next chapter).
•
void
means this function is going to run a couple of instructions, but not
give you any data back—it won't “return” any values to the caller.