Skip to content

Commit

Permalink
Set the default controllable behaviour to not require an owner (use t…
Browse files Browse the repository at this point in the history
…he -o flag to require an owner)
  • Loading branch information
fullwall committed Nov 20, 2014
1 parent 1147372 commit e4bb5f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -216,12 +216,12 @@ public void anchor(CommandContext args, CommandSender sender, NPC npc) throws Co

@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("_", "")))
Expand All @@ -237,6 +237,7 @@ public void controllable(CommandContext args, CommandSender sender, NPC npc) thr
} 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) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/citizensnpcs/trait/Controllable.java
Expand Up @@ -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");
Expand All @@ -58,8 +60,9 @@ public void configure(CommandContext args) {
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) {
Expand All @@ -70,9 +73,10 @@ private void enterOrLeaveVehicle(Player player) {
}
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() {
Expand Down Expand Up @@ -195,6 +199,10 @@ private void setMountedYaw(net.minecraft.server.v1_7_R4.Entity handle) {
NMS.setHeadYaw(handle, handle.yaw);
}

public void setOwnerRequired(boolean ownerRequired) {
this.ownerRequired = ownerRequired;
}

@Override
public boolean toggle() {
enabled = !enabled;
Expand Down Expand Up @@ -360,7 +368,6 @@ public static void registerControllerType(EntityType type, Class<? extends Movem

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);
Expand Down

0 comments on commit e4bb5f6

Please sign in to comment.