O'Reilly logo

Learn to Program with Minecraft Plugins, 2nd Edition by Andy Hunt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
 
$ ​./build.sh

And restart the server.

Now teleport to a couple of locations, either by using the /tp command in creative 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.

This plugin will listen for events to keep track of where you’ve been, and let you return to previous locations in order.

BackCmd/src/backcmd/BackCmd.java
 
package​ backcmd;
 
 
import​ java.util.ArrayList;
 
import​ java.util.HashMap;
 
import​ java.util.List;
 
import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required