mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-27 06:42:57 +02:00
Waypoints use PersistenceLoader now
This commit is contained in:
parent
c05e249440
commit
0ba1bd9f2c
@ -14,6 +14,7 @@ import net.citizensnpcs.api.ai.event.NavigationCompleteEvent;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.event.NPCRemoveEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.PersistenceLoader;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
@ -58,12 +59,10 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
@Override
|
||||
public void load(DataKey key) {
|
||||
for (DataKey root : key.getRelative("points").getIntegerSubKeys()) {
|
||||
root = root.getRelative("location");
|
||||
if (Bukkit.getWorld(root.getString("world")) == null)
|
||||
Waypoint waypoint = PersistenceLoader.load(Waypoint.class, root);
|
||||
if (waypoint == null)
|
||||
continue;
|
||||
waypoints.add(new Waypoint(new Location(Bukkit.getWorld(root.getString("world")), root
|
||||
.getDouble("x"), root.getDouble("y"), root.getDouble("z"), (float) root.getDouble("yaw",
|
||||
0), (float) root.getDouble("pitch", 0))));
|
||||
waypoints.add(waypoint);
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,16 +80,8 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
public void save(DataKey key) {
|
||||
key.removeKey("points");
|
||||
key = key.getRelative("points");
|
||||
for (int i = 0; i < waypoints.size(); ++i) {
|
||||
Location location = waypoints.get(i).getLocation();
|
||||
DataKey root = key.getRelative(Integer.toString(i) + ".location");
|
||||
root.setString("world", location.getWorld().getName());
|
||||
root.setDouble("x", location.getX());
|
||||
root.setDouble("y", location.getY());
|
||||
root.setDouble("z", location.getZ());
|
||||
root.setDouble("yaw", location.getYaw());
|
||||
root.setDouble("pitch", location.getPitch());
|
||||
}
|
||||
for (int i = 0; i < waypoints.size(); ++i)
|
||||
PersistenceLoader.save(waypoints.get(i), key.getRelative(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,15 +1,30 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.persistence.PersistenceLoader;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Waypoint {
|
||||
private final Location location;
|
||||
@Persist(required = true)
|
||||
private Location location;
|
||||
@Persist
|
||||
private List<WaypointTrigger> triggers;
|
||||
|
||||
public Waypoint(Location location) {
|
||||
this.location = location;
|
||||
public Waypoint() {
|
||||
}
|
||||
|
||||
public Waypoint(Location at) {
|
||||
location = at;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
static {
|
||||
PersistenceLoader.registerPersistDelegate(WaypointTrigger.class, WaypointTriggerPersister.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface WaypointTrigger {
|
||||
void onWaypointReached(NPC npc, Location waypoint);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persister;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
public class WaypointTriggerPersister implements Persister {
|
||||
@Override
|
||||
public Object create(DataKey root) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Object instance, DataKey root) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user