Your problem is the Location
is not serializable:
java.io.NotSerializableException: org.bukkit.Location
To make it serializable, first convert it to a string: worldName
,x
,y
,z
, which you could do using this:
public String locationToString(Location l){
String world = l.getWorld().getName(); //get the world name
Double x = l.getX(); //get the x coordinate
Double y = l.getY(); //get the y coordinate
Double z = l.getZ(); //get the z coordinate
return world + "," + x + "," + y + "," + z; //return the location, but in string form
}
Then, if you wanted to get the location from the string, you could do:
public Location stringToLocation(String s){
String[] str = s.split(","); //split s by ','
World world = Bukkit.getWorld(str[0]); //get the world
Double x = Double.parseDouble(str[1]); //get the x coord
Double y = Double.parseDouble(str[2]); //get the y coord
Double z = Double.parseDouble(str[3]); //get the z coord
return new Location(world, x, y, z); //return a location created from the String
}
By doing this, you have now converted a Location
to a String
, using locationToString()
which you can put in an Array, then, you can take the String
out of the Array, and convert it to a Location
using stringToLocation()
.