Add debugging command

This commit is contained in:
fullwall 2022-08-22 22:10:48 +08:00
parent a1da32d1d6
commit 0a0f4a8c63
3 changed files with 20 additions and 5 deletions

View File

@ -40,6 +40,7 @@ import org.bukkit.entity.Villager.Profession;
import org.bukkit.entity.Zombie;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@ -663,12 +664,12 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "debug -p(aths) -n(avigation)",
usage = "debug -p(aths) -n(avigation) -r(epathing)",
desc = "Display debugging information",
modifiers = { "debug" },
min = 1,
max = 1,
flags = "pn",
flags = "pnr",
permission = "citizens.npc.debug")
@Requirements(ownership = true, selected = true)
public void debug(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
@ -685,6 +686,13 @@ public class NPCCommands {
+ npc.getNavigator().getDefaultParameters().speed() + "]]<br>";
output += "Stuck action [[" + npc.getNavigator().getDefaultParameters().stuckAction() + "]]<br>";
Messaging.send(sender, output);
} else if (args.hasFlag('r')) {
if (!npc.getEntity().hasMetadata("CitizensPrintMovements")) {
npc.getEntity().setMetadata("CitizensPrintMovements",
new FixedMetadataValue(CitizensAPI.getPlugin(), true));
} else {
npc.getEntity().removeMetadata("CitizensPrintMovements", CitizensAPI.getPlugin());
}
}
}

View File

@ -14,6 +14,7 @@ import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason;
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
@ -40,7 +41,10 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
this.target = Util.getCenterLocation(dest.getBlock());
this.parameters = params;
entity = npc.getEntity();
this.navigator = NMS.getTargetNavigator(npc.getEntity(), target, params);
if (entity.hasMetadata("CitizensPrintMovements")) {
Messaging.log("Setting MCNavigation path", entity, target);
}
this.navigator = NMS.getTargetNavigator(entity, target, params);
}
@Override

View File

@ -614,9 +614,9 @@ public class NMSImpl implements NMSBridge {
}
@Override
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest,
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> nodes,
final NavigatorParameters params) {
List<Node> list = Lists.<Node> newArrayList(Iterables.<Vector, Node> transform(dest, (input) -> {
List<Node> list = Lists.<Node> newArrayList(Iterables.<Vector, Node> transform(nodes, (input) -> {
return new Node(input.getBlockX(), input.getBlockY(), input.getBlockZ());
}));
Node last = list.size() > 0 ? list.get(list.size() - 1) : null;
@ -630,6 +630,9 @@ public class NMSImpl implements NMSBridge {
public MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final Location dest,
final NavigatorParameters params) {
return getTargetNavigator(entity, params, (input) -> {
if (entity.hasMetadata("CitizensPrintMovements")) {
Messaging.log("Repathing", entity, dest);
}
return input.moveTo(dest.getX(), dest.getY(), dest.getZ(), params.speed());
});
}