aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2021-04-09 14:48:24 +0200
committerCow <cow@volloeko.de>2021-04-09 14:48:24 +0200
commita3f2cd8c51179c54661751525ae02249d0341934 (patch)
treed6db22266f6cf94312ca24aba4fd69b685f1510b /src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
parent911e7b32e781b327fb87f7229bfea34389636b5d (diff)
downloadCowlection-a3f2cd8c51179c54661751525ae02249d0341934.tar.gz
Cowlection-a3f2cd8c51179c54661751525ae02249d0341934.tar.bz2
Cowlection-a3f2cd8c51179c54661751525ae02249d0341934.zip
Added Dungeons Master mode support
- fixed unexpected API-related exceptions voiding chat output
Diffstat (limited to 'src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java b/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
index 0efd9c5..9eae1c3 100644
--- a/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
+++ b/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
@@ -1,6 +1,7 @@
package de.cowtipper.cowlection.command.exception;
import de.cowtipper.cowlection.Cowlection;
+import de.cowtipper.cowlection.util.MooChatComponent;
import net.minecraft.command.CommandException;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
@@ -15,11 +16,28 @@ public interface ThrowingConsumer<T> extends Consumer<T> {
try {
acceptThrows(t);
} catch (CommandException e) {
- IChatComponent errorMsg = new ChatComponentTranslation(e.getMessage(), e.getErrorObjects());
+ ChatComponentTranslation errorMsg = new ChatComponentTranslation(e.getMessage(), e.getErrorObjects());
errorMsg.getChatStyle().setColor(EnumChatFormatting.RED);
- Cowlection.getInstance().getChatHelper().sendMessage(errorMsg);
+ handleException(e, errorMsg);
+ } catch (Exception e) {
+ String stackTraceInfo = null;
+ for (StackTraceElement traceElement : e.getStackTrace()) {
+ if (traceElement.getClassName().startsWith("de.cowtipper")) {
+ stackTraceInfo = traceElement.getClassName()
+ + EnumChatFormatting.WHITE + "#" + EnumChatFormatting.GRAY + traceElement.getMethodName()
+ + EnumChatFormatting.WHITE + ":" + EnumChatFormatting.GRAY + traceElement.getLineNumber();
+ break;
+ }
+ }
+ handleException(e, new MooChatComponent(EnumChatFormatting.DARK_RED + "Something went wrong: " + EnumChatFormatting.RED + e.toString()
+ + (stackTraceInfo == null ? "" : EnumChatFormatting.GRAY + " (" + EnumChatFormatting.WHITE + "in " + EnumChatFormatting.GRAY + stackTraceInfo + EnumChatFormatting.GRAY + ")")));
}
}
+ default void handleException(Exception exception, IChatComponent errorMsg) {
+ Cowlection.getInstance().getChatHelper().sendMessage(errorMsg);
+ exception.printStackTrace();
+ }
+
void acceptThrows(T t) throws CommandException;
}