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

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.