Merge pull request #3024 from wagyourtail/followerror

better follow command error handling
This commit is contained in:
Leijurv 2021-10-10 14:07:27 -07:00 committed by GitHub
commit bcc33362b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import baritone.api.command.argument.IArgConsumer;
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.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity;
@ -60,7 +61,7 @@ public class FollowCommand extends Command {
if (gotten instanceof Class) {
//noinspection unchecked
classes.add((Class<? extends Entity>) gotten);
} else {
} else if (gotten != null) {
entities.add((Entity) gotten);
}
}
@ -73,12 +74,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 +158,12 @@ public class FollowCommand extends Command {
this.datatype = datatype;
}
}
public static class NoEntitiesException extends CommandErrorMessageException {
protected NoEntitiesException() {
super("No valid entities in range!");
}
}
}