Allow any entity type to be controlled as a flyable npc

This commit is contained in:
fullwall 2012-10-15 16:55:13 +08:00
parent 9fcb6214e0
commit 5b629638d7
3 changed files with 14 additions and 4 deletions

View File

@ -202,14 +202,16 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "controllable|control",
usage = "controllable|control -f",
desc = "Toggles whether the NPC can be ridden and controlled",
modifiers = { "controllable", "control" },
min = 1,
max = 1,
flags = "f",
permission = "npc.controllable")
public void controllable(CommandContext args, CommandSender sender, NPC npc) {
boolean enabled = npc.getTrait(Controllable.class).toggle();
Controllable trait = npc.getTrait(Controllable.class);
boolean enabled = trait.toggle();
String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;
Messaging.sendTr(sender, key);
}

View File

@ -57,7 +57,7 @@ public class TraitCommands {
}
@Command(
aliases = { "traitc", "trc", "tc" },
aliases = { "traitc", "trc" },
usage = "[trait name] [flags]",
desc = "Configures a trait",
modifiers = { "*" },

View File

@ -7,6 +7,8 @@ import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.command.CommandConfigurable;
import net.citizensnpcs.command.CommandContext;
import net.minecraft.server.EntityLiving;
import net.minecraft.server.EntityPlayer;
@ -22,7 +24,7 @@ import org.bukkit.util.Vector;
import com.google.common.collect.Maps;
//TODO: reduce reliance on CitizensNPC
public class Controllable extends Trait implements Toggleable {
public class Controllable extends Trait implements Toggleable, CommandConfigurable {
private Controller controller = new GroundController();
private boolean enabled;
@ -224,4 +226,10 @@ public class Controllable extends Trait implements Toggleable {
controllerTypes.put(EntityType.ENDER_DRAGON, AirController.class);
controllerTypes.put(EntityType.GHAST, AirController.class);
}
@Override
public void configure(CommandContext args) {
if (args.hasFlag('f'))
controller = new AirController();
}
}