List profession/rabbit type values using the pretty formatter

This commit is contained in:
fullwall 2022-01-27 10:48:52 +08:00
parent 77aa63f1ff
commit 927d27e09c
3 changed files with 8 additions and 13 deletions

View File

@ -1697,7 +1697,7 @@ public class NPCCommands {
Profession parsed = Util.matchEnum(Profession.values(), profession.toUpperCase());
if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
Joiner.on(',').join(Profession.values()));
Util.listValuesPretty(Profession.values()));
}
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
@ -1716,7 +1716,7 @@ public class NPCCommands {
try {
type = Rabbit.Type.valueOf(args.getString(1).toUpperCase());
} catch (IllegalArgumentException ex) {
throw new CommandException(Messages.INVALID_RABBIT_TYPE, Joiner.on(',').join(Rabbit.Type.values()));
throw new CommandException(Messages.INVALID_RABBIT_TYPE, Util.listValuesPretty(Rabbit.Type.values()));
}
npc.getOrAddTrait(RabbitType.class).setType(type);
Messaging.sendTr(sender, Messages.RABBIT_TYPE_SET, npc.getName(), type.name());

View File

@ -18,7 +18,6 @@ import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
public class MCNavigationStrategy extends AbstractPathStrategy {
private Location centerLocation;
private final Entity handle;
private final MCNavigator navigator;
private final NavigatorParameters parameters;
@ -38,10 +37,10 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
if (!MinecraftBlockExaminer.canStandIn(dest.getBlock().getType())) {
dest = MinecraftBlockExaminer.findValidLocationAbove(dest, 2);
}
this.target = dest;
this.target = Util.getCenterLocation(dest.getBlock());
this.parameters = params;
handle = npc.getEntity();
this.navigator = NMS.getTargetNavigator(npc.getEntity(), dest, params);
this.navigator = NMS.getTargetNavigator(npc.getEntity(), target, params);
}
@Override
@ -61,7 +60,6 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
@Override
public void stop() {
centerLocation = null;
navigator.stop();
}
@ -77,15 +75,12 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
}
if (getCancelReason() != null)
return true;
if (centerLocation == null) {
centerLocation = Util.getCenterLocation(target.getBlock());
}
boolean wasFinished = navigator.update();
parameters.run();
Location loc = handle.getLocation(HANDLE_LOCATION);
double dX = centerLocation.getX() - loc.getX();
double dZ = centerLocation.getZ() - loc.getZ();
double dY = centerLocation.getY() - loc.getY();
double dX = target.getX() - loc.getX();
double dZ = target.getZ() - loc.getZ();
double dY = target.getY() - loc.getY();
double xzDistance = dX * dX + dZ * dZ;
if ((dY * dY) < 1 && xzDistance <= parameters.distanceMargin()) {
stop();

View File

@ -51,7 +51,7 @@ public class Util {
if (npc == null) {
return new Vector(x, y, z);
}
boolean allowed = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)
boolean allowed = !npc.isProtected()
|| (npc.data().has(NPC.COLLIDABLE_METADATA) && npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA));
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
return allowed ? new Vector(x, y, z) : null;