Fix some off-by-one errors

This commit is contained in:
fullwall 2021-01-02 20:25:29 +08:00
parent 0b1a8cc369
commit 37e6414b13
2 changed files with 4 additions and 4 deletions

View File

@ -779,7 +779,7 @@ public class NPCCommands {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
}
int idx = Math.max(0, args.getInteger(2));
if (idx > trait.getLines().size()) {
if (idx >= trait.getLines().size()) {
throw new CommandException(Messages.HOLOGRAM_INVALID_LINE);
}
trait.removeLine(idx);

View File

@ -234,10 +234,10 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
return selectedWaypoint == null ? waypoints.get(waypoints.size() - 1) : selectedWaypoint;
}
private Location getPreviousWaypoint() {
private Location getLastWaypoint() {
if (waypoints.size() <= 1)
return null;
return waypoints.get(waypoints.size() - 2).getLocation();
return waypoints.get(waypoints.size() - 1).getLocation();
}
@EventHandler
@ -312,7 +312,7 @@ public class LinearWaypointProvider implements EnumerableWaypointProvider {
return;
event.setCancelled(true);
Location at = event.getClickedBlock().getLocation();
Location prev = getPreviousWaypoint();
Location prev = getLastWaypoint();
if (prev != null && prev.getWorld() == at.getWorld()) {
double distance = at.distance(prev);