diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 91cc8b203..2b6fec8ff 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -89,7 +89,9 @@ public class Citizens extends JavaPlugin { NPC npc = null; if (player != null && player.getMetadata("selected").size() > 0) npc = npcManager.getNPC(player.getMetadata("selected").get(0).asInt()); - + // TODO: change the args supplied to a context style system for + // flexibility (ie. adding more context in the future without + // changing everything) try { commands.execute(split, player, player == null ? sender : player, npc); } catch (ServerCommandException ex) { diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index a49ca08ed..17e9c63a3 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -86,25 +86,6 @@ public class NPCCommands { Messaging.send(player, "Age " + (trait.toggle() ? "locked" : "unlocked") + "."); } - @Command( - aliases = { "npc" }, - usage = "controllable", - desc = "Toggles whether the NPC can be ridden and controlled", - modifiers = { "controllable" }, - min = 2, - max = 2, - permission = "npc.controllable") - public void toggleControllable(CommandContext args, Player player, NPC npc) { - if (npc.hasTrait(Controllable.class)) { - npc.removeTrait(Controllable.class); - Messaging.send(player, StringHelper.wrap(npc.getName()) + " can no longer be controlled."); - } else { - npc.addTrait(traitManager.getTrait(Controllable.class, npc)); - Messaging.send(player, StringHelper.wrap(npc.getName()) + " can now be controlled."); - } - - } - @Command( aliases = { "npc" }, usage = "character [character]", @@ -469,6 +450,25 @@ public class NPCCommands { + " Use '/npc tphere' to teleport the NPC to your location."); } + @Command( + aliases = { "npc" }, + usage = "controllable", + desc = "Toggles whether the NPC can be ridden and controlled", + modifiers = { "controllable" }, + min = 1, + max = 1, + permission = "npc.controllable") + public void controllable(CommandContext args, Player player, NPC npc) { + if (npc.hasTrait(Controllable.class)) { + npc.removeTrait(Controllable.class); + Messaging.send(player, StringHelper.wrap(npc.getName()) + " can no longer be controlled."); + } else { + npc.addTrait(traitManager.getTrait(Controllable.class, npc)); + Messaging.send(player, StringHelper.wrap(npc.getName()) + " can now be controlled."); + } + + } + @Command( aliases = { "npc" }, usage = "tp", diff --git a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java index 51f4bfd3f..0b5646d85 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java @@ -60,7 +60,11 @@ public class CitizensTraitManager implements TraitManager { if (!CACHED_CTORS.containsKey(trait)) { try { + // TODO: perhaps replace this fixed constructor with a context + // class of sorts, which can have extra environment variables. constructor = trait.getConstructor(NPC.class); + if (constructor == null) + constructor = trait.getConstructor(CitizensNPC.class); constructor.setAccessible(true); } catch (Exception ex) { constructor = null; @@ -91,6 +95,8 @@ public class CitizensTraitManager implements TraitManager { if (!subEntry.getValue().equals(clazz)) continue; Trait trait = create(subEntry.getValue(), npc); + if (trait == null) + return null; trait.setName(subEntry.getKey()); trait.setPlugin(entry.getKey()); return (T) trait; diff --git a/src/main/java/net/citizensnpcs/trait/Controllable.java b/src/main/java/net/citizensnpcs/trait/Controllable.java index ffa72c3a9..07e4071cb 100644 --- a/src/main/java/net/citizensnpcs/trait/Controllable.java +++ b/src/main/java/net/citizensnpcs/trait/Controllable.java @@ -2,6 +2,7 @@ package net.citizensnpcs.trait; import net.citizensnpcs.api.event.NPCRightClickEvent; import net.citizensnpcs.api.exception.NPCLoadException; +import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.npc.CitizensNPC; @@ -17,8 +18,8 @@ import org.bukkit.event.player.PlayerInteractEvent; public class Controllable extends Trait implements Runnable, Listener { private final CitizensNPC npc; - public Controllable(CitizensNPC npc) { - this.npc = npc; + public Controllable(NPC npc) { + this.npc = (CitizensNPC) npc; } private void jump() {