better follow command error handling

This commit is contained in:
wagyourtail 2021-10-08 14:58:17 -06:00
parent 14178fcd14
commit 89c960c455
1 changed files with 16 additions and 2 deletions

View File

@ -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<? extends Entity>) 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!");
}
}
}