add /npc controllable -y | -n

This commit is contained in:
fullwall 2013-08-11 12:20:15 +08:00
parent 4b6191b705
commit 5c4af2f4b9
2 changed files with 48 additions and 37 deletions

View File

@ -203,12 +203,12 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "controllable|control -f",
usage = "controllable|control (-m,-y,-n)",
desc = "Toggles whether the NPC can be ridden and controlled",
modifiers = { "controllable", "control" },
min = 1,
max = 1,
flags = "m")
flags = "myn")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable."
+ npc.getBukkitEntity().getType().toString().toLowerCase()))
@ -219,6 +219,11 @@ public class NPCCommands {
}
Controllable trait = npc.getTrait(Controllable.class);
boolean enabled = trait.toggle();
if (args.hasFlag('y')) {
enabled = trait.setEnabled(true);
} else if (args.hasFlag('n')) {
enabled = trait.setEnabled(false);
}
String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;
Messaging.sendTr(sender, key, npc.getName());
if (enabled && args.hasFlag('m') && sender instanceof Player) {

View File

@ -168,8 +168,14 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
public void save(DataKey key) {
if (explicitType == null) {
key.removeKey("explicittype");
} else
} else {
key.setString("explicittype", explicitType.name());
}
}
public boolean setEnabled(boolean enabled) {
this.enabled = enabled;
return enabled;
}
private void setMountedYaw(EntityLiving handle) {
@ -220,40 +226,6 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
}
public class LookAirController implements MovementController {
boolean paused = false;
@Override
public void leftClick(PlayerInteractEvent event) {
paused = !paused;
}
@Override
public void rightClick(PlayerInteractEvent event) {
paused = !paused;
}
@Override
public void rightClickEntity(NPCRightClickEvent event) {
enterOrLeaveVehicle(event.getClicker());
}
@Override
public void run(Player rider) {
if (paused) {
getHandle().motY = 0.001;
return;
}
Vector dir = rider.getEyeLocation().getDirection();
dir.multiply(npc.getNavigator().getDefaultParameters().speedModifier());
EntityLiving handle = getHandle();
handle.motX = dir.getX();
handle.motY = dir.getY();
handle.motZ = dir.getZ();
setMountedYaw(handle);
}
}
public class GroundController implements MovementController {
private int jumpTicks = 0;
private double speed = 0.07D;
@ -298,6 +270,40 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
private static final float JUMP_VELOCITY = 0.6F;
}
public class LookAirController implements MovementController {
boolean paused = false;
@Override
public void leftClick(PlayerInteractEvent event) {
paused = !paused;
}
@Override
public void rightClick(PlayerInteractEvent event) {
paused = !paused;
}
@Override
public void rightClickEntity(NPCRightClickEvent event) {
enterOrLeaveVehicle(event.getClicker());
}
@Override
public void run(Player rider) {
if (paused) {
getHandle().motY = 0.001;
return;
}
Vector dir = rider.getEyeLocation().getDirection();
dir.multiply(npc.getNavigator().getDefaultParameters().speedModifier());
EntityLiving handle = getHandle();
handle.motX = dir.getX();
handle.motY = dir.getY();
handle.motZ = dir.getZ();
setMountedYaw(handle);
}
}
public static interface MovementController {
void leftClick(PlayerInteractEvent event);