diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index bbf7b733e..60fd9ab3a 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -72,6 +72,23 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { } } + private void enableSubPlugins() { + File root = new File(getDataFolder(), Setting.SUBPLUGIN_FOLDER.asString()); + if (!root.exists() || !root.isDirectory()) + return; + Plugin[] plugins = Bukkit.getPluginManager().loadPlugins(root); + // code beneath modified from CraftServer + for (Plugin plugin : plugins) { + try { + Messaging.logF("Loading %s", plugin.getDescription().getFullName()); + plugin.onLoad(); + } catch (Throwable ex) { + Messaging.severe(ex.getMessage() + " initializing " + plugin.getDescription().getFullName()); + ex.printStackTrace(); + } + } + } + public Iterable getCommands(String base) { return commands.getCommands(base); } @@ -203,48 +220,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { Bukkit.getPluginManager().disablePlugin(this); } - private void enableSubPlugins() { - File root = new File(getDataFolder(), Setting.SUBPLUGIN_FOLDER.asString()); - if (!root.exists() || !root.isDirectory()) - return; - Plugin[] plugins = Bukkit.getPluginManager().loadPlugins(root); - // code beneath modified from CraftServer - for (Plugin plugin : plugins) { - try { - Messaging.logF("Loading %s", plugin.getDescription().getFullName()); - plugin.onLoad(); - } catch (Throwable ex) { - Messaging.severe(ex.getMessage() + " initializing " + plugin.getDescription().getFullName()); - ex.printStackTrace(); - } - } - } - - private void startMetrics() { - new Thread() { - @Override - public void run() { - try { - Metrics metrics = new Metrics(Citizens.this); - if (metrics.isOptOut()) - return; - metrics.addCustomData(new Metrics.Plotter("Total NPCs") { - @Override - public int getValue() { - return Iterables.size(npcRegistry); - } - }); - - traitFactory.addPlotters(metrics.createGraph("traits")); - metrics.start(); - Messaging.log("Metrics started."); - } catch (IOException e) { - Messaging.logF("Unable to start metrics: %s.", e.getMessage()); - } - } - }.start(); - } - private void registerCommands() { commands.setInjector(new Injector(this)); @@ -340,6 +315,31 @@ public class Citizens extends JavaPlugin implements CitizensPlugin { Messaging.logF("Save method set to %s.", saves.toString()); } + private void startMetrics() { + new Thread() { + @Override + public void run() { + try { + Metrics metrics = new Metrics(Citizens.this); + if (metrics.isOptOut()) + return; + metrics.addCustomData(new Metrics.Plotter("Total NPCs") { + @Override + public int getValue() { + return Iterables.size(npcRegistry); + } + }); + + traitFactory.addPlotters(metrics.createGraph("traits")); + metrics.start(); + Messaging.log("Metrics started."); + } catch (IOException e) { + Messaging.logF("Unable to start metrics: %s.", e.getMessage()); + } + } + }.start(); + } + private boolean suggestClosestModifier(CommandSender sender, String command, String modifier) { int minDist = Integer.MAX_VALUE; String closest = ""; diff --git a/src/main/java/net/citizensnpcs/Settings.java b/src/main/java/net/citizensnpcs/Settings.java index 225764757..bc26cd53e 100644 --- a/src/main/java/net/citizensnpcs/Settings.java +++ b/src/main/java/net/citizensnpcs/Settings.java @@ -69,10 +69,10 @@ public class Settings { SERVER_OWNS_NPCS("npc.server-ownership", false), STORAGE_FILE("storage.file", "saves.yml"), STORAGE_TYPE("storage.type", "yaml"), + SUBPLUGIN_FOLDER("subplugins.folder", "plugins"), TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60), TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30), - TALK_ITEM("npc.text.talk-item", "340"), - SUBPLUGIN_FOLDER("subplugins.folder", "plugins"); + TALK_ITEM("npc.text.talk-item", "340"); protected String path; protected Object value; diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 820a86f94..9e0c8c6e7 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -140,7 +140,8 @@ public abstract class CitizensNPC extends AbstractNPC { public void update() { try { super.update(); - navigator.update(); + if (isSpawned()) + navigator.update(); } catch (Exception ex) { Messaging.logF("Exception while updating %d: %s.", getId(), ex.getMessage()); ex.printStackTrace(); diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 90c9c7b1b..e036ce185 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -20,25 +20,15 @@ import org.bukkit.entity.LivingEntity; import com.google.common.collect.Maps; public class CitizensNavigator implements Navigator { + private PathStrategy executing; private final CitizensNPC npc; private float speed; - private PathStrategy executing; public CitizensNavigator(CitizensNPC npc) { this.npc = npc; this.speed = getSpeedFor(npc.getHandle()); } - public void update() { - if (executing == null) - return; - boolean finished = executing.update(); - if (finished) { - Bukkit.getPluginManager().callEvent(new NavigationCompleteEvent(this)); - executing = null; - } - } - @Override public void cancelNavigation() { if (executing != null) { @@ -47,14 +37,33 @@ public class CitizensNavigator implements Navigator { executing = null; } + @Override + public EntityTarget getEntityTarget() { + return executing instanceof EntityTarget ? (EntityTarget) executing : null; + } + @Override public float getSpeed() { return speed; } - @Override - public EntityTarget getEntityTarget() { - return executing instanceof EntityTarget ? (EntityTarget) executing : null; + private float getSpeedFor(EntityLiving from) { + EntityType entityType = from.getBukkitEntity().getType(); + Float cached = MOVEMENT_SPEEDS.get(entityType); + if (cached != null) + return cached; + if (SPEED_FIELD == null) { + MOVEMENT_SPEEDS.put(entityType, DEFAULT_SPEED); + return DEFAULT_SPEED; + } + try { + float speed = SPEED_FIELD.getFloat(from); + MOVEMENT_SPEEDS.put(entityType, speed); + return speed; + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + return DEFAULT_SPEED; + } } @Override @@ -83,6 +92,12 @@ public class CitizensNavigator implements Navigator { switchStrategyTo(newStrategy); } + @Override + public void setTarget(Location target) { + PathStrategy newStrategy = new MCNavigationStrategy(npc, target, speed); + switchStrategyTo(newStrategy); + } + private void switchStrategyTo(PathStrategy newStrategy) { if (executing != null) Bukkit.getPluginManager().callEvent(new NavigationReplaceEvent(this)); @@ -92,28 +107,13 @@ public class CitizensNavigator implements Navigator { Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this)); } - @Override - public void setTarget(Location target) { - PathStrategy newStrategy = new MCNavigationStrategy(npc, target, speed); - switchStrategyTo(newStrategy); - } - - private float getSpeedFor(EntityLiving from) { - EntityType entityType = from.getBukkitEntity().getType(); - Float cached = MOVEMENT_SPEEDS.get(entityType); - if (cached != null) - return cached; - if (SPEED_FIELD == null) { - MOVEMENT_SPEEDS.put(entityType, DEFAULT_SPEED); - return DEFAULT_SPEED; - } - try { - float speed = SPEED_FIELD.getFloat(from); - MOVEMENT_SPEEDS.put(entityType, speed); - return speed; - } catch (IllegalAccessException ex) { - ex.printStackTrace(); - return DEFAULT_SPEED; + public void update() { + if (executing == null) + return; + boolean finished = executing.update(); + if (finished) { + Bukkit.getPluginManager().callEvent(new NavigationCompleteEvent(this)); + executing = null; } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index e2e9fa698..3d4d5de46 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -34,11 +34,6 @@ public class MCNavigationStrategy implements PathStrategy { navigation = entity.al(); } - @Override - public boolean update() { - return navigation.e(); - } - @Override public Location getTargetAsLocation() { return target; @@ -48,4 +43,9 @@ public class MCNavigationStrategy implements PathStrategy { public TargetType getTargetType() { return TargetType.LOCATION; } + + @Override + public boolean update() { + return navigation.e(); + } } diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 924c7f9ef..e84446ce9 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -35,6 +35,26 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { return handle.getBukkitEntity().getLocation().distanceSquared(target.getBukkitEntity().getLocation()); } + @Override + public LivingEntity getTarget() { + return (LivingEntity) target.getBukkitEntity(); + } + + @Override + public Location getTargetAsLocation() { + return getTarget().getLocation(); + } + + @Override + public TargetType getTargetType() { + return TargetType.ENTITY; + } + + @Override + public boolean isAggressive() { + return aggro; + } + @Override public boolean update() { if (target == null || target.dead) @@ -57,24 +77,4 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { } private static final double ATTACK_DISTANCE = 1.75 * 1.75; - - @Override - public LivingEntity getTarget() { - return (LivingEntity) target.getBukkitEntity(); - } - - @Override - public boolean isAggressive() { - return aggro; - } - - @Override - public Location getTargetAsLocation() { - return getTarget().getLocation(); - } - - @Override - public TargetType getTargetType() { - return TargetType.ENTITY; - } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java index 3d4144848..43ea83e69 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/PathStrategy.java @@ -5,9 +5,9 @@ import net.citizensnpcs.api.ai.TargetType; import org.bukkit.Location; public interface PathStrategy { - boolean update(); - Location getTargetAsLocation(); TargetType getTargetType(); + + boolean update(); } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java index 98b5d639d..8efab604e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensBlazeNPC.java @@ -37,6 +37,12 @@ public class CitizensBlazeNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc != null) @@ -49,11 +55,5 @@ public class CitizensBlazeNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java index f4e42add5..b3fe519fb 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCaveSpiderNPC.java @@ -33,6 +33,12 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -43,11 +49,5 @@ public class CitizensCaveSpiderNPC extends CitizensMobNPC { super.z_(); npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java index 4e8c37b54..c6108dee7 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensChickenNPC.java @@ -37,6 +37,12 @@ public class CitizensChickenNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensChickenNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java index 387c12be3..bf2bed91b 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCowNPC.java @@ -37,6 +37,12 @@ public class CitizensCowNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensCowNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java index 98f4db3ab..1c9c7b137 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensCreeperNPC.java @@ -44,6 +44,12 @@ public class CitizensCreeperNPC extends CitizensMobNPC { super.a(entityweatherlighting); } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -55,11 +61,5 @@ public class CitizensCreeperNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java index 21ee64e25..0970dfb04 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEnderDragonNPC.java @@ -33,6 +33,12 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc == null) @@ -51,11 +57,5 @@ public class CitizensEnderDragonNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java index 310890f31..c85df1657 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensEndermanNPC.java @@ -75,6 +75,12 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc == null) @@ -93,11 +99,5 @@ public class CitizensEndermanNPC extends CitizensMobNPC implements Equipable { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java index 62526d27f..6cf0c1f86 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGhastNPC.java @@ -37,6 +37,12 @@ public class CitizensGhastNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc != null) @@ -49,11 +55,5 @@ public class CitizensGhastNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java index 0c5050f39..80163f369 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensGiantNPC.java @@ -33,6 +33,12 @@ public class CitizensGiantNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { npc.update(); @@ -42,11 +48,5 @@ public class CitizensGiantNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java index f3ace3910..6f3f40002 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensIronGolemNPC.java @@ -33,6 +33,12 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -44,11 +50,5 @@ public class CitizensIronGolemNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java index c4ce98771..e554bdf84 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMagmaCubeNPC.java @@ -38,6 +38,12 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc != null) @@ -50,11 +56,5 @@ public class CitizensMagmaCubeNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java index 1de97fc46..420a861bc 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensMushroomCowNPC.java @@ -37,6 +37,12 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensMushroomCowNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java index a620ddeab..fd3d6148a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensOcelotNPC.java @@ -37,6 +37,12 @@ public class CitizensOcelotNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensOcelotNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java index bb7ac7b77..936cba18f 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigNPC.java @@ -70,6 +70,12 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { super.a(entityweatherlighting); } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -81,11 +87,5 @@ public class CitizensPigNPC extends CitizensMobNPC implements Equipable { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java index 435433822..c1303cec5 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensPigZombieNPC.java @@ -37,6 +37,12 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc != null) @@ -49,11 +55,5 @@ public class CitizensPigZombieNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java index 167779da4..1d5d18248 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSheepNPC.java @@ -75,6 +75,12 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -86,11 +92,5 @@ public class CitizensSheepNPC extends CitizensMobNPC implements Equipable { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java index 2139cda36..22b4c4f69 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSilverfishNPC.java @@ -37,6 +37,12 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensSilverfishNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java index d1c44b8cf..999633fdd 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSkeletonNPC.java @@ -37,6 +37,12 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensSkeletonNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java index 133b44077..c753daec5 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSlimeNPC.java @@ -38,6 +38,12 @@ public class CitizensSlimeNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -49,11 +55,5 @@ public class CitizensSlimeNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java index 75c764b0b..93d8d76a3 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSnowmanNPC.java @@ -33,6 +33,12 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -43,11 +49,5 @@ public class CitizensSnowmanNPC extends CitizensMobNPC { super.z_(); npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java index fce102fbe..6edf1983a 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSpiderNPC.java @@ -37,6 +37,12 @@ public class CitizensSpiderNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensSpiderNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java index 47cf51c21..336545bc2 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensSquidNPC.java @@ -37,6 +37,12 @@ public class CitizensSquidNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void d_() { if (npc != null) @@ -49,11 +55,5 @@ public class CitizensSquidNPC extends CitizensMobNPC { public NPC getNPC() { return npc; } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java index 02c88c347..6f9f15dc9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensVillagerNPC.java @@ -37,6 +37,12 @@ public class CitizensVillagerNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensVillagerNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java index 0a7e9e09f..09e6a3464 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensWolfNPC.java @@ -37,6 +37,12 @@ public class CitizensWolfNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensWolfNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java index ef1ddcc11..137e2b336 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/CitizensZombieNPC.java @@ -37,6 +37,12 @@ public class CitizensZombieNPC extends CitizensMobNPC { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public NPC getNPC() { return npc; @@ -48,11 +54,5 @@ public class CitizensZombieNPC extends CitizensMobNPC { if (npc != null) npc.update(); } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index a49358b50..2dc95065e 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -42,6 +42,12 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { } } + @Override + public void b_(double x, double y, double z) { + // when another entity collides, b_ is called to push the NPC + // so we prevent b_ from doing anything. + } + @Override public void F_() { super.F_(); @@ -81,10 +87,4 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { a(aW, aX); X = yaw; // TODO: this looks jerky } - - @Override - public void b_(double x, double y, double z) { - // when another entity collides, b_ is called to push the NPC - // so we prevent b_ from doing anything. - } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/trait/Behaviour.java b/src/main/java/net/citizensnpcs/trait/Behaviour.java index 4b22d02b6..1f3759d86 100644 --- a/src/main/java/net/citizensnpcs/trait/Behaviour.java +++ b/src/main/java/net/citizensnpcs/trait/Behaviour.java @@ -56,6 +56,11 @@ public class Behaviour extends Trait { addScripts(Splitter.on(",").split(scripts)); } + @Override + public void onRemove() { + removeGoals(); + } + @Override public void onSpawn() { for (Entry entry : addedGoals.entrySet()) { @@ -63,11 +68,6 @@ public class Behaviour extends Trait { } } - @Override - public void onRemove() { - removeGoals(); - } - private void removeGoals() { for (Goal entry : addedGoals.keySet()) { npc.getDefaultGoalController().removeGoal(entry); diff --git a/src/main/java/net/citizensnpcs/trait/Saddle.java b/src/main/java/net/citizensnpcs/trait/Saddle.java index 86c22bc29..cb7053b82 100644 --- a/src/main/java/net/citizensnpcs/trait/Saddle.java +++ b/src/main/java/net/citizensnpcs/trait/Saddle.java @@ -22,6 +22,12 @@ public class Saddle extends Trait implements Toggleable { saddle = key.getBoolean(""); } + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (pig && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))) + event.setCancelled(true); + } + @Override public void onSpawn() { if (npc.getBukkitEntity() instanceof Pig) { @@ -31,12 +37,6 @@ public class Saddle extends Trait implements Toggleable { pig = false; } - @EventHandler - public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { - if (pig && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))) - event.setCancelled(true); - } - @Override public void save(DataKey key) { key.setBoolean("", saddle); diff --git a/src/main/java/net/citizensnpcs/trait/Sheared.java b/src/main/java/net/citizensnpcs/trait/Sheared.java index e116c979a..71b821d98 100644 --- a/src/main/java/net/citizensnpcs/trait/Sheared.java +++ b/src/main/java/net/citizensnpcs/trait/Sheared.java @@ -21,17 +21,17 @@ public class Sheared extends Trait implements Toggleable { sheared = key.getBoolean(""); } - @Override - public void onSpawn() { - ((Sheep) npc.getBukkitEntity()).setSheared(sheared); - } - @EventHandler public void onPlayerShearEntityEvent(PlayerShearEntityEvent event) { if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()))) event.setCancelled(true); } + @Override + public void onSpawn() { + ((Sheep) npc.getBukkitEntity()).setSheared(sheared); + } + @Override public void save(DataKey key) { key.setBoolean("", sheared); diff --git a/src/main/java/net/citizensnpcs/trait/WoolColor.java b/src/main/java/net/citizensnpcs/trait/WoolColor.java index e3006428c..3ffab5102 100644 --- a/src/main/java/net/citizensnpcs/trait/WoolColor.java +++ b/src/main/java/net/citizensnpcs/trait/WoolColor.java @@ -27,6 +27,12 @@ public class WoolColor extends Trait { } } + @EventHandler + public void onSheepDyeWool(SheepDyeWoolEvent event) { + if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()))) + event.setCancelled(true); + } + @Override public void onSpawn() { if (npc.getBukkitEntity() instanceof Sheep) { @@ -36,12 +42,6 @@ public class WoolColor extends Trait { sheep = false; } - @EventHandler - public void onSheepDyeWool(SheepDyeWoolEvent event) { - if (npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getEntity()))) - event.setCancelled(true); - } - @Override public void save(DataKey key) { key.setString("", color.name()); diff --git a/src/main/java/net/citizensnpcs/trait/text/Text.java b/src/main/java/net/citizensnpcs/trait/text/Text.java index 44dc9bf68..135d68fd3 100644 --- a/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -95,12 +95,6 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve randomTalker = key.getBoolean("random-talker"); } - @Override - public void onSpawn() { - if (text.isEmpty()) - populateDefaultText(); - } - @EventHandler public void onRightClick(NPCRightClickEvent event) { if (!event.getNPC().equals(npc)) @@ -109,6 +103,12 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve sendText(event.getClicker()); } + @Override + public void onSpawn() { + if (text.isEmpty()) + populateDefaultText(); + } + private void populateDefaultText() { text.addAll(Setting.DEFAULT_TEXT.asList()); } diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index f467325ea..d786f77a8 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -3,6 +3,8 @@ package net.citizensnpcs.trait.waypoint; import java.util.Iterator; import java.util.List; +import net.citizensnpcs.api.ai.Goal; +import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.editor.Editor; import net.citizensnpcs.util.Messaging; @@ -20,7 +22,7 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import com.google.common.collect.Lists; public class LinearWaypointProvider implements WaypointProvider, Iterable { - private final PassiveWaypointCycler cycler = new PassiveWaypointCycler(this); + private WaypointGoal currentGoal; private final List waypoints = Lists.newArrayList(); @Override @@ -67,7 +69,7 @@ public class LinearWaypointProvider implements WaypointProvider, IterableRemoved a waypoint (%d remaining) (%d)", waypoints.size(), editingSlot + 1)); } - cycler.onProviderChanged(); + currentGoal.onProviderChanged(); } @EventHandler @@ -98,6 +100,13 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable iterator() { return waypoints.iterator(); @@ -113,11 +122,6 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable itr; - - private final Iterable provider; - - public PassiveWaypointCycler(Iterable provider) { - this.provider = provider; - } - - private void ensureItr() { - if (itr == null || !itr.hasNext()) { - itr = provider.iterator(); - } - } - - /*@Override - public boolean onCancel(AI ai, CancelReason reason) { - if (hackfix) { - hackfix = false; - return false; - } - hackfix = false; - if (executing && reason == CancelReason.REPLACE) { - executing = false; - return false; - } - executing = true; - ensureItr(); - if (dest == null && itr.hasNext()) - dest = itr.next().getLocation(); - if (dest != null) { - hackfix = true; - ai.setDestination(dest); - hackfix = false; - } - return false; - } - - @Override - public boolean onCompletion(AI ai) { - if (executing) { // if we're executing, we need to get the next waypoint - ensureItr(); - dest = itr.hasNext() ? itr.next().getLocation() : null; - } else { - executing = true; - // we're free to return to our waypoints! - // if we had a destination, we will return to it. - } - if (dest != null) { - ai.setDestination(dest); - } - return false; - } - - public void onProviderChanged() { - itr = provider.iterator(); - if (ai == null) - return; - dest = itr.hasNext() ? itr.next().getLocation() : null; - if (dest != null) { - ai.setDestination(dest); - } - }*/ - - public void onProviderChanged() { - } -} diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/WaypointGoal.java b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointGoal.java new file mode 100644 index 000000000..cd01e2661 --- /dev/null +++ b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointGoal.java @@ -0,0 +1,66 @@ +package net.citizensnpcs.trait.waypoint; + +import java.util.Iterator; + +import net.citizensnpcs.api.ai.Goal; +import net.citizensnpcs.api.ai.GoalSelector; +import net.citizensnpcs.api.ai.Navigator; +import net.citizensnpcs.api.ai.event.NavigationCancelEvent; + +import org.bukkit.Location; +import org.bukkit.event.EventHandler; + +public class WaypointGoal implements Goal { + private Location currentDestination; + private Iterator itr; + private final Navigator navigator; + private final Iterable provider; + private GoalSelector selector; + + public WaypointGoal(Iterable provider, Navigator navigator) { + this.provider = provider; + this.navigator = navigator; + } + + private void ensureItr() { + if (itr == null || !itr.hasNext()) { + itr = provider.iterator(); + } + } + + @EventHandler + public void onNavigationCancel(NavigationCancelEvent event) { + if (!event.getNavigator().equals(navigator) || currentDestination == null) + return; + if (currentDestination.equals(event.getNavigator().getTargetAsLocation())) + selector.finish(); + } + + public void onProviderChanged() { + itr = provider.iterator(); + if (currentDestination != null) + selector.finish(); + } + + @Override + public void reset() { + currentDestination = null; + selector = null; + } + + @Override + public void run() { + } + + @Override + public boolean shouldExecute(GoalSelector selector) { + ensureItr(); + boolean shouldExecute = itr.hasNext(); + if (shouldExecute) { + this.selector = selector; + currentDestination = itr.next().getLocation(); + navigator.setTarget(currentDestination); + } + return shouldExecute; + } +} diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java index ed48f1c66..c45194bc6 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/WaypointProvider.java @@ -1,5 +1,7 @@ package net.citizensnpcs.trait.waypoint; +import net.citizensnpcs.api.ai.Goal; +import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.editor.Editor; @@ -16,6 +18,14 @@ public interface WaypointProvider { */ public Editor createEditor(Player player); + /** + * + * @param npc + * The attached {@link NPC} the goal is for. + * @return The {@link Goal} to attach to the NPC. + */ + public Goal getGoal(NPC npc); + /** * Loads from the specified {@link DataKey}. * @@ -24,12 +34,6 @@ public interface WaypointProvider { */ public void load(DataKey key); - /** - * Called when the NPC attached to this provider's {@link Waypoints} is - * spawned. - */ - public void onSpawn(); - /** * Saves to the specified {@link DataKey}. * diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java index 10ec896e7..87ac7d354 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; +import net.citizensnpcs.api.ai.Goal; import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.util.DataKey; @@ -50,8 +51,10 @@ public class Waypoints extends Trait { @Override public void onSpawn() { - if (provider != null) - provider.onSpawn(); + if (provider != null) { + Goal goal = provider.getGoal(getNPC()); + getNPC().getDefaultGoalController().addGoal(goal, 1); + } } @Override