mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-28 20:17:50 +01:00
add /npc controllable -y | -n
This commit is contained in:
parent
4b6191b705
commit
5c4af2f4b9
@ -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) {
|
||||
|
@ -168,9 +168,15 @@ 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) {
|
||||
if (handle instanceof EntityEnderDragon || !Setting.USE_BOAT_CONTROLS.asBoolean())
|
||||
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user