Java Reference
In-Depth Information
•Write a conversion function that takes a Location object and returns a string
that contains each coordinate, separated by “,” characters.
•Write a conversion function that takes a string of coordinates, separated
by “,” characters, and builds a Location object.
Now that's just a first pass at what you might need to do. As we go along,
other things might come up, and that's okay: that's how software development
really works.
And as you go along, don't be shy about adding logger.info() messages to help
trace what the plugin is doing.
Okay, you have your hands full. I'll get you started.
Create a SavedLocation Class
Since you can't save a stack of Location objects directly to disk, you need to
make an object that you can save to disk: a DataAccess object. You'll create a
SavedLocation that will save a list of strings for each player.
Let's get started writing some code. Go into the BackCmd plugin's src/backcmd
directory and create a new file named SavedLocation.java . The first thing you'll
need is a package statement and some imports.
The start of your SavedLocation class will look like this:
BackCmdSave/src/backcmdsave/SavedLocation.java
package backcmdsave;
import java.util.ArrayList;
import java.util.HashMap;
import net.canarymod.database.Column;
import net.canarymod.database.Column.DataType;
import net.canarymod.database.DataAccess;
import net.canarymod.database.exceptions.*;
import net.canarymod.api.entity.living.humanoid.Player;
import net.canarymod.api.world.position.Location;
import net.canarymod.api.world.World;
import net.canarymod.database.Database;
import net.canarymod.Canary;
public class SavedLocation extends DataAccess {
Copy that into your new file, or type it in as we go.
Next up you'll need to add the @Column annotations to describe the fields you
want to save in the database. Remember, you'll need two fields:
 
 
 
Search WWH ::




Custom Search