From 89c960c455cde2cdef747ff16ebe067fbf5f3696 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Fri, 8 Oct 2021 14:58:17 -0600 Subject: [PATCH 1/2] better follow command error handling --- .../command/defaults/FollowCommand.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/baritone/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java index a3df5387f..3374d223d 100644 --- a/src/main/java/baritone/command/defaults/FollowCommand.java +++ b/src/main/java/baritone/command/defaults/FollowCommand.java @@ -20,11 +20,15 @@ package baritone.command.defaults; import baritone.KeepName; import baritone.api.IBaritone; import baritone.api.command.Command; +import baritone.api.command.ICommand; import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.argument.ICommandArgument; import baritone.api.command.datatypes.EntityClassById; import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.NearbyPlayer; +import baritone.api.command.exception.CommandErrorMessageException; import baritone.api.command.exception.CommandException; +import baritone.api.command.exception.CommandInvalidArgumentException; import baritone.api.command.helpers.TabCompleteHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -60,7 +64,7 @@ public class FollowCommand extends Command { if (gotten instanceof Class) { //noinspection unchecked classes.add((Class) gotten); - } else { + } else if (gotten != null) { entities.add((Entity) gotten); } } @@ -73,12 +77,14 @@ public class FollowCommand extends Command { if (group != null) { logDirect(String.format("Following all %s", group.name().toLowerCase(Locale.US))); } else { - logDirect("Following these types of entities:"); if (classes.isEmpty()) { + if (entities.isEmpty()) throw new NoEntitiesException(); + logDirect("Following these entities:"); entities.stream() .map(Entity::toString) .forEach(this::logDirect); } else { + logDirect("Following these types of entities:"); classes.stream() .map(EntityList::getKey) .map(Objects::requireNonNull) @@ -155,4 +161,12 @@ public class FollowCommand extends Command { this.datatype = datatype; } } + + public static class NoEntitiesException extends CommandErrorMessageException { + + protected NoEntitiesException() { + super("no valid entites in range!"); + } + + } } From ba0b5f929f07406bd8e710fd47b9809a6790d917 Mon Sep 17 00:00:00 2001 From: wagyourtail Date: Fri, 8 Oct 2021 15:49:22 -0600 Subject: [PATCH 2/2] cleanup --- src/main/java/baritone/command/defaults/FollowCommand.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/baritone/command/defaults/FollowCommand.java b/src/main/java/baritone/command/defaults/FollowCommand.java index 3374d223d..a6e7cc5b2 100644 --- a/src/main/java/baritone/command/defaults/FollowCommand.java +++ b/src/main/java/baritone/command/defaults/FollowCommand.java @@ -20,15 +20,12 @@ package baritone.command.defaults; import baritone.KeepName; import baritone.api.IBaritone; import baritone.api.command.Command; -import baritone.api.command.ICommand; import baritone.api.command.argument.IArgConsumer; -import baritone.api.command.argument.ICommandArgument; import baritone.api.command.datatypes.EntityClassById; import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.NearbyPlayer; import baritone.api.command.exception.CommandErrorMessageException; import baritone.api.command.exception.CommandException; -import baritone.api.command.exception.CommandInvalidArgumentException; import baritone.api.command.helpers.TabCompleteHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; @@ -165,7 +162,7 @@ public class FollowCommand extends Command { public static class NoEntitiesException extends CommandErrorMessageException { protected NoEntitiesException() { - super("no valid entites in range!"); + super("No valid entities in range!"); } }