diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 395be07e2..2558c27b1 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -18,6 +18,7 @@ import net.citizensnpcs.command.Requirements; import net.citizensnpcs.command.exception.CommandException; import net.citizensnpcs.command.exception.NoPermissionsException; import net.citizensnpcs.npc.CitizensNPCManager; +import net.citizensnpcs.npc.CitizensTraitManager; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.Powered; @@ -35,6 +36,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class NPCCommands { private final CharacterManager characterManager = CitizensAPI.getCharacterManager(); private final CitizensNPCManager npcManager; + private final CitizensTraitManager traitManager = (CitizensTraitManager) CitizensAPI.getTraitManager(); public NPCCommands(Citizens plugin) { npcManager = plugin.getNPCManager(); @@ -116,8 +118,8 @@ public class NPCCommands { // Initialize necessary traits create.getTrait(Owner.class).setOwner(player.getName()); create.getTrait(MobType.class).setType(type.toString()); - create.addTrait(new LookClose(create)); - create.addTrait(new Text(create)); + create.addTrait(traitManager.getTrait(LookClose.class, create)); + create.addTrait(traitManager.getTrait(Text.class, create)); create.spawn(player.getLocation()); npcManager.selectNPC(player, create); diff --git a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 36643a168..ddaa8f07c 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -28,8 +28,8 @@ import org.bukkit.inventory.Inventory; public abstract class CitizensNPC extends AbstractNPC { private final CitizensAI ai = new CitizensAI(this); private final CitizensNPCManager manager; - protected EntityLiving mcEntity; private final CitizensTraitManager traitManager; + protected EntityLiving mcEntity; protected CitizensNPC(CitizensNPCManager manager, int id, String name) { super(id, name); @@ -43,6 +43,7 @@ public abstract class CitizensNPC extends AbstractNPC { Bukkit.getLogger().log(Level.SEVERE, "Cannot register a null trait. Was it registered properly?"); return; } + if (trait instanceof Runnable) { runnables.add((Runnable) trait); if (traits.containsKey(trait.getClass())) @@ -52,6 +53,7 @@ public abstract class CitizensNPC extends AbstractNPC { Bukkit.getPluginManager().registerEvents((Listener) trait, null); // TODO: insert plugin instance somehow } + traits.put(trait.getClass(), trait); } @@ -179,8 +181,9 @@ public abstract class CitizensNPC extends AbstractNPC { if (trait == null) throw new NPCLoadException("No trait with the name '" + traitKey.name() + "' exists. Was it registered properly?"); + addTrait(trait); try { - trait.load(traitKey); + getTrait(trait.getClass()).load(traitKey); } catch (Exception ex) { Bukkit.getLogger().log( Level.SEVERE, @@ -189,7 +192,6 @@ public abstract class CitizensNPC extends AbstractNPC { + ex.getMessage()); ex.printStackTrace(); } - addTrait(trait); } // Spawn the NPC