diff options
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/command/exception')
4 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/command/exception/ApiContactException.java b/src/main/java/eu/olli/cowmoonication/command/exception/ApiContactException.java new file mode 100644 index 0000000..9dd8d9e --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/command/exception/ApiContactException.java @@ -0,0 +1,7 @@ +package eu.olli.cowmoonication.command.exception; + +public class ApiContactException extends MooCommandException { + public ApiContactException(String api, String failedAction) { + super("Sorry, couldn't contact the " + api + " API and thus " + failedAction); + } +} diff --git a/src/main/java/eu/olli/cowmoonication/command/exception/InvalidPlayerNameException.java b/src/main/java/eu/olli/cowmoonication/command/exception/InvalidPlayerNameException.java new file mode 100644 index 0000000..7afdeaa --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/command/exception/InvalidPlayerNameException.java @@ -0,0 +1,10 @@ +package eu.olli.cowmoonication.command.exception; + +import net.minecraft.command.SyntaxErrorException; +import net.minecraft.util.EnumChatFormatting; + +public class InvalidPlayerNameException extends SyntaxErrorException { + public InvalidPlayerNameException(String playerName) { + super(EnumChatFormatting.DARK_RED + playerName + EnumChatFormatting.RED + "? This... doesn't look like a valid username."); + } +} diff --git a/src/main/java/eu/olli/cowmoonication/command/exception/MooCommandException.java b/src/main/java/eu/olli/cowmoonication/command/exception/MooCommandException.java new file mode 100644 index 0000000..6c3cb08 --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/command/exception/MooCommandException.java @@ -0,0 +1,9 @@ +package eu.olli.cowmoonication.command.exception; + +import net.minecraft.command.CommandException; + +public class MooCommandException extends CommandException { + public MooCommandException(String msg) { + super("cowmoonication.commands.generic.exception", msg); + } +} diff --git a/src/main/java/eu/olli/cowmoonication/command/exception/ThrowingConsumer.java b/src/main/java/eu/olli/cowmoonication/command/exception/ThrowingConsumer.java new file mode 100644 index 0000000..589ada6 --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/command/exception/ThrowingConsumer.java @@ -0,0 +1,25 @@ +package eu.olli.cowmoonication.command.exception; + +import eu.olli.cowmoonication.Cowmoonication; +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); + Cowmoonication.getInstance().getChatHelper().sendMessage(errorMsg); + } + } + + void acceptThrows(T t) throws CommandException; +} |