Java Reference
In-Depth Information
@Column(columnName = "y" , dataType = DataType.DOUBLE)
public double y;
@Column(columnName = "z" , dataType = DataType.DOUBLE)
public double z;
public AllPlayerLocations() {
super( "all_player_locations" );
public DataAccess getInstance() {
return new AllPlayerLocations();
Let's see how to use this code within a plugin.
Plugin: LocationSnapshot
Here's an example of using a DataAccess (in this case, AllPlayerLocations ) in a new
plugin, LocationSnapshot . For this plugin, we'll provide two new commands:
You might want to use this kind of feature as part of a competition, where
you can return all players back to their starting points at the end.
The savelocations command, as you'd expect, saves the current locations of all
online players to disk. loadlocations reads them back in and teleports everyone
back to those saved locations. We'll use Canary's Database functions with our
AllPlayerLocations DataAccess object to save and load a hash of Player s and Location s.
There are two main pieces to this plugin: saveLocations and loadLocations . To keep
things clean and start forming better habits, we'll put the code for each in its
own function.
The logic for savelocations will look like this:
private void saveLocations() {
List <Player> playerList = Canary.getServer().getPlayerList();
// For all players...
for (Player player : playerList) {
// Save the raw coordinates, not the Location
AllPlayerLocations apl = new AllPlayerLocations();
apl.player_name = player.getDisplayName();
Location loc = player.getLocation();
Search WWH ::

Custom Search