Java Reference
In-Depth Information
like we've seen with @Command . Always start off an event handler with that
special annotation.
The function for the listener itself can be named anything you want (shown
here as anyname ). But the argument list is important: the type of event you list
here determines when this function will be called, or if it gets called at all.
An event handler for the TeleportHook would look like this:
public void myTeleportListener(TeleportHook event) {
// Some code here
I made up the name myTeleportListener , but that part doesn't matter—it's the
TeleportHook that's important. According to the documentation, this event hook
object has several interesting functions we can use:
Return the location the player is teleporting from
Get the location this player is teleporting to
Get the player
Lets you cancel this event
For instance, to prevent anything from teleporting anywhere, you could write
public void myTeleportListener(TeleportHook event) {
Plugin: BackCmd
Let's use some of these features in a complete plugin. Here's the full source
for BackCmd that provides a single command named back . Go ahead and build
and install it:
$ cd Desktop
$ cd code/BackCmd
$ ./
And restart the server.
Now teleport to a couple of locations, either by using the /tp command in cre-
ative mode or by right-clicking on an Ender Pearl in survival mode.
Now type /back , and you'll be teleported back to your last location.
Search WWH ::

Custom Search