Bugfix (may need changing later)

This commit is contained in:
fullwall 2012-02-28 19:25:42 +08:00
parent bf7b868a09
commit f42248a38e
2 changed files with 10 additions and 8 deletions

View File

@ -52,7 +52,6 @@ public class LinearWaypointProvider implements WaypointProvider {
@Override
public void load(DataKey key) {
waypoints.clear();
for (DataKey root : key.getRelative("waypoints").getIntegerSubKeys()) {
waypoints.add(new Waypoint(StorageUtils.loadLocation(root)));
}

View File

@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
public class Waypoints extends Trait {
private final NPC npc;
private String providerName;
private WaypointProvider provider;
private WaypointProvider provider = new LinearWaypointProvider();
public Waypoints(NPC npc) {
this.npc = npc;
@ -23,12 +23,10 @@ public class Waypoints extends Trait {
@Override
public void load(DataKey key) throws NPCLoadException {
if (provider == null) {
providerName = key.getString("provider", "linear");
provider = providers.getInstance(providerName);
if (provider == null)
return;
}
providerName = key.getString("provider", "linear");
provider = providers.getInstance(providerName);
if (provider == null)
return;
provider.load(key.getRelative(providerName));
npc.getAI().registerNavigationCallback(provider.getCallback());
}
@ -45,6 +43,11 @@ public class Waypoints extends Trait {
return provider.createEditor(player);
}
public void setWaypointProvider(WaypointProvider provider, String name) {
this.provider = provider;
providerName = name;
}
public static void registerWaypointProvider(Class<? extends WaypointProvider> clazz, String name) {
providers.register(clazz, name);
}