Merge branch 'master' of github.com:cabaletta/baritone

This commit is contained in:
leijurv 2018-08-27 19:15:16 -07:00
commit c404258b00
2 changed files with 19 additions and 17 deletions

View File

@ -17,12 +17,11 @@
package baritone.chunk; package baritone.chunk;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import org.apache.commons.lang3.ArrayUtils;
import java.util.Collections; import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/** /**
* A single waypoint * A single waypoint
@ -30,6 +29,7 @@ import java.util.Map;
* @author leijurv * @author leijurv
*/ */
public class Waypoint { public class Waypoint {
public final String name; public final String name;
public final Tag tag; public final Tag tag;
private final long creationTimestamp; private final long creationTimestamp;
@ -72,19 +72,21 @@ public class Waypoint {
} }
public enum Tag { public enum Tag {
HOME, DEATH, BED, USER; HOME("home", "base"),
DEATH("death"),
BED("bed", "spawn"),
USER();
} private static final List<Tag> TAG_LIST = ImmutableList.<Tag>builder().add(Tag.values()).build();
public static final Map<String, Tag> TAG_MAP; private final String[] names;
static { Tag(String... names) {
HashMap<String, Tag> map = new HashMap<>(); this.names = names;
map.put("home", Tag.HOME); }
map.put("base", Tag.HOME);
map.put("bed", Tag.BED); public static Tag fromString(String name) {
map.put("spawn", Tag.BED); return TAG_LIST.stream().filter(tag -> ArrayUtils.contains(tag.names, name.toLowerCase())).findFirst().orElse(null);
map.put("death", Tag.DEATH); }
TAG_MAP = Collections.unmodifiableMap(map);
} }
} }

View File

@ -210,7 +210,7 @@ public class ExampleBaritoneControl extends Behavior {
// for example, "show deaths" // for example, "show deaths"
waypointType = waypointType.substring(0, waypointType.length() - 1); waypointType = waypointType.substring(0, waypointType.length() - 1);
} }
Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType); Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
if (tag == null) { if (tag == null) {
displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
event.cancel(); event.cancel();
@ -233,7 +233,7 @@ public class ExampleBaritoneControl extends Behavior {
// for example, "show deaths" // for example, "show deaths"
waypointType = waypointType.substring(0, waypointType.length() - 1); waypointType = waypointType.substring(0, waypointType.length() - 1);
} }
Waypoint.Tag tag = Waypoint.TAG_MAP.get(waypointType); Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType);
if (tag == null) { if (tag == null) {
displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase());
event.cancel(); event.cancel();