From 47dbd881f50783093b731b7ce5141b9da65e3894 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 6 May 2022 21:25:12 +0800 Subject: [PATCH] Use new API --- .../citizensnpcs/commands/NPCCommands.java | 35 +++++++++++++++---- .../citizensnpcs/npc/ai/FallingExaminer.java | 3 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index da1ae9046..5f5bd92fd 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -28,6 +28,7 @@ import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Ageable; +import org.bukkit.entity.Damageable; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; @@ -1017,6 +1018,18 @@ public class NPCCommands { } } + @Command( + aliases = { "npc" }, + usage = "hurt [damage]", + desc = "Damages the NPC", + modifiers = { "hurt" }, + min = 2, + max = 2, + permission = "citizens.npc.hurt") + public void hurt(CommandContext args, Player sender, NPC npc) { + ((Damageable) npc.getEntity()).damage(args.getInteger(1)); + } + @Command( aliases = { "npc" }, usage = "id", @@ -1621,17 +1634,27 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "pathto [x] [y] [z]", + usage = "pathto me | here | cursor | [x] [y] [z]", desc = "Starts pathfinding to a certain location", modifiers = { "pathto" }, - min = 4, + min = 2, max = 4, permission = "citizens.npc.pathto") - public void pathto(CommandContext args, CommandSender sender, NPC npc) { + public void pathto(CommandContext args, CommandSender sender, NPC npc) throws CommandException { Location loc = npc.getStoredLocation(); - loc.setX(args.getDouble(1)); - loc.setY(args.getDouble(2)); - loc.setZ(args.getDouble(3)); + if (args.argsLength() == 2) { + if ((args.getString(1).equalsIgnoreCase("me") || args.getString(1).equalsIgnoreCase("here"))) { + loc = args.getSenderLocation(); + } else if (args.getString(1).equalsIgnoreCase("cursor")) { + loc = ((Player) sender).getTargetBlockExact(32).getLocation(); + } else { + throw new CommandUsageException(); + } + } else { + loc.setX(args.getDouble(1)); + loc.setY(args.getDouble(2)); + loc.setZ(args.getDouble(3)); + } npc.getNavigator().setTarget(loc); } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/FallingExaminer.java b/main/src/main/java/net/citizensnpcs/npc/ai/FallingExaminer.java index 59399092e..8624e46e3 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/FallingExaminer.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/FallingExaminer.java @@ -13,6 +13,7 @@ import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; import net.citizensnpcs.api.astar.pathfinder.NeighbourGeneratorBlockExaminer; import net.citizensnpcs.api.astar.pathfinder.PathPoint; import net.citizensnpcs.api.astar.pathfinder.VectorNode; +import net.citizensnpcs.api.util.SpigotUtil; public class FallingExaminer implements NeighbourGeneratorBlockExaminer { private final Map fallen = Maps.newHashMap(); @@ -31,7 +32,7 @@ public class FallingExaminer implements NeighbourGeneratorBlockExaminer { public List getNeighbours(BlockSource source, PathPoint point) { Vector pos = point.getVector(); List neighbours = ((VectorNode) point).getNeighbours(source, point); - if (pos.getBlockY() <= 1) + if (pos.getBlockY() <= SpigotUtil.getMinBlockY() + 1) return neighbours; Material above = source.getMaterialAt(pos.getBlockX(), pos.getBlockY() + 1, pos.getBlockZ());