blob: 0efd9c5418c264f69aac6390cd731ce6c8b92d9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package de.cowtipper.cowlection.command.exception;
import de.cowtipper.cowlection.Cowlection;
import net.minecraft.command.CommandException;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import java.util.function.Consumer;
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {
@Override
default void accept(T t) {
try {
acceptThrows(t);
} catch (CommandException e) {
IChatComponent errorMsg = new ChatComponentTranslation(e.getMessage(), e.getErrorObjects());
errorMsg.getChatStyle().setColor(EnumChatFormatting.RED);
Cowlection.getInstance().getChatHelper().sendMessage(errorMsg);
}
}
void acceptThrows(T t) throws CommandException;
}
|