clean up toLowerCase

This commit is contained in:
Leijurv 2018-09-16 16:45:56 -07:00
parent a92465a5f9
commit 7fd0d2d038
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -62,16 +62,16 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return; return;
} }
} }
String msg = event.getMessage(); String msg = event.getMessage().toLowerCase(Locale.US);
if (Baritone.settings().prefix.get()) { if (Baritone.settings().prefix.get()) {
if (!msg.startsWith("#")) { if (!msg.startsWith("#")) {
return; return;
} }
msg = msg.substring(1); msg = msg.substring(1);
} }
if (msg.toLowerCase().startsWith("goal")) { if (msg.startsWith("goal")) {
event.cancel(); event.cancel();
String[] params = msg.toLowerCase().substring(4).trim().split(" "); String[] params = msg.substring(4).trim().split(" ");
if (params[0].equals("")) { if (params[0].equals("")) {
params = new String[]{}; params = new String[]{};
} }
@ -145,7 +145,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("cancel")) { if (msg.equals("cancel")) {
MineBehavior.INSTANCE.cancel(); MineBehavior.INSTANCE.cancel();
FollowBehavior.INSTANCE.cancel(); FollowBehavior.INSTANCE.cancel();
PathingBehavior.INSTANCE.cancel(); PathingBehavior.INSTANCE.cancel();
@ -153,13 +153,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
logDirect("ok canceled"); logDirect("ok canceled");
return; return;
} }
if (msg.toLowerCase().equals("forcecancel")) { if (msg.equals("forcecancel")) {
AbstractNodeCostSearch.forceCancel(); AbstractNodeCostSearch.forceCancel();
event.cancel(); event.cancel();
logDirect("ok force canceled"); logDirect("ok force canceled");
return; return;
} }
if (msg.toLowerCase().equals("invert")) { if (msg.equals("invert")) {
Goal goal = PathingBehavior.INSTANCE.getGoal(); Goal goal = PathingBehavior.INSTANCE.getGoal();
BlockPos runAwayFrom; BlockPos runAwayFrom;
if (goal instanceof GoalXZ) { if (goal instanceof GoalXZ) {
@ -183,7 +183,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("follow")) { if (msg.equals("follow")) {
Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt(); Optional<Entity> entity = MovementHelper.whatEntityAmILookingAt();
if (!entity.isPresent()) { if (!entity.isPresent()) {
logDirect("You aren't looking at an entity bruh"); logDirect("You aren't looking at an entity bruh");
@ -195,20 +195,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("reloadall")) { if (msg.equals("reloadall")) {
WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk(); WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk();
logDirect("ok"); logDirect("ok");
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("saveall")) { if (msg.equals("saveall")) {
WorldProvider.INSTANCE.getCurrentWorld().cache.save(); WorldProvider.INSTANCE.getCurrentWorld().cache.save();
logDirect("ok"); logDirect("ok");
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("find")) { if (msg.startsWith("find")) {
String blockType = msg.toLowerCase().substring(4).trim(); String blockType = msg.substring(4).trim();
LinkedList<BlockPos> locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4); LinkedList<BlockPos> locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4);
logDirect("Have " + locs.size() + " locations"); logDirect("Have " + locs.size() + " locations");
for (BlockPos pos : locs) { for (BlockPos pos : locs) {
@ -220,8 +220,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("mine")) { if (msg.startsWith("mine")) {
String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" "); String[] blockTypes = msg.substring(4).trim().split(" ");
for (String s : blockTypes) { for (String s : blockTypes) {
if (ChunkPacker.stringToBlock(s) == null) { if (ChunkPacker.stringToBlock(s) == null) {
logDirect(s + " isn't a valid block name"); logDirect(s + " isn't a valid block name");
@ -234,7 +234,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("thisway")) { if (msg.startsWith("thisway")) {
try { try {
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
PathingBehavior.INSTANCE.setGoal(goal); PathingBehavior.INSTANCE.setGoal(goal);
@ -245,8 +245,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("list") || msg.toLowerCase().startsWith("get ") || msg.toLowerCase().startsWith("show")) { if (msg.startsWith("list") || msg.startsWith("get ") || msg.startsWith("show")) {
String waypointType = msg.toLowerCase().substring(4).trim(); String waypointType = msg.substring(4).trim();
if (waypointType.endsWith("s")) { if (waypointType.endsWith("s")) {
// for example, "show deaths" // for example, "show deaths"
waypointType = waypointType.substring(0, waypointType.length() - 1); waypointType = waypointType.substring(0, waypointType.length() - 1);
@ -268,15 +268,15 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("save")) { if (msg.startsWith("save")) {
String name = msg.substring(4).trim(); String name = msg.substring(4).trim();
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint(name, Waypoint.Tag.USER, playerFeet())); WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint(name, Waypoint.Tag.USER, playerFeet()));
logDirect("Saved user defined tag under name '" + name + "'. Say 'goto user' to set goal, say 'list user' to list."); logDirect("Saved user defined tag under name '" + name + "'. Say 'goto user' to set goal, say 'list user' to list.");
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().startsWith("goto")) { if (msg.startsWith("goto")) {
String waypointType = msg.toLowerCase().substring(4).trim(); String waypointType = msg.substring(4).trim();
if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) { if (waypointType.endsWith("s") && Waypoint.Tag.fromString(waypointType.substring(0, waypointType.length() - 1)) != null) {
// for example, "show deaths" // for example, "show deaths"
waypointType = waypointType.substring(0, waypointType.length() - 1); waypointType = waypointType.substring(0, waypointType.length() - 1);
@ -316,7 +316,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("spawn") || msg.toLowerCase().equals("bed")) { if (msg.equals("spawn") || msg.equals("bed")) {
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.BED); Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.BED);
if (waypoint == null) { if (waypoint == null) {
BlockPos spawnPoint = player().getBedLocation(); BlockPos spawnPoint = player().getBedLocation();
@ -332,13 +332,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("sethome")) { if (msg.equals("sethome")) {
WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet())); WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet()));
logDirect("Saved. Say home to set goal."); logDirect("Saved. Say home to set goal.");
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("home")) { if (msg.equals("home")) {
Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME); Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME);
if (waypoint == null) { if (waypoint == null) {
logDirect("home not saved"); logDirect("home not saved");
@ -350,7 +350,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
event.cancel(); event.cancel();
return; return;
} }
if (msg.toLowerCase().equals("costs")) { if (msg.equals("costs")) {
Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext()); Movement[] movements = AStarPathFinder.getConnectedPositions(new BetterBlockPos(playerFeet()), new CalculationContext());
List<Movement> moves = new ArrayList<>(Arrays.asList(movements)); List<Movement> moves = new ArrayList<>(Arrays.asList(movements));
while (moves.contains(null)) { while (moves.contains(null)) {
@ -378,7 +378,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
return; return;
} }
} }
if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) { if (msg.equals("baritone") || msg.equals("settings")) {
for (Settings.Setting<?> setting : Baritone.settings().allSettings) { for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
logDirect(setting.toString()); logDirect(setting.toString());
} }
@ -388,7 +388,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
if (msg.contains(" ")) { if (msg.contains(" ")) {
String[] data = msg.split(" "); String[] data = msg.split(" ");
if (data.length == 2) { if (data.length == 2) {
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0].toLowerCase()); Settings.Setting setting = Baritone.settings().byLowerName.get(data[0]);
if (setting != null) { if (setting != null) {
try { try {
if (setting.value.getClass() == Long.class) { if (setting.value.getClass() == Long.class) {
@ -411,8 +411,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
} }
} }
} }
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) { if (Baritone.settings().byLowerName.containsKey(msg)) {
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase()); Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg);
logDirect(setting.toString()); logDirect(setting.toString());
event.cancel(); event.cancel();
return; return;