diff --git a/src/main/java/baritone/chunk/Waypoint.java b/src/main/java/baritone/chunk/Waypoint.java index cb2adbc8..aa800907 100644 --- a/src/main/java/baritone/chunk/Waypoint.java +++ b/src/main/java/baritone/chunk/Waypoint.java @@ -32,7 +32,7 @@ import java.util.Map; public class Waypoint { public final String name; public final Tag tag; - public final long creationTimestamp; + private final long creationTimestamp; public final BlockPos location; public Waypoint(String name, Tag tag, BlockPos location) { diff --git a/src/main/java/baritone/chunk/Waypoints.java b/src/main/java/baritone/chunk/Waypoints.java index 2ad7f16d..fafc102b 100644 --- a/src/main/java/baritone/chunk/Waypoints.java +++ b/src/main/java/baritone/chunk/Waypoints.java @@ -79,11 +79,11 @@ public class Waypoints { try ( FileOutputStream fileOut = new FileOutputStream(fileName.toFile()); BufferedOutputStream bufOut = new BufferedOutputStream(fileOut); - DataOutputStream out = new DataOutputStream(bufOut); + DataOutputStream out = new DataOutputStream(bufOut) ) { for (Waypoint waypoint : waypoints.get(tag)) { out.writeUTF(waypoint.name); - out.writeLong(waypoint.creationTimestamp); + out.writeLong(waypoint.creationTimestamp()); out.writeInt(waypoint.location.getX()); out.writeInt(waypoint.location.getY()); out.writeInt(waypoint.location.getZ()); @@ -98,14 +98,8 @@ public class Waypoints { } public Waypoint getMostRecentByTag(Waypoint.Tag tag) { - Set pts = waypoints.get(tag); - Waypoint best = null; - for (Waypoint waypoint : pts) { - if (best == null || waypoint.creationTimestamp > best.creationTimestamp) { - best = waypoint; - } - } - return best; + // Find a waypoint of the given tag which has the greatest timestamp value, indicating the most recent + return this.waypoints.get(tag).stream().min(Comparator.comparingLong(w -> -w.creationTimestamp())).orElse(null); } public void addWaypoint(Waypoint waypoint) {