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

View File

@ -24,6 +24,7 @@ import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.datatypes.EntityClassById; import baritone.api.command.datatypes.EntityClassById;
import baritone.api.command.datatypes.IDatatypeFor; import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.NearbyPlayer; import baritone.api.command.datatypes.NearbyPlayer;
import baritone.api.command.exception.CommandErrorMessageException;
import baritone.api.command.exception.CommandException; import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -60,7 +61,7 @@ public class FollowCommand extends Command {
if (gotten instanceof Class) { if (gotten instanceof Class) {
//noinspection unchecked //noinspection unchecked
classes.add((Class<? extends Entity>) gotten); classes.add((Class<? extends Entity>) gotten);
} else { } else if (gotten != null) {
entities.add((Entity) gotten); entities.add((Entity) gotten);
} }
} }
@ -73,12 +74,14 @@ public class FollowCommand extends Command {
if (group != null) { if (group != null) {
logDirect(String.format("Following all %s", group.name().toLowerCase(Locale.US))); logDirect(String.format("Following all %s", group.name().toLowerCase(Locale.US)));
} else { } else {
logDirect("Following these types of entities:");
if (classes.isEmpty()) { if (classes.isEmpty()) {
if (entities.isEmpty()) throw new NoEntitiesException();
logDirect("Following these entities:");
entities.stream() entities.stream()
.map(Entity::toString) .map(Entity::toString)
.forEach(this::logDirect); .forEach(this::logDirect);
} else { } else {
logDirect("Following these types of entities:");
classes.stream() classes.stream()
.map(EntityList::getKey) .map(EntityList::getKey)
.map(Objects::requireNonNull) .map(Objects::requireNonNull)
@ -155,4 +158,12 @@ public class FollowCommand extends Command {
this.datatype = datatype; this.datatype = datatype;
} }
} }
public static class NoEntitiesException extends CommandErrorMessageException {
protected NoEntitiesException() {
super("No valid entities in range!");
}
}
} }