Fix the scuff

This commit is contained in:
Brady
2019-09-26 23:33:37 -05:00
parent 45bea50c91
commit b75a78f3d3
5 changed files with 37 additions and 15 deletions
+5 -2
View File
@@ -37,6 +37,11 @@ public interface Helper {
*/ */
Helper HELPER = new Helper() {}; Helper HELPER = new Helper() {};
/**
* Instance of the game
*/
Minecraft mc = Minecraft.getMinecraft();
static ITextComponent getPrefix() { static ITextComponent getPrefix() {
// Inner text component // Inner text component
ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone"); ITextComponent baritone = new TextComponentString(BaritoneAPI.getSettings().shortBaritonePrefix.value ? "B" : "Baritone");
@@ -52,8 +57,6 @@ public interface Helper {
return prefix; return prefix;
} }
Minecraft mc = Minecraft.getMinecraft();
/** /**
* Send a message to chat only if chatDebug is on * Send a message to chat only if chatDebug is on
* *
@@ -72,8 +72,7 @@ public class ArgParserManager {
public static <T> T parseStateless(Class<T> type, CommandArgument arg) throws CommandInvalidTypeException { public static <T> T parseStateless(Class<T> type, CommandArgument arg) throws CommandInvalidTypeException {
IArgParser.Stateless<T> parser = getParserStateless(type); IArgParser.Stateless<T> parser = getParserStateless(type);
if (parser == null) { if (parser == null) {
// TODO: Fix this scuff lol throw new CommandNoParserForTypeException(type);
throw new CommandUnhandledException(new CommandNoParserForTypeException(type));
} }
try { try {
return parser.parseArg(arg); return parser.parseArg(arg);
@@ -95,8 +94,7 @@ public class ArgParserManager {
public static <T, S> T parseStated(Class<T> type, Class<S> stateKlass, CommandArgument arg, S state) throws CommandInvalidTypeException { public static <T, S> T parseStated(Class<T> type, Class<S> stateKlass, CommandArgument arg, S state) throws CommandInvalidTypeException {
IArgParser.Stated<T, S> parser = getParserStated(type, stateKlass); IArgParser.Stated<T, S> parser = getParserStated(type, stateKlass);
if (parser == null) { if (parser == null) {
// TODO: Fix this scuff lol throw new CommandNoParserForTypeException(type);
throw new CommandUnhandledException(new CommandNoParserForTypeException(type));
} }
try { try {
return parser.parseArg(arg, state); return parser.parseArg(arg, state);
@@ -17,12 +17,9 @@
package baritone.api.utils.command.exception; package baritone.api.utils.command.exception;
public class CommandNoParserForTypeException extends CommandErrorMessageException { public class CommandNoParserForTypeException extends CommandUnhandledException {
public final Class<?> klass;
public CommandNoParserForTypeException(Class<?> klass) { public CommandNoParserForTypeException(Class<?> klass) {
super(String.format("Could not find a handler for type %s", klass.getSimpleName())); super(String.format("Could not find a handler for type %s", klass.getSimpleName()));
this.klass = klass;
} }
} }
@@ -17,10 +17,30 @@
package baritone.api.utils.command.exception; 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 class CommandUnhandledException extends RuntimeException implements ICommandException { public class CommandUnhandledException extends RuntimeException implements ICommandException {
public CommandUnhandledException(String message) {
super(message);
}
public CommandUnhandledException(Throwable cause) { public CommandUnhandledException(Throwable cause) {
super("An unhandled exception occurred. The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues"); super(cause);
cause.printStackTrace(); }
@Override
public void handle(Command command, List<CommandArgument> args) {
HELPER.logDirect("An unhandled exception occurred." +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED);
this.printStackTrace();
} }
} }
@@ -21,6 +21,7 @@ import baritone.api.utils.command.Command;
import baritone.api.utils.command.argument.CommandArgument; import baritone.api.utils.command.argument.CommandArgument;
import baritone.api.utils.command.exception.CommandException; import baritone.api.utils.command.exception.CommandException;
import baritone.api.utils.command.exception.CommandUnhandledException; import baritone.api.utils.command.exception.CommandUnhandledException;
import baritone.api.utils.command.exception.ICommandException;
import baritone.api.utils.command.helpers.arguments.ArgConsumer; import baritone.api.utils.command.helpers.arguments.ArgConsumer;
import baritone.api.utils.command.manager.ICommandManager; import baritone.api.utils.command.manager.ICommandManager;
import com.mojang.realmsclient.util.Pair; import com.mojang.realmsclient.util.Pair;
@@ -68,10 +69,13 @@ public class CommandExecution {
public void execute() { public void execute() {
try { try {
command.execute(this); command.execute(this);
} catch (CommandException e) {
e.handle(command, args.args);
} catch (Throwable t) { } catch (Throwable t) {
new CommandUnhandledException(t).handle(command, args.args); // Create a handleable exception, wrap if needed
ICommandException exception = t instanceof ICommandException
? (ICommandException) t
: new CommandUnhandledException(t);
exception.handle(command, args.args);
} }
} }