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.*; 023 024/** 025 * A marker for a position in the world. 026 * 027 * @author Brady 028 * @since 9/24/2018 029 */ 030public interface IWaypoint { 031 032 /** 033 * @return The label for this waypoint 034 */ 035 String getName(); 036 037 /** 038 * Returns the tag for this waypoint. The tag is a category 039 * for the waypoint in a sense, it describes the source of 040 * the waypoint. 041 * 042 * @return The waypoint tag 043 */ 044 Tag getTag(); 045 046 /** 047 * Returns the unix epoch time in milliseconds that this waypoint 048 * was created. This value should only be set once, when the waypoint 049 * is initially created, and not when it is being loaded from file. 050 * 051 * @return The unix epoch milliseconds that this waypoint was created 052 */ 053 long getCreationTimestamp(); 054 055 /** 056 * Returns the actual block position of this waypoint. 057 * 058 * @return The block position of this waypoint 059 */ 060 BetterBlockPos getLocation(); 061 062 enum Tag { 063 064 /** 065 * Tag indicating a position explictly marked as a home base 066 */ 067 HOME("home", "base"), 068 069 /** 070 * Tag indicating a position that the local player has died at 071 */ 072 DEATH("death"), 073 074 /** 075 * Tag indicating a bed position 076 */ 077 BED("bed", "spawn"), 078 079 /** 080 * Tag indicating that the waypoint was user-created 081 */ 082 USER("user"); 083 084 /** 085 * A list of all of the 086 */ 087 private static final List<Tag> TAG_LIST = Collections.unmodifiableList(Arrays.asList(Tag.values())); 088 089 /** 090 * The names for the tag, anything that the tag can be referred to as. 091 */ 092 public final String[] names; 093 094 Tag(String... names) { 095 this.names = names; 096 } 097 098 /** 099 * @return A name that can be passed to {@link #getByName(String)} to retrieve this tag 100 */ 101 public String getName() { 102 return names[0]; 103 } 104 105 /** 106 * Gets a tag by one of its names. 107 * 108 * @param name The name to search for. 109 * @return The tag, if found, or null. 110 */ 111 public static Tag getByName(String name) { 112 for (Tag action : Tag.values()) { 113 for (String alias : action.names) { 114 if (alias.equalsIgnoreCase(name)) { 115 return action; 116 } 117 } 118 } 119 120 return null; 121 } 122 123 /** 124 * @return All tag names. 125 */ 126 public static String[] getAllNames() { 127 Set<String> names = new HashSet<>(); 128 129 for (Tag tag : Tag.values()) { 130 names.addAll(Arrays.asList(tag.names)); 131 } 132 133 return names.toArray(new String[0]); 134 } 135 } 136}