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 ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.