001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.cache; 019 020import baritone.api.utils.BetterBlockPos; 021 022import java.util.Date; 023 024/** 025 * Basic implementation of {@link IWaypoint} 026 * 027 * @author leijurv 028 */ 029public class Waypoint implements IWaypoint { 030 031 private final String name; 032 private final Tag tag; 033 private final long creationTimestamp; 034 private final BetterBlockPos location; 035 036 public Waypoint(String name, Tag tag, BetterBlockPos location) { 037 this(name, tag, location, System.currentTimeMillis()); 038 } 039 040 /** 041 * Constructor called when a Waypoint is read from disk, adds the creationTimestamp 042 * as a parameter so that it is reserved after a waypoint is wrote to the disk. 043 * 044 * @param name The waypoint name 045 * @param tag The waypoint tag 046 * @param location The waypoint location 047 * @param creationTimestamp When the waypoint was created 048 */ 049 public Waypoint(String name, Tag tag, BetterBlockPos location, long creationTimestamp) { 050 this.name = name; 051 this.tag = tag; 052 this.location = location; 053 this.creationTimestamp = creationTimestamp; 054 } 055 056 @Override 057 public int hashCode() { 058 return name.hashCode() ^ tag.hashCode() ^ location.hashCode() ^ Long.hashCode(creationTimestamp); 059 } 060 061 @Override 062 public String getName() { 063 return this.name; 064 } 065 066 @Override 067 public Tag getTag() { 068 return this.tag; 069 } 070 071 @Override 072 public long getCreationTimestamp() { 073 return this.creationTimestamp; 074 } 075 076 @Override 077 public BetterBlockPos getLocation() { 078 return this.location; 079 } 080 081 @Override 082 public String toString() { 083 return String.format( 084 "%s %s %s", 085 name, 086 BetterBlockPos.from(location).toString(), 087 new Date(creationTimestamp).toString() 088 ); 089 } 090 091 @Override 092 public boolean equals(Object o) { 093 if (o == null) { 094 return false; 095 } 096 if (!(o instanceof IWaypoint)) { 097 return false; 098 } 099 IWaypoint w = (IWaypoint) o; 100 return name.equals(w.getName()) && tag == w.getTag() && location.equals(w.getLocation()); 101 } 102}