Skip to content

Commit

Permalink
better follow command error handling
Browse files Browse the repository at this point in the history
(cherry picked from commit 89c960c455cde2cdef747ff16ebe067fbf5f3696)
  • Loading branch information
wagyourtail authored and Pyrofab committed Feb 24, 2022
1 parent d3a3007 commit b71c096
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/java/baritone/command/defaults/FollowCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -34,7 +35,11 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;

Expand All @@ -61,7 +66,7 @@ public void execute(ServerCommandSource source, String label, IArgConsumer args,
Object gotten = args.getDatatypeFor(list.datatype);
if (gotten instanceof EntityType) {
classes.add((EntityType<?>) gotten);
} else {
} else if (gotten != null) {
entities.add((Entity) gotten);
}
}
Expand All @@ -75,12 +80,14 @@ public void execute(ServerCommandSource source, String label, IArgConsumer args,
if (group != null) {
logDirect(source, String.format("Following all %s", group.name().toLowerCase(Locale.US)));
} else {
logDirect(source, "Following these types of entities:");
if (classes.isEmpty()) {
if (entities.isEmpty()) throw new NoEntitiesException();
logDirect(source, "Following these entities:");
entities.stream()
.map(Entity::toString)
.forEach(message -> logDirect(source, message));
} else {
logDirect(source, "Following these types of entities:");
classes.stream()
.map(Registry.ENTITY_TYPE::getId)
.map(Objects::requireNonNull)
Expand Down Expand Up @@ -157,4 +164,12 @@ private enum FollowList {
this.datatype = datatype;
}
}

public static class NoEntitiesException extends CommandErrorMessageException {

protected NoEntitiesException() {
super("No valid entities in range!");
}

}
}

0 comments on commit b71c096

Please sign in to comment.