Use new API

This commit is contained in:
fullwall 2022-05-06 21:25:12 +08:00
parent c880ef8bc5
commit 47dbd881f5
2 changed files with 31 additions and 7 deletions

View File

@ -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);
}

View File

@ -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<PathPoint, Integer> fallen = Maps.newHashMap();
@ -31,7 +32,7 @@ public class FallingExaminer implements NeighbourGeneratorBlockExaminer {
public List<PathPoint> getNeighbours(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
List<PathPoint> 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());