Checked Command Exceptions
This commit is contained in:
parent
e70d18f046
commit
b7eaae88a8
@ -28,6 +28,7 @@ import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.exception.CommandNotFoundException;
|
||||
import baritone.api.utils.command.execution.CommandExecution;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
@ -124,7 +125,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
|
||||
String command = pair.first();
|
||||
String rest = msg.substring(pair.first().length());
|
||||
ArgConsumer argc = new ArgConsumer(pair.second());
|
||||
if (!argc.has()) {
|
||||
if (!argc.hasAny()) {
|
||||
Settings.Setting setting = settings.byLowerName.get(command.toLowerCase(Locale.US));
|
||||
if (setting != null) {
|
||||
logRanCommand(command, rest);
|
||||
@ -142,7 +143,9 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
|
||||
}
|
||||
if (setting.getName().equalsIgnoreCase(pair.first())) {
|
||||
logRanCommand(command, rest);
|
||||
CommandManager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
|
||||
try {
|
||||
CommandManager.execute(String.format("set %s %s", setting.getName(), argc.getString()));
|
||||
} catch (CommandNotEnoughArgumentsException ignored) {} // The operation is safe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -176,31 +179,35 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
|
||||
}
|
||||
|
||||
public Stream<String> tabComplete(String msg) {
|
||||
List<CommandArgument> args = CommandArgument.from(msg, true);
|
||||
ArgConsumer argc = new ArgConsumer(args);
|
||||
if (argc.hasAtMost(2)) {
|
||||
if (argc.hasExactly(1)) {
|
||||
return new TabCompleteHelper()
|
||||
.addCommands()
|
||||
.addSettings()
|
||||
.filterPrefix(argc.getString())
|
||||
.stream();
|
||||
}
|
||||
Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
|
||||
if (setting != null) {
|
||||
if (setting.getValueClass() == Boolean.class) {
|
||||
TabCompleteHelper helper = new TabCompleteHelper();
|
||||
if ((Boolean) setting.value) {
|
||||
helper.append(Stream.of("true", "false"));
|
||||
try {
|
||||
List<CommandArgument> args = CommandArgument.from(msg, true);
|
||||
ArgConsumer argc = new ArgConsumer(args);
|
||||
if (argc.hasAtMost(2)) {
|
||||
if (argc.hasExactly(1)) {
|
||||
return new TabCompleteHelper()
|
||||
.addCommands()
|
||||
.addSettings()
|
||||
.filterPrefix(argc.getString())
|
||||
.stream();
|
||||
}
|
||||
Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
|
||||
if (setting != null) {
|
||||
if (setting.getValueClass() == Boolean.class) {
|
||||
TabCompleteHelper helper = new TabCompleteHelper();
|
||||
if ((Boolean) setting.value) {
|
||||
helper.append(Stream.of("true", "false"));
|
||||
} else {
|
||||
helper.append(Stream.of("false", "true"));
|
||||
}
|
||||
return helper.filterPrefix(argc.getString()).stream();
|
||||
} else {
|
||||
helper.append(Stream.of("false", "true"));
|
||||
return Stream.of(SettingsUtil.settingValueToString(setting));
|
||||
}
|
||||
return helper.filterPrefix(argc.getString()).stream();
|
||||
} else {
|
||||
return Stream.of(SettingsUtil.settingValueToString(setting));
|
||||
}
|
||||
}
|
||||
return CommandManager.tabComplete(msg);
|
||||
} catch (CommandNotEnoughArgumentsException ignored) { // Shouldn't happen, the operation is safe
|
||||
return Stream.empty();
|
||||
}
|
||||
return CommandManager.tabComplete(msg);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.execution.CommandExecution;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -61,7 +62,7 @@ public abstract class Command implements Helper {
|
||||
*
|
||||
* @param execution The command execution to execute this command with
|
||||
*/
|
||||
public void execute(CommandExecution execution) {
|
||||
public void execute(CommandExecution execution) throws CommandException {
|
||||
executed(execution.label, execution.args, execution.settings);
|
||||
}
|
||||
|
||||
@ -82,13 +83,13 @@ public abstract class Command implements Helper {
|
||||
/**
|
||||
* Called when this command is executed.
|
||||
*/
|
||||
protected abstract void executed(String label, ArgConsumer args, Settings settings);
|
||||
protected abstract void executed(String label, ArgConsumer args, Settings settings) throws CommandException;
|
||||
|
||||
/**
|
||||
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
|
||||
* list.
|
||||
*/
|
||||
protected abstract Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings);
|
||||
protected abstract Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException;
|
||||
|
||||
/**
|
||||
* @return A <b>single-line</b> string containing a short description of this command's purpose.
|
||||
|
@ -20,6 +20,7 @@ package baritone.api.utils.command.argparser;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.exception.CommandNoParserForTypeException;
|
||||
import baritone.api.utils.command.exception.CommandUnhandledException;
|
||||
import baritone.api.utils.command.registry.Registry;
|
||||
|
||||
public class ArgParserManager {
|
||||
@ -66,13 +67,13 @@ public class ArgParserManager {
|
||||
* @param type The type to try and parse the argument into.
|
||||
* @param arg The argument to parse.
|
||||
* @return An instance of the specified class.
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
*/
|
||||
public static <T> T parseStateless(Class<T> type, CommandArgument arg) {
|
||||
public static <T> T parseStateless(Class<T> type, CommandArgument arg) throws CommandInvalidTypeException {
|
||||
ArgParser.Stateless<T> parser = getParserStateless(type);
|
||||
if (parser == null) {
|
||||
throw new CommandNoParserForTypeException(type);
|
||||
// TODO: Fix this scuff lol
|
||||
throw new CommandUnhandledException(new CommandNoParserForTypeException(type));
|
||||
}
|
||||
try {
|
||||
return parser.parseArg(arg);
|
||||
@ -88,14 +89,14 @@ public class ArgParserManager {
|
||||
* @param arg The argument to parse.
|
||||
* @param state The state to pass to the {@link ArgParser.Stated}.
|
||||
* @return An instance of the specified class.
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
* @see ArgParser.Stated
|
||||
*/
|
||||
public static <T, S> T parseStated(Class<T> type, Class<S> stateKlass, CommandArgument arg, S state) {
|
||||
public static <T, S> T parseStated(Class<T> type, Class<S> stateKlass, CommandArgument arg, S state) throws CommandInvalidTypeException {
|
||||
ArgParser.Stated<T, S> parser = getParserStated(type, stateKlass);
|
||||
if (parser == null) {
|
||||
throw new CommandNoParserForTypeException(type);
|
||||
// TODO: Fix this scuff lol
|
||||
throw new CommandUnhandledException(new CommandNoParserForTypeException(type));
|
||||
}
|
||||
try {
|
||||
return parser.parseArg(arg, state);
|
||||
|
@ -66,7 +66,7 @@ public class CommandArgument {
|
||||
* @see ArgConsumer#getEnum(Class)
|
||||
* @see ArgConsumer#getEnumOrNull(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E getEnum(Class<E> enumClass) {
|
||||
public <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.filter(e -> e.name().equalsIgnoreCase(value))
|
||||
.findFirst()
|
||||
@ -78,10 +78,9 @@ public class CommandArgument {
|
||||
*
|
||||
* @param type The class to parse this argument into
|
||||
* @return An instance of the specified type
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
*/
|
||||
public <T> T getAs(Class<T> type) {
|
||||
public <T> T getAs(Class<T> type) throws CommandInvalidTypeException {
|
||||
return ArgParserManager.parseStateless(type, this);
|
||||
}
|
||||
|
||||
@ -105,11 +104,10 @@ public class CommandArgument {
|
||||
*
|
||||
* @param type The class to parse this argument into
|
||||
* @return An instance of the specified type
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
*/
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public <T, S> T getAs(Class<T> type, Class<S> stateType, S state) {
|
||||
public <T, S> T getAs(Class<T> type, Class<S> stateType, S state) throws CommandInvalidTypeException {
|
||||
return ArgParserManager.parseStated(type, stateType, this, state);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
import net.minecraft.block.Block;
|
||||
@ -33,7 +35,7 @@ public class BlockById implements IDatatypeFor<Block> {
|
||||
block = null;
|
||||
}
|
||||
|
||||
public BlockById(ArgConsumer consumer) {
|
||||
public BlockById(ArgConsumer consumer) throws CommandNotEnoughArgumentsException {
|
||||
ResourceLocation id = new ResourceLocation(consumer.getString());
|
||||
if ((block = Block.REGISTRY.getObject(id)) == Blocks.AIR) {
|
||||
throw new IllegalArgumentException("no block found by that id");
|
||||
@ -46,7 +48,7 @@ public class BlockById implements IDatatypeFor<Block> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
return new TabCompleteHelper()
|
||||
.append(
|
||||
Block.REGISTRY.getKeys()
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -33,7 +34,7 @@ public class EntityClassById implements IDatatypeFor<Class<? extends Entity>> {
|
||||
entity = null;
|
||||
}
|
||||
|
||||
public EntityClassById(ArgConsumer consumer) {
|
||||
public EntityClassById(ArgConsumer consumer) throws CommandException {
|
||||
ResourceLocation id = new ResourceLocation(consumer.getString());
|
||||
if ((entity = EntityList.REGISTRY.getObject(id)) == null) {
|
||||
throw new IllegalArgumentException("no entity found by that id");
|
||||
@ -46,7 +47,7 @@ public class EntityClassById implements IDatatypeFor<Class<? extends Entity>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
return new TabCompleteHelper()
|
||||
.append(
|
||||
EntityList.getEntityNameList()
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.BlockOptionalMeta;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -30,7 +31,7 @@ public class ForBlockOptionalMeta implements IDatatypeFor<BlockOptionalMeta> {
|
||||
selector = null;
|
||||
}
|
||||
|
||||
public ForBlockOptionalMeta(ArgConsumer consumer) {
|
||||
public ForBlockOptionalMeta(ArgConsumer consumer) throws CommandException {
|
||||
selector = new BlockOptionalMeta(consumer.getString());
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
@ -33,7 +35,7 @@ public class ForEnumFacing implements IDatatypeFor<EnumFacing> {
|
||||
facing = null;
|
||||
}
|
||||
|
||||
public ForEnumFacing(ArgConsumer consumer) {
|
||||
public ForEnumFacing(ArgConsumer consumer) throws CommandNotEnoughArgumentsException {
|
||||
facing = EnumFacing.valueOf(consumer.getString().toUpperCase(Locale.US));
|
||||
}
|
||||
|
||||
@ -43,7 +45,7 @@ public class ForEnumFacing implements IDatatypeFor<EnumFacing> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
return new TabCompleteHelper()
|
||||
.append(
|
||||
Arrays.stream(EnumFacing.values())
|
||||
|
@ -20,6 +20,8 @@ package baritone.api.utils.command.datatypes;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.cache.IWaypoint;
|
||||
import baritone.api.cache.IWaypointCollection;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
|
||||
@ -40,7 +42,7 @@ public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
|
||||
waypoints = tag == null ? getWaypointsByName(arg) : getWaypointsByTag(tag);
|
||||
}
|
||||
|
||||
public ForWaypoints(ArgConsumer consumer) {
|
||||
public ForWaypoints(ArgConsumer consumer) throws CommandNotEnoughArgumentsException {
|
||||
this(consumer.getString());
|
||||
}
|
||||
|
||||
@ -50,7 +52,7 @@ public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
return new TabCompleteHelper()
|
||||
.append(getWaypointNames())
|
||||
.sortAlphabetically()
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.argparser.ArgParser;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidArgumentException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -44,5 +45,5 @@ public interface IDatatype {
|
||||
* @return A stream representing the strings that can be tab completed. DO NOT INCLUDE SPACES IN ANY STRINGS.
|
||||
* @see ArgConsumer#tabCompleteDatatype(Class)
|
||||
*/
|
||||
Stream<String> tabComplete(ArgConsumer consumer);
|
||||
Stream<String> tabComplete(ArgConsumer consumer) throws CommandException;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@ -35,7 +36,7 @@ public class PlayerByUsername implements IDatatypeFor<EntityPlayer> {
|
||||
player = null;
|
||||
}
|
||||
|
||||
public PlayerByUsername(ArgConsumer consumer) {
|
||||
public PlayerByUsername(ArgConsumer consumer) throws CommandException {
|
||||
String username = consumer.getString();
|
||||
player = players
|
||||
.stream()
|
||||
@ -53,7 +54,7 @@ public class PlayerByUsername implements IDatatypeFor<EntityPlayer> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
return new TabCompleteHelper()
|
||||
.append(
|
||||
players
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -34,7 +35,7 @@ public class RelativeBlockPos implements IDatatypePost<BetterBlockPos, BetterBlo
|
||||
z = null;
|
||||
}
|
||||
|
||||
public RelativeBlockPos(ArgConsumer consumer) {
|
||||
public RelativeBlockPos(ArgConsumer consumer) throws CommandException {
|
||||
x = consumer.getDatatype(RelativeCoordinate.class);
|
||||
y = consumer.getDatatype(RelativeCoordinate.class);
|
||||
z = consumer.getDatatype(RelativeCoordinate.class);
|
||||
@ -50,8 +51,8 @@ public class RelativeBlockPos implements IDatatypePost<BetterBlockPos, BetterBlo
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
if (consumer.has() && !consumer.has(4)) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
if (consumer.hasAny() && !consumer.has(4)) {
|
||||
while (consumer.has(2)) {
|
||||
if (consumer.peekDatatypeOrNull(RelativeCoordinate.class) == null) {
|
||||
break;
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
@ -35,7 +37,7 @@ public class RelativeCoordinate implements IDatatypePost<Double, Double> {
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
public RelativeCoordinate(ArgConsumer consumer) {
|
||||
public RelativeCoordinate(ArgConsumer consumer) throws CommandNotEnoughArgumentsException {
|
||||
Matcher matcher = PATTERN.matcher(consumer.getString());
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("pattern doesn't match");
|
||||
@ -57,7 +59,7 @@ public class RelativeCoordinate implements IDatatypePost<Double, Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) {
|
||||
public Stream<String> tabComplete(ArgConsumer consumer) throws CommandException {
|
||||
if (!consumer.has(2) && consumer.getString().matches("^(~|$)")) {
|
||||
return Stream.of("~");
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotEnoughArgumentsException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.io.File;
|
||||
@ -40,7 +42,7 @@ public class RelativeFile implements IDatatypePost<File, File> {
|
||||
path = null;
|
||||
}
|
||||
|
||||
public RelativeFile(ArgConsumer consumer) {
|
||||
public RelativeFile(ArgConsumer consumer) throws CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
path = FileSystems.getDefault().getPath(consumer.getString());
|
||||
} catch (InvalidPathException e) {
|
||||
@ -68,9 +70,12 @@ public class RelativeFile implements IDatatypePost<File, File> {
|
||||
}
|
||||
}
|
||||
|
||||
public static Stream<String> tabComplete(ArgConsumer consumer, File base0) {
|
||||
public static Stream<String> tabComplete(ArgConsumer consumer, File base0) throws CommandException {
|
||||
// I will not make the caller deal with this, seriously
|
||||
// Tab complete code is beautiful and I'm not going to bloat it with dumb ass checked exception bullshit
|
||||
// Tab complete code is beautiful and I'm not going to bloat it with dumb ass checked exception bullshit -LoganDark
|
||||
|
||||
// lol owned -Brady
|
||||
|
||||
File base = getCanonicalFileUnchecked(base0);
|
||||
String currentPathStringThing = consumer.getString();
|
||||
Path currentPath = FileSystems.getDefault().getPath(currentPathStringThing);
|
||||
|
@ -22,6 +22,7 @@ import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.pathing.goals.GoalYLevel;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -36,7 +37,7 @@ public class RelativeGoal implements IDatatypePost<Goal, BetterBlockPos> {
|
||||
coords = new RelativeCoordinate[0];
|
||||
}
|
||||
|
||||
public RelativeGoal(ArgConsumer consumer) {
|
||||
public RelativeGoal(ArgConsumer consumer) throws CommandException {
|
||||
List<RelativeCoordinate> coordsList = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (consumer.peekDatatypeOrNull(RelativeCoordinate.class) != null) {
|
||||
|
@ -19,6 +19,8 @@ package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -31,7 +33,7 @@ public class RelativeGoalBlock implements IDatatypePost<GoalBlock, BetterBlockPo
|
||||
coords = new RelativeCoordinate[0];
|
||||
}
|
||||
|
||||
public RelativeGoalBlock(ArgConsumer consumer) {
|
||||
public RelativeGoalBlock(ArgConsumer consumer) throws CommandException {
|
||||
coords = new RelativeCoordinate[]{
|
||||
consumer.getDatatype(RelativeCoordinate.class),
|
||||
consumer.getDatatype(RelativeCoordinate.class),
|
||||
|
@ -19,6 +19,7 @@ package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -31,7 +32,7 @@ public class RelativeGoalXZ implements IDatatypePost<GoalXZ, BetterBlockPos> {
|
||||
coords = new RelativeCoordinate[0];
|
||||
}
|
||||
|
||||
public RelativeGoalXZ(ArgConsumer consumer) {
|
||||
public RelativeGoalXZ(ArgConsumer consumer) throws CommandException {
|
||||
coords = new RelativeCoordinate[]{
|
||||
consumer.getDatatype(RelativeCoordinate.class),
|
||||
consumer.getDatatype(RelativeCoordinate.class)
|
||||
|
@ -19,6 +19,7 @@ package baritone.api.utils.command.datatypes;
|
||||
|
||||
import baritone.api.pathing.goals.GoalYLevel;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
@ -31,7 +32,7 @@ public class RelativeGoalYLevel implements IDatatypePost<GoalYLevel, BetterBlock
|
||||
coord = null;
|
||||
}
|
||||
|
||||
public RelativeGoalYLevel(ArgConsumer consumer) {
|
||||
public RelativeGoalYLevel(ArgConsumer consumer) throws CommandException {
|
||||
coord = consumer.getDatatype(RelativeCoordinate.class);
|
||||
}
|
||||
|
||||
|
@ -17,22 +17,9 @@
|
||||
|
||||
package baritone.api.utils.command.exception;
|
||||
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static baritone.api.utils.Helper.HELPER;
|
||||
|
||||
public abstract class CommandErrorMessageException extends CommandException {
|
||||
|
||||
protected CommandErrorMessageException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Command command, List<CommandArgument> args) {
|
||||
HELPER.logDirect(getMessage(), TextFormatting.RED);
|
||||
}
|
||||
}
|
||||
|
@ -17,22 +17,9 @@
|
||||
|
||||
package baritone.api.utils.command.exception;
|
||||
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommandException extends RuntimeException {
|
||||
public abstract class CommandException extends Exception implements ICommandException {
|
||||
|
||||
protected CommandException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this exception is thrown, to handle the exception.
|
||||
*
|
||||
* @param command The command that threw it.
|
||||
* @param args The arguments the command was called with.
|
||||
*/
|
||||
public abstract void handle(Command command, List<CommandArgument> args);
|
||||
}
|
||||
|
@ -23,15 +23,22 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandUnhandledException extends CommandErrorMessageException {
|
||||
public class CommandUnhandledException extends RuntimeException implements ICommandException {
|
||||
|
||||
public static String getStackTrace(Throwable throwable) {
|
||||
public CommandUnhandledException(Throwable cause) {
|
||||
super(String.format(
|
||||
"An unhandled exception has occurred:\n\n%s",
|
||||
getFriendlierStackTrace(cause)
|
||||
));
|
||||
}
|
||||
|
||||
private static String getStackTrace(Throwable throwable) {
|
||||
StringWriter sw = new StringWriter();
|
||||
throwable.printStackTrace(new PrintWriter(sw));
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
public static String getBaritoneStackTrace(String stackTrace) {
|
||||
private static String getBaritoneStackTrace(String stackTrace) {
|
||||
List<String> lines = Arrays.stream(stackTrace.split("\n"))
|
||||
.collect(Collectors.toList());
|
||||
int lastBaritoneLine = 0;
|
||||
@ -43,11 +50,11 @@ public class CommandUnhandledException extends CommandErrorMessageException {
|
||||
return String.join("\n", lines.subList(0, lastBaritoneLine + 1));
|
||||
}
|
||||
|
||||
public static String getBaritoneStackTrace(Throwable throwable) {
|
||||
private static String getBaritoneStackTrace(Throwable throwable) {
|
||||
return getBaritoneStackTrace(getStackTrace(throwable));
|
||||
}
|
||||
|
||||
public static String getFriendlierStackTrace(String stackTrace) {
|
||||
private static String getFriendlierStackTrace(String stackTrace) {
|
||||
List<String> lines = Arrays.asList(stackTrace.split("\n"));
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
@ -64,14 +71,7 @@ public class CommandUnhandledException extends CommandErrorMessageException {
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
|
||||
public static String getFriendlierStackTrace(Throwable throwable) {
|
||||
private static String getFriendlierStackTrace(Throwable throwable) {
|
||||
return getFriendlierStackTrace(getBaritoneStackTrace(throwable));
|
||||
}
|
||||
|
||||
public CommandUnhandledException(Throwable cause) {
|
||||
super(String.format(
|
||||
"An unhandled exception has occurred:\n\n%s",
|
||||
getFriendlierStackTrace(cause)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.api.utils.command.exception;
|
||||
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.argument.CommandArgument;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static baritone.api.utils.Helper.HELPER;
|
||||
|
||||
/**
|
||||
* The base for a Baritone Command Exception, checked or unchecked. Provides a
|
||||
* {@link #handle(Command, List)} method that is used to provide useful output
|
||||
* to the user for diagnosing issues that may have occurred during execution.
|
||||
* <p>
|
||||
* Anything implementing this interface should be assignable to {@link Exception}.
|
||||
*
|
||||
* @author Brady
|
||||
* @since 9/20/2019
|
||||
*/
|
||||
public interface ICommandException {
|
||||
|
||||
/**
|
||||
* @see Exception#getMessage()
|
||||
* @return The exception details
|
||||
*/
|
||||
String getMessage();
|
||||
|
||||
/**
|
||||
* Called when this exception is thrown, to handle the exception.
|
||||
*
|
||||
* @param command The command that threw it.
|
||||
* @param args The arguments the command was called with.
|
||||
*/
|
||||
default void handle(Command command, List<CommandArgument> args) {
|
||||
HELPER.logDirect(this.getMessage(), TextFormatting.RED);
|
||||
}
|
||||
}
|
@ -77,7 +77,7 @@ public class ArgConsumer {
|
||||
/**
|
||||
* @param num The number of arguments to check for
|
||||
* @return {@code true} if there are <i>at least</i> {@code num} arguments left in this {@link ArgConsumer}
|
||||
* @see #has()
|
||||
* @see #hasAny()
|
||||
* @see #hasAtMost(int)
|
||||
* @see #hasExactly(int)
|
||||
*/
|
||||
@ -91,7 +91,7 @@ public class ArgConsumer {
|
||||
* @see #hasAtMostOne()
|
||||
* @see #hasExactlyOne()
|
||||
*/
|
||||
public boolean has() {
|
||||
public boolean hasAny() {
|
||||
return has(1);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ public class ArgConsumer {
|
||||
|
||||
/**
|
||||
* @return {@code true} if there is <i>at most</i> 1 argument left in this {@link ArgConsumer}
|
||||
* @see #has()
|
||||
* @see #hasAny()
|
||||
* @see #hasAtMostOne()
|
||||
* @see #hasExactlyOne()
|
||||
*/
|
||||
@ -128,7 +128,7 @@ public class ArgConsumer {
|
||||
|
||||
/**
|
||||
* @return {@code true} if there is <i>exactly</i> 1 argument left in this {@link ArgConsumer}
|
||||
* @see #has()
|
||||
* @see #hasAny()
|
||||
* @see #hasAtMostOne()
|
||||
*/
|
||||
public boolean hasExactlyOne() {
|
||||
@ -145,7 +145,7 @@ public class ArgConsumer {
|
||||
* @see #peekAs(Class, int)
|
||||
* @see #get()
|
||||
*/
|
||||
public CommandArgument peek(int index) {
|
||||
public CommandArgument peek(int index) throws CommandNotEnoughArgumentsException {
|
||||
requireMin(index + 1);
|
||||
return args.get(index);
|
||||
}
|
||||
@ -161,7 +161,7 @@ public class ArgConsumer {
|
||||
* @see #peekDatatypePost(Class, Object)
|
||||
* @see #get()
|
||||
*/
|
||||
public CommandArgument peek() {
|
||||
public CommandArgument peek() throws CommandNotEnoughArgumentsException {
|
||||
return peek(0);
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ public class ArgConsumer {
|
||||
* @see #peek()
|
||||
* @see #getAs(Class)
|
||||
*/
|
||||
public boolean is(Class<?> type, int index) {
|
||||
public boolean is(Class<?> type, int index) throws CommandNotEnoughArgumentsException {
|
||||
return peek(index).is(type);
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ public class ArgConsumer {
|
||||
* @see #peek()
|
||||
* @see #getAs(Class)
|
||||
*/
|
||||
public boolean is(Class<?> type) {
|
||||
public boolean is(Class<?> type) throws CommandNotEnoughArgumentsException {
|
||||
return is(type, 0);
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ public class ArgConsumer {
|
||||
* @see #peek()
|
||||
* @see #peekString()
|
||||
*/
|
||||
public String peekString(int index) {
|
||||
public String peekString(int index) throws CommandNotEnoughArgumentsException {
|
||||
return peek(index).value;
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ public class ArgConsumer {
|
||||
* @see #peekString(int)
|
||||
* @see #getString()
|
||||
*/
|
||||
public String peekString() {
|
||||
public String peekString() throws CommandNotEnoughArgumentsException {
|
||||
return peekString(0);
|
||||
}
|
||||
|
||||
@ -222,7 +222,7 @@ public class ArgConsumer {
|
||||
* @see #getEnum(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E peekEnum(Class<E> enumClass, int index) {
|
||||
public <E extends Enum<?>> E peekEnum(Class<E> enumClass, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return peek(index).getEnum(enumClass);
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ public class ArgConsumer {
|
||||
* @see #getEnum(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E peekEnum(Class<E> enumClass) {
|
||||
public <E extends Enum<?>> E peekEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return peekEnum(enumClass, 0);
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ public class ArgConsumer {
|
||||
* @see #getEnumOrNull(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass, int index) {
|
||||
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass, int index) throws CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
return peekEnum(enumClass, index);
|
||||
} catch (CommandInvalidTypeException e) {
|
||||
@ -264,12 +264,8 @@ public class ArgConsumer {
|
||||
* @see #getEnumOrNull(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass) {
|
||||
try {
|
||||
return peekEnumOrNull(enumClass, 0);
|
||||
} catch (CommandInvalidTypeException e) {
|
||||
return null;
|
||||
}
|
||||
public <E extends Enum<?>> E peekEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException {
|
||||
return peekEnumOrNull(enumClass, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -283,14 +279,13 @@ public class ArgConsumer {
|
||||
* @param type The type to peek as
|
||||
* @param index The index to peek
|
||||
* @return An instance of the specified type
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
* @see ArgParser
|
||||
* @see #peekAs(Class)
|
||||
* @see #peekAsOrDefault(Class, Object, int)
|
||||
* @see #peekAsOrNull(Class, int)
|
||||
*/
|
||||
public <T> T peekAs(Class<T> type, int index) {
|
||||
public <T> T peekAs(Class<T> type, int index) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return peek(index).getAs(type);
|
||||
}
|
||||
|
||||
@ -303,14 +298,13 @@ public class ArgConsumer {
|
||||
*
|
||||
* @param type The type to peek as
|
||||
* @return An instance of the specified type
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
* @see ArgParser
|
||||
* @see #peekAs(Class, int)
|
||||
* @see #peekAsOrDefault(Class, Object)
|
||||
* @see #peekAsOrNull(Class)
|
||||
*/
|
||||
public <T> T peekAs(Class<T> type) {
|
||||
public <T> T peekAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return peekAs(type, 0);
|
||||
}
|
||||
|
||||
@ -331,7 +325,7 @@ public class ArgConsumer {
|
||||
* @see #peekAs(Class, int)
|
||||
* @see #peekAsOrNull(Class, int)
|
||||
*/
|
||||
public <T> T peekAsOrDefault(Class<T> type, T def, int index) {
|
||||
public <T> T peekAsOrDefault(Class<T> type, T def, int index) throws CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
return peekAs(type, index);
|
||||
} catch (CommandInvalidTypeException e) {
|
||||
@ -354,7 +348,7 @@ public class ArgConsumer {
|
||||
* @see #peekAs(Class)
|
||||
* @see #peekAsOrNull(Class)
|
||||
*/
|
||||
public <T> T peekAsOrDefault(Class<T> type, T def) {
|
||||
public <T> T peekAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException {
|
||||
return peekAsOrDefault(type, def, 0);
|
||||
}
|
||||
|
||||
@ -374,7 +368,7 @@ public class ArgConsumer {
|
||||
* @see #peekAs(Class, int)
|
||||
* @see #peekAsOrDefault(Class, Object, int)
|
||||
*/
|
||||
public <T> T peekAsOrNull(Class<T> type, int index) {
|
||||
public <T> T peekAsOrNull(Class<T> type, int index) throws CommandNotEnoughArgumentsException {
|
||||
return peekAsOrDefault(type, null, index);
|
||||
}
|
||||
|
||||
@ -392,7 +386,7 @@ public class ArgConsumer {
|
||||
* @see #peekAs(Class)
|
||||
* @see #peekAsOrDefault(Class, Object)
|
||||
*/
|
||||
public <T> T peekAsOrNull(Class<T> type) {
|
||||
public <T> T peekAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException {
|
||||
return peekAsOrNull(type, 0);
|
||||
}
|
||||
|
||||
@ -409,7 +403,7 @@ public class ArgConsumer {
|
||||
* @return The datatype instance
|
||||
* @see IDatatype
|
||||
*/
|
||||
public <T extends IDatatype> T peekDatatype(Class<T> datatype) {
|
||||
public <T extends IDatatype> T peekDatatype(Class<T> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return copy().getDatatype(datatype);
|
||||
}
|
||||
|
||||
@ -426,7 +420,7 @@ public class ArgConsumer {
|
||||
* @return The datatype instance, or {@code null} if it throws an exception
|
||||
* @see IDatatype
|
||||
*/
|
||||
public <T extends IDatatype> T peekDatatypeOrNull(Class<T> datatype) {
|
||||
public <T extends IDatatype> T peekDatatypeOrNull(Class<T> datatype) throws CommandNotEnoughArgumentsException {
|
||||
return copy().getDatatypeOrNull(datatype);
|
||||
}
|
||||
|
||||
@ -444,7 +438,7 @@ public class ArgConsumer {
|
||||
* @see IDatatype
|
||||
* @see IDatatypePost
|
||||
*/
|
||||
public <T, O, D extends IDatatypePost<T, O>> T peekDatatypePost(Class<D> datatype, O original) {
|
||||
public <T, O, D extends IDatatypePost<T, O>> T peekDatatypePost(Class<D> datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return copy().getDatatypePost(datatype, original);
|
||||
}
|
||||
|
||||
@ -547,7 +541,7 @@ public class ArgConsumer {
|
||||
* @return The next argument
|
||||
* @throws CommandNotEnoughArgumentsException If there's less than one argument left
|
||||
*/
|
||||
public CommandArgument get() {
|
||||
public CommandArgument get() throws CommandNotEnoughArgumentsException {
|
||||
requireMin(1);
|
||||
CommandArgument arg = args.removeFirst();
|
||||
consumed.add(arg);
|
||||
@ -561,7 +555,7 @@ public class ArgConsumer {
|
||||
* @return The value of the next argument
|
||||
* @throws CommandNotEnoughArgumentsException If there's less than one argument left
|
||||
*/
|
||||
public String getString() {
|
||||
public String getString() throws CommandNotEnoughArgumentsException {
|
||||
return get().value;
|
||||
}
|
||||
|
||||
@ -578,7 +572,7 @@ public class ArgConsumer {
|
||||
* @see #getEnumOrNull(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E getEnum(Class<E> enumClass) {
|
||||
public <E extends Enum<?>> E getEnum(Class<E> enumClass) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return get().getEnum(enumClass);
|
||||
}
|
||||
|
||||
@ -597,7 +591,7 @@ public class ArgConsumer {
|
||||
* @see #peekEnumOrNull(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E getEnumOrDefault(Class<E> enumClass, E def) {
|
||||
public <E extends Enum<?>> E getEnumOrDefault(Class<E> enumClass, E def) throws CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
peekEnum(enumClass);
|
||||
return getEnum(enumClass);
|
||||
@ -620,7 +614,7 @@ public class ArgConsumer {
|
||||
* @see #peekEnumOrNull(Class)
|
||||
* @see CommandArgument#getEnum(Class)
|
||||
*/
|
||||
public <E extends Enum<?>> E getEnumOrNull(Class<E> enumClass) {
|
||||
public <E extends Enum<?>> E getEnumOrNull(Class<E> enumClass) throws CommandNotEnoughArgumentsException {
|
||||
return getEnumOrDefault(enumClass, null);
|
||||
}
|
||||
|
||||
@ -633,7 +627,6 @@ public class ArgConsumer {
|
||||
*
|
||||
* @param type The type to peek as
|
||||
* @return An instance of the specified type
|
||||
* @throws CommandNoParserForTypeException If no parser exists for that type
|
||||
* @throws CommandInvalidTypeException If the parsing failed
|
||||
* @see ArgParser
|
||||
* @see #get()
|
||||
@ -643,7 +636,7 @@ public class ArgConsumer {
|
||||
* @see #peekAsOrDefault(Class, Object, int)
|
||||
* @see #peekAsOrNull(Class, int)
|
||||
*/
|
||||
public <T> T getAs(Class<T> type) {
|
||||
public <T> T getAs(Class<T> type) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return get().getAs(type);
|
||||
}
|
||||
|
||||
@ -665,7 +658,7 @@ public class ArgConsumer {
|
||||
* @see #peekAsOrDefault(Class, Object, int)
|
||||
* @see #peekAsOrNull(Class, int)
|
||||
*/
|
||||
public <T> T getAsOrDefault(Class<T> type, T def) {
|
||||
public <T> T getAsOrDefault(Class<T> type, T def) throws CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
T val = peek().getAs(type);
|
||||
get();
|
||||
@ -692,7 +685,7 @@ public class ArgConsumer {
|
||||
* @see #peekAsOrDefault(Class, Object, int)
|
||||
* @see #peekAsOrNull(Class, int)
|
||||
*/
|
||||
public <T> T getAsOrNull(Class<T> type) {
|
||||
public <T> T getAsOrNull(Class<T> type) throws CommandNotEnoughArgumentsException {
|
||||
return getAsOrDefault(type, null);
|
||||
}
|
||||
|
||||
@ -707,11 +700,11 @@ public class ArgConsumer {
|
||||
* @return The datatype instance
|
||||
* @see IDatatype
|
||||
*/
|
||||
public <T extends IDatatype> T getDatatype(Class<T> datatype) {
|
||||
public <T extends IDatatype> T getDatatype(Class<T> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
try {
|
||||
return datatype.getConstructor(ArgConsumer.class).newInstance(this);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new CommandInvalidTypeException(has() ? peek() : consumed(), datatype.getSimpleName());
|
||||
throw new CommandInvalidTypeException(hasAny() ? peek() : consumed(), datatype.getSimpleName());
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException e) {
|
||||
throw new CommandUnhandledException(e);
|
||||
}
|
||||
@ -730,7 +723,7 @@ public class ArgConsumer {
|
||||
* @return The datatype instance, or {@code null} if it throws an exception
|
||||
* @see IDatatype
|
||||
*/
|
||||
public <T extends IDatatype> T getDatatypeOrNull(Class<T> datatype) {
|
||||
public <T extends IDatatype> T getDatatypeOrNull(Class<T> datatype) throws CommandNotEnoughArgumentsException {
|
||||
List<CommandArgument> argsSnapshot = new ArrayList<>(args);
|
||||
List<CommandArgument> consumedSnapshot = new ArrayList<>(consumed);
|
||||
try {
|
||||
@ -756,7 +749,7 @@ public class ArgConsumer {
|
||||
* @see IDatatype
|
||||
* @see IDatatypePost
|
||||
*/
|
||||
public <T, O, D extends IDatatypePost<T, O>> T getDatatypePost(Class<D> datatype, O original) {
|
||||
public <T, O, D extends IDatatypePost<T, O>> T getDatatypePost(Class<D> datatype, O original) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return getDatatype(datatype).apply(original);
|
||||
}
|
||||
|
||||
@ -819,7 +812,7 @@ public class ArgConsumer {
|
||||
* @see IDatatype
|
||||
* @see IDatatypeFor
|
||||
*/
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeFor(Class<D> datatype) {
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeFor(Class<D> datatype) throws CommandInvalidTypeException, CommandNotEnoughArgumentsException {
|
||||
return getDatatype(datatype).get();
|
||||
}
|
||||
|
||||
@ -838,7 +831,7 @@ public class ArgConsumer {
|
||||
* @see IDatatype
|
||||
* @see IDatatypeFor
|
||||
*/
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrDefault(Class<D> datatype, T def) {
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrDefault(Class<D> datatype, T def) throws CommandNotEnoughArgumentsException {
|
||||
List<CommandArgument> argsSnapshot = new ArrayList<>(args);
|
||||
List<CommandArgument> consumedSnapshot = new ArrayList<>(consumed);
|
||||
try {
|
||||
@ -866,7 +859,7 @@ public class ArgConsumer {
|
||||
* @see IDatatype
|
||||
* @see IDatatypeFor
|
||||
*/
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrNull(Class<D> datatype) {
|
||||
public <T, D extends IDatatypeFor<T>> T getDatatypeForOrNull(Class<D> datatype) throws CommandNotEnoughArgumentsException {
|
||||
return getDatatypeForOrDefault(datatype, null);
|
||||
}
|
||||
|
||||
@ -915,7 +908,7 @@ public class ArgConsumer {
|
||||
* @see #requireMax(int)
|
||||
* @see #requireExactly(int)
|
||||
*/
|
||||
public void requireMin(int min) {
|
||||
public void requireMin(int min) throws CommandNotEnoughArgumentsException {
|
||||
if (args.size() < min) {
|
||||
throw new CommandNotEnoughArgumentsException(min + consumed.size());
|
||||
}
|
||||
@ -923,11 +916,11 @@ public class ArgConsumer {
|
||||
|
||||
/**
|
||||
* @param max The maximum amount of arguments allowed.
|
||||
* @throws CommandNotEnoughArgumentsException If there are more than {@code max} arguments left.
|
||||
* @throws CommandTooManyArgumentsException If there are more than {@code max} arguments left.
|
||||
* @see #requireMin(int)
|
||||
* @see #requireExactly(int)
|
||||
*/
|
||||
public void requireMax(int max) {
|
||||
public void requireMax(int max) throws CommandTooManyArgumentsException {
|
||||
if (args.size() > max) {
|
||||
throw new CommandTooManyArgumentsException(max + consumed.size());
|
||||
}
|
||||
@ -940,7 +933,7 @@ public class ArgConsumer {
|
||||
* @see #requireMin(int)
|
||||
* @see #requireMax(int)
|
||||
*/
|
||||
public void requireExactly(int args) {
|
||||
public void requireExactly(int args) throws CommandException {
|
||||
requireMin(args);
|
||||
requireMax(args);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
package baritone.api.utils.command.helpers.pagination;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
@ -114,10 +115,10 @@ public class Paginator<E> implements Helper {
|
||||
display(transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
int page = 1;
|
||||
consumer.requireMax(1);
|
||||
if (consumer.has()) {
|
||||
if (consumer.hasAny()) {
|
||||
page = consumer.getAs(Integer.class);
|
||||
if (!pagi.validPage(page)) {
|
||||
throw new CommandInvalidTypeException(
|
||||
@ -137,47 +138,47 @@ public class Paginator<E> implements Helper {
|
||||
pagi.display(transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
paginate(consumer, new Paginator<>(elems), pre, transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
paginate(consumer, Arrays.asList(elems), pre, transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
paginate(consumer, pagi, null, transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
paginate(consumer, new Paginator<>(elems), null, transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform, String commandPrefix) {
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform, String commandPrefix) throws CommandException {
|
||||
paginate(consumer, Arrays.asList(elems), null, transform, commandPrefix);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, pagi, pre, transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, new Paginator<>(elems), pre, transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Runnable pre, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, Arrays.asList(elems), pre, transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, Paginator<T> pagi, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, pagi, null, transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, List<T> elems, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, new Paginator<>(elems), null, transform, null);
|
||||
}
|
||||
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform) {
|
||||
public static <T> void paginate(ArgConsumer consumer, T[] elems, Function<T, ITextComponent> transform) throws CommandException {
|
||||
paginate(consumer, Arrays.asList(elems), null, transform, null);
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalAxis;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -35,7 +36,7 @@ public class AxisCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
Goal goal = new GoalAxis();
|
||||
baritone.getCustomGoalProcess().setGoal(goal);
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.process.IGetToBlockProcess;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -35,7 +36,7 @@ public class BlacklistCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
IGetToBlockProcess proc = baritone.getGetToBlockProcess();
|
||||
if (!proc.isActive()) {
|
||||
|
@ -23,6 +23,7 @@ import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeBlockPos;
|
||||
import baritone.api.utils.command.datatypes.RelativeFile;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@ -42,14 +43,14 @@ public class BuildCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
File file = args.getDatatypePost(RelativeFile.class, schematicsDir).getAbsoluteFile();
|
||||
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
|
||||
file = new File(file.getAbsolutePath() + ".schematic");
|
||||
}
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
BetterBlockPos buildOrigin;
|
||||
if (args.has()) {
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
buildOrigin = args.getDatatype(RelativeBlockPos.class).apply(origin);
|
||||
} else {
|
||||
@ -64,7 +65,7 @@ public class BuildCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return RelativeFile.tabComplete(args, schematicsDir);
|
||||
} else if (args.has(2)) {
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class CancelCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
baritone.getPathingBehavior().cancelEverything();
|
||||
logDirect("ok canceled");
|
||||
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
||||
import baritone.api.cache.IRememberedInventory;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -41,7 +42,7 @@ public class ChestsCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
Set<Map.Entry<BlockPos, IRememberedInventory>> entries =
|
||||
ctx.worldData().getContainerMemory().getRememberedInventories().entrySet();
|
||||
|
@ -24,6 +24,7 @@ import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -38,10 +39,10 @@ public class ClearareaCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
BetterBlockPos pos1 = ctx.playerFeet();
|
||||
BetterBlockPos pos2;
|
||||
if (args.has()) {
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
pos2 = args.getDatatype(RelativeBlockPos.class).apply(pos1);
|
||||
} else {
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class ClickCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
baritone.openClick();
|
||||
logDirect("aight dude");
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -37,7 +38,7 @@ public class ComeCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
Entity entity = mc.getRenderViewEntity();
|
||||
if (entity == null) {
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils.command.defaults;
|
||||
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class EmptyCommand extends Command {
|
||||
|
||||
public EmptyCommand(IBaritone baritone) {
|
||||
super(baritone, Arrays.asList("name1", "name2"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getShortDesc() {
|
||||
return "Short description";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLongDesc() {
|
||||
return Arrays.asList(
|
||||
"",
|
||||
"",
|
||||
"Usage:",
|
||||
"> "
|
||||
);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeGoalXZ;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -35,13 +36,13 @@ public class ExploreCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
if (args.has()) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasAny()) {
|
||||
args.requireExactly(2);
|
||||
} else {
|
||||
args.requireMax(0);
|
||||
}
|
||||
GoalXZ goal = args.has()
|
||||
GoalXZ goal = args.hasAny()
|
||||
? args.getDatatypePost(RelativeGoalXZ.class, ctx.playerFeet())
|
||||
: new GoalXZ(ctx.playerFeet());
|
||||
baritone.getExploreProcess().explore(goal.getX(), goal.getZ());
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeFile;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
@ -39,11 +40,11 @@ public class ExploreFilterCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(2);
|
||||
File file = args.getDatatypePost(RelativeFile.class, mc.gameDir.getAbsoluteFile().getParentFile());
|
||||
boolean invert = false;
|
||||
if (args.has()) {
|
||||
if (args.hasAny()) {
|
||||
if (args.getString().equalsIgnoreCase("invert")) {
|
||||
invert = true;
|
||||
} else {
|
||||
@ -63,7 +64,7 @@ public class ExploreFilterCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return RelativeFile.tabComplete(args, RelativeFile.gameDir());
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class FarmCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
baritone.getFarmProcess().farm();
|
||||
logDirect("Farming");
|
||||
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.BlockById;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
@ -37,9 +38,9 @@ public class FindCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
List<Block> toFind = new ArrayList<>();
|
||||
while (args.has()) {
|
||||
while (args.hasAny()) {
|
||||
toFind.add(args.getDatatypeFor(BlockById.class));
|
||||
}
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
|
@ -24,6 +24,7 @@ import baritone.api.utils.command.datatypes.EntityClassById;
|
||||
import baritone.api.utils.command.datatypes.IDatatype;
|
||||
import baritone.api.utils.command.datatypes.IDatatypeFor;
|
||||
import baritone.api.utils.command.datatypes.PlayerByUsername;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@ -43,7 +44,7 @@ public class FollowCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMin(1);
|
||||
FollowGroup group;
|
||||
FollowList list;
|
||||
@ -55,7 +56,7 @@ public class FollowCommand extends Command {
|
||||
args.requireMin(2);
|
||||
group = null;
|
||||
list = args.getEnum(FollowList.class);
|
||||
while (args.has()) {
|
||||
while (args.hasAny()) {
|
||||
//noinspection unchecked
|
||||
Object gotten = args.getDatatypeFor(list.datatype);
|
||||
if (gotten instanceof Class) {
|
||||
@ -90,7 +91,7 @@ public class FollowCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return new TabCompleteHelper()
|
||||
.append(FollowGroup.class)
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.behavior.IPathingBehavior;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -34,7 +35,7 @@ public class ForceCancelCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
IPathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||
pathingBehavior.cancelEverything();
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class GcCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
System.gc();
|
||||
logDirect("ok called System.gc()");
|
||||
|
@ -25,6 +25,7 @@ import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeCoordinate;
|
||||
import baritone.api.utils.command.datatypes.RelativeGoal;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
|
||||
@ -39,9 +40,9 @@ public class GoalCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
|
||||
if (args.has() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) {
|
||||
if (args.hasAny() && Arrays.asList("reset", "clear", "none").contains(args.peekString())) {
|
||||
args.requireMax(1);
|
||||
if (goalProcess.getGoal() != null) {
|
||||
goalProcess.setGoal(null);
|
||||
@ -59,7 +60,7 @@ public class GoalCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
TabCompleteHelper helper = new TabCompleteHelper();
|
||||
if (args.hasExactlyOne()) {
|
||||
helper.append(Stream.of("reset", "clear", "none", "~"));
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandNotFoundException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.pagination.Paginator;
|
||||
@ -46,9 +47,9 @@ public class HelpCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(1);
|
||||
if (!args.has() || args.is(Integer.class)) {
|
||||
if (!args.hasAny() || args.is(Integer.class)) {
|
||||
Paginator.paginate(
|
||||
args, new Paginator<>(
|
||||
CommandManager.REGISTRY.descendingStream()
|
||||
@ -99,7 +100,7 @@ public class HelpCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalInverted;
|
||||
import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -37,7 +38,7 @@ public class InvertCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||
Goal goal;
|
||||
|
@ -23,6 +23,7 @@ import baritone.api.utils.BlockOptionalMeta;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.BlockById;
|
||||
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.cache.WorldScanner;
|
||||
|
||||
@ -38,11 +39,11 @@ public class MineCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
int quantity = args.getAsOrDefault(Integer.class, 0);
|
||||
args.requireMin(1);
|
||||
List<BlockOptionalMeta> boms = new ArrayList<>();
|
||||
while (args.has()) {
|
||||
while (args.hasAny()) {
|
||||
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
|
||||
}
|
||||
WorldScanner.INSTANCE.repack(ctx);
|
||||
|
@ -24,6 +24,7 @@ import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.RelativeCoordinate;
|
||||
import baritone.api.utils.command.datatypes.RelativeGoal;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.tabcomplete.TabCompleteHelper;
|
||||
@ -40,10 +41,10 @@ public class PathCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||
Goal goal;
|
||||
if (args.has()) {
|
||||
if (args.hasAny()) {
|
||||
args.requireMax(3);
|
||||
goal = args.getDatatype(RelativeGoal.class).apply(ctx.playerFeet());
|
||||
} else if ((goal = customGoalProcess.getGoal()) == null) {
|
||||
@ -56,8 +57,8 @@ public class PathCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
if (args.has() && !args.has(4)) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasAny() && !args.has(4)) {
|
||||
while (args.has(2)) {
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.class) == null) {
|
||||
break;
|
||||
|
@ -23,6 +23,7 @@ import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -81,7 +82,7 @@ public class PauseResumeCommands {
|
||||
);
|
||||
pauseCommand = new Command(baritone, "pause") {
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
if (paused[0]) {
|
||||
throw new CommandInvalidStateException("Already paused");
|
||||
@ -114,7 +115,7 @@ public class PauseResumeCommands {
|
||||
};
|
||||
resumeCommand = new Command(baritone, "resume") {
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
if (!paused[0]) {
|
||||
throw new CommandInvalidStateException("Not paused");
|
||||
@ -145,7 +146,7 @@ public class PauseResumeCommands {
|
||||
};
|
||||
pausedCommand = new Command(baritone, "paused") {
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import baritone.api.pathing.calc.IPathingControlManager;
|
||||
import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -37,7 +38,7 @@ public class ProcCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
|
||||
IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class ReloadAllCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
ctx.worldData().getCachedWorld().reloadAllFromDisk();
|
||||
logDirect("Reloaded");
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -34,7 +35,7 @@ public class RenderCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16;
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.cache.WorldScanner;
|
||||
|
||||
@ -34,7 +35,7 @@ public class RepackCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class SaveAllCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
ctx.worldData().getCachedWorld().save();
|
||||
logDirect("Saved");
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -33,7 +34,7 @@ public class SchematicaCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
baritone.getBuilderProcess().buildOpenSchematic();
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.ForBlockOptionalMeta;
|
||||
import baritone.api.utils.command.datatypes.ForEnumFacing;
|
||||
import baritone.api.utils.command.datatypes.RelativeBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
@ -75,7 +76,7 @@ public class SelCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
Action action = Action.getByName(args.getString());
|
||||
if (action == null) {
|
||||
throw new CommandInvalidTypeException(args.consumed(), "an action");
|
||||
@ -85,7 +86,7 @@ public class SelCommand extends Command {
|
||||
throw new CommandInvalidStateException("Set pos1 first before using pos2");
|
||||
}
|
||||
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(new BlockPos(mc.getRenderViewEntity())) : ctx.playerFeet();
|
||||
BetterBlockPos pos = args.has() ? args.getDatatypePost(RelativeBlockPos.class, playerPos) : playerPos;
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.class, playerPos) : playerPos;
|
||||
args.requireMax(0);
|
||||
if (action == Action.POS1) {
|
||||
pos1 = pos;
|
||||
@ -186,7 +187,7 @@ public class SelCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return new TabCompleteHelper()
|
||||
.append(Action.getAllNames())
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
import baritone.api.utils.command.helpers.pagination.Paginator;
|
||||
@ -48,8 +49,8 @@ public class SetCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
String arg = args.has() ? args.getString().toLowerCase(Locale.US) : "list";
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
String arg = args.hasAny() ? args.getString().toLowerCase(Locale.US) : "list";
|
||||
if (Arrays.asList("s", "save").contains(arg)) {
|
||||
SettingsUtil.save(settings);
|
||||
logDirect("Settings saved");
|
||||
@ -59,7 +60,7 @@ public class SetCommand extends Command {
|
||||
boolean viewAll = Arrays.asList("all", "l", "list").contains(arg);
|
||||
boolean paginate = viewModified || viewAll;
|
||||
if (paginate) {
|
||||
String search = args.has() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
|
||||
String search = args.hasAny() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
|
||||
args.requireMax(1);
|
||||
List<? extends Settings.Setting> toPaginate =
|
||||
(viewModified ? SettingsUtil.modifiedSettings(settings) : settings.allSettings).stream()
|
||||
@ -104,7 +105,7 @@ public class SetCommand extends Command {
|
||||
boolean toggling = arg.equalsIgnoreCase("toggle");
|
||||
boolean doingSomething = resetting || toggling;
|
||||
if (resetting) {
|
||||
if (!args.has()) {
|
||||
if (!args.hasAny()) {
|
||||
logDirect("Please specify 'all' as an argument to reset to confirm you'd really like to do this");
|
||||
logDirect("ALL settings will be reset. Use the 'set modified' or 'modified' commands to see what will be reset.");
|
||||
logDirect("Specify a setting name instead of 'all' to only reset one setting");
|
||||
@ -126,7 +127,7 @@ public class SetCommand extends Command {
|
||||
if (setting == null) {
|
||||
throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
|
||||
}
|
||||
if (!doingSomething && !args.has()) {
|
||||
if (!doingSomething && !args.hasAny()) {
|
||||
logDirect(String.format("Value of setting %s:", setting.getName()));
|
||||
logDirect(settingValueToString(setting));
|
||||
} else {
|
||||
@ -184,8 +185,8 @@ public class SetCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
if (args.has()) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasAny()) {
|
||||
String arg = args.getString();
|
||||
if (args.hasExactlyOne() && !Arrays.asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) {
|
||||
if (arg.equalsIgnoreCase("reset")) {
|
||||
@ -214,7 +215,7 @@ public class SetCommand extends Command {
|
||||
return Stream.of(settingValueToString(setting));
|
||||
}
|
||||
}
|
||||
} else if (!args.has()) {
|
||||
} else if (!args.hasAny()) {
|
||||
return new TabCompleteHelper()
|
||||
.addSettings()
|
||||
.sortAlphabetically()
|
||||
|
@ -21,6 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.GoalXZ;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -34,7 +35,7 @@ public class ThisWayCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireExactly(1);
|
||||
GoalXZ goal = GoalXZ.fromDirection(
|
||||
ctx.playerFeetAsVec(),
|
||||
|
@ -22,6 +22,7 @@ import baritone.api.Settings;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalStrictDirection;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -35,7 +36,7 @@ public class TunnelCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
Goal goal = new GoalStrictDirection(
|
||||
ctx.playerFeet(),
|
||||
|
@ -20,6 +20,7 @@ package baritone.utils.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
|
||||
@ -34,7 +35,7 @@ public class VersionCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
args.requireMax(0);
|
||||
String version = getClass().getPackage().getImplementationVersion();
|
||||
if (version == null) {
|
||||
|
@ -27,6 +27,7 @@ import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.command.Command;
|
||||
import baritone.api.utils.command.datatypes.ForWaypoints;
|
||||
import baritone.api.utils.command.datatypes.RelativeBlockPos;
|
||||
import baritone.api.utils.command.exception.CommandException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.utils.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.utils.command.helpers.arguments.ArgConsumer;
|
||||
@ -52,8 +53,8 @@ public class WaypointsCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) {
|
||||
Action action = args.has() ? Action.getByName(args.getString()) : Action.LIST;
|
||||
protected void executed(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
Action action = args.hasAny() ? Action.getByName(args.getString()) : Action.LIST;
|
||||
if (action == null) {
|
||||
throw new CommandInvalidTypeException(args.consumed(), "an action");
|
||||
}
|
||||
@ -90,7 +91,7 @@ public class WaypointsCommand extends Command {
|
||||
Function<IWaypoint, ITextComponent> transform = waypoint ->
|
||||
toComponent.apply(waypoint, action == Action.LIST ? Action.INFO : action);
|
||||
if (action == Action.LIST) {
|
||||
IWaypoint.Tag tag = args.has() ? IWaypoint.Tag.getByName(args.peekString()) : null;
|
||||
IWaypoint.Tag tag = args.hasAny() ? IWaypoint.Tag.getByName(args.peekString()) : null;
|
||||
if (tag != null) {
|
||||
args.get();
|
||||
}
|
||||
@ -129,8 +130,8 @@ public class WaypointsCommand extends Command {
|
||||
if (tag == null) {
|
||||
throw new CommandInvalidStateException(String.format("'%s' is not a tag ", args.consumedString()));
|
||||
}
|
||||
String name = args.has() ? args.getString() : "";
|
||||
BetterBlockPos pos = args.has()
|
||||
String name = args.hasAny() ? args.getString() : "";
|
||||
BetterBlockPos pos = args.hasAny()
|
||||
? args.getDatatypePost(RelativeBlockPos.class, ctx.playerFeet())
|
||||
: ctx.playerFeet();
|
||||
args.requireMax(0);
|
||||
@ -151,7 +152,7 @@ public class WaypointsCommand extends Command {
|
||||
} else {
|
||||
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.class);
|
||||
IWaypoint waypoint = null;
|
||||
if (args.has() && args.peekString().equals("@")) {
|
||||
if (args.hasAny() && args.peekString().equals("@")) {
|
||||
args.requireExactly(2);
|
||||
args.get();
|
||||
long timestamp = args.getAs(Long.class);
|
||||
@ -241,8 +242,8 @@ public class WaypointsCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
|
||||
if (args.has()) {
|
||||
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) throws CommandException {
|
||||
if (args.hasAny()) {
|
||||
if (args.hasExactlyOne()) {
|
||||
return new TabCompleteHelper()
|
||||
.append(Action.getAllNames())
|
||||
|
Loading…
Reference in New Issue
Block a user