Java Reference
In-Depth Information
There are a few things you still need to write: the internal push_stack , pop_stack ,
and peek_stack functions, and the database functions, myRead and myWrite . You
can copy the equalsIsh function straight from the BackCmd plugin.
Let's get started on the internal stack functions first. We want to be able to
pass in a Location to the push, and get a Location back from the peek and pop,
so use the conversion functions locationToString and stringToLocation .
Go give that a try on your own first. When you're done, come check back here
and see if it looks close to this:
BackCmdSave/src/backcmdsave/SavedLocation.java
private void push_stack(Location loc) {
String s = locationToString(loc);
location_strings.add(s);
}
private Location peek_stack() {
if (location_strings.isEmpty()) {
return null;
}
String s = location_strings.get(location_strings.size()-1);
return stringToLocation(s);
}
private Location pop_stack() {
Location loc = peek_stack();
location_strings.remove(location_strings.size()-1);
return loc;
}
Make sure that much compiles, using build.sh as usual.
Add Save and Load to BackCmd
Now that you have a SavedLocation that knows how to push and pop individual
locations for a Player , it's time for you to add the code into BackCmd.java , which
will call them.
Open up BackCmd.java and start making the following changes:
•In onTeleport , delete all the code in the else portion of the block, and replace
it with code that creates a new SavedLocation and calls its push with the
player's location.
•In backCommand , get the location to teleport to by creating a new SavedLocation
and calling its pop to get the latest value.
The new plugin main class should end up looking like this:
 
 
 
Search WWH ::




Custom Search