Add some more TODOs, make TraitManager slightly more flexible with constructors, fix number of args for controllable

This commit is contained in:
fullwall 2012-04-20 22:19:03 +08:00
parent 8225f3e57b
commit 82da2c8beb
4 changed files with 31 additions and 22 deletions

View File

@ -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) {

View File

@ -86,25 +86,6 @@ public class NPCCommands {
Messaging.send(player, "<a>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",

View File

@ -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;

View File

@ -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() {