Set the default controllable behaviour to not require an owner (use the -o flag to require an owner)

This commit is contained in:
fullwall 2014-11-20 15:39:37 +08:00
parent 36b9a0c4c8
commit 8ae49480ae
2 changed files with 14 additions and 6 deletions

View File

@ -216,12 +216,12 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "controllable|control (-m,-y,-n)",
usage = "controllable|control (-m(ount),-y,-n,-o)",
desc = "Toggles whether the NPC can be ridden and controlled",
modifiers = { "controllable", "control" },
min = 1,
max = 1,
flags = "myn")
flags = "myno")
public void controllable(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
if ((npc.isSpawned() && !sender.hasPermission("citizens.npc.controllable."
+ npc.getEntity().getType().name().toLowerCase().replace("_", "")))
@ -237,6 +237,7 @@ public class NPCCommands {
} else if (args.hasFlag('n')) {
enabled = trait.setEnabled(false);
}
trait.setOwnerRequired(args.hasFlag('o'));
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

@ -36,6 +36,8 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
@Persist
private boolean enabled = true;
private EntityType explicitType;
@Persist("owner_required")
private boolean ownerRequired;
public Controllable() {
super("controllable");
@ -58,9 +60,10 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
explicitType = null;
} else if (args.hasValueFlag("explicittype"))
explicitType = Util.matchEntityType(args.getFlag("explicittype"));
if (npc.isSpawned())
if (npc.isSpawned()) {
loadController();
}
}
private void enterOrLeaveVehicle(Player player) {
EntityPlayer handle = ((CraftPlayer) player).getHandle();
@ -70,9 +73,10 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
}
return;
}
if (npc.getTrait(Owner.class).isOwnedBy(handle.getBukkitEntity())) {
handle.setPassengerOf(getHandle());
if (ownerRequired && !npc.getTrait(Owner.class).isOwnedBy(handle.getBukkitEntity())) {
return;
}
handle.setPassengerOf(getHandle());
}
private net.minecraft.server.v1_7_R4.Entity getHandle() {
@ -195,6 +199,10 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
NMS.setHeadYaw(handle, handle.yaw);
}
public void setOwnerRequired(boolean ownerRequired) {
this.ownerRequired = ownerRequired;
}
@Override
public boolean toggle() {
enabled = !enabled;
@ -360,7 +368,6 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
private static final Map<EntityType, Class<? extends MovementController>> controllerTypes = Maps
.newEnumMap(EntityType.class);
static {
controllerTypes.put(EntityType.BAT, PlayerInputAirController.class);
controllerTypes.put(EntityType.BLAZE, PlayerInputAirController.class);