From f63143c4991ef0219800ef927ddc39c6b7f3b7a0 Mon Sep 17 00:00:00 2001 From: Revxrsal Date: Mon, 1 Apr 2024 16:01:21 +0300 Subject: [PATCH] create a no-args constructor that does not send any message --- .../commands/exception/CommandErrorException.java | 13 +++++++++++++ .../commands/exception/SendMessageException.java | 13 +++++++++++++ .../commands/exception/SendableException.java | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/common/src/main/java/revxrsal/commands/exception/CommandErrorException.java b/common/src/main/java/revxrsal/commands/exception/CommandErrorException.java index 4723ccf4..315e7c9d 100644 --- a/common/src/main/java/revxrsal/commands/exception/CommandErrorException.java +++ b/common/src/main/java/revxrsal/commands/exception/CommandErrorException.java @@ -38,6 +38,17 @@ public class CommandErrorException extends SendableException { private final Object[] arguments; + /** + * Constructs a new {@link CommandErrorException} that does not send any message. + *

+ * Use this constructor if you would like to implement your own messaging + * system instead of relying on {@link CommandActor#error(String)}. + */ + public CommandErrorException() { + super(); + this.arguments = new Object[0]; + } + /** * Constructs a new {@link CommandErrorException} with an inferred actor * @@ -54,6 +65,8 @@ public CommandErrorException(String message, Object... arguments) { * @param actor Actor to send to */ @Override public void sendTo(@NotNull CommandActor actor) { + if (getMessage().isEmpty()) + return; actor.errorLocalized(getMessage(), arguments); } } diff --git a/common/src/main/java/revxrsal/commands/exception/SendMessageException.java b/common/src/main/java/revxrsal/commands/exception/SendMessageException.java index ef1ddfcb..bd8542bc 100644 --- a/common/src/main/java/revxrsal/commands/exception/SendMessageException.java +++ b/common/src/main/java/revxrsal/commands/exception/SendMessageException.java @@ -37,6 +37,17 @@ public class SendMessageException extends SendableException { private final Object[] arguments; + /** + * Constructs a new {@link SendMessageException} that does not send any message. + *

+ * Use this constructor if you would like to implement your own messaging + * system instead of relying on {@link CommandActor#reply(String)}. + */ + public SendMessageException() { + super(); + this.arguments = new Object[0]; + } + /** * Constructs a new {@link SendMessageException} with an inferred actor * @@ -53,6 +64,8 @@ public SendMessageException(String message, Object... arguments) { * @param actor Actor to send to */ @Override public void sendTo(@NotNull CommandActor actor) { + if (getMessage().isEmpty()) + return; actor.replyLocalized(getMessage(), arguments); } } diff --git a/common/src/main/java/revxrsal/commands/exception/SendableException.java b/common/src/main/java/revxrsal/commands/exception/SendableException.java index b6b7f71c..1be869d7 100644 --- a/common/src/main/java/revxrsal/commands/exception/SendableException.java +++ b/common/src/main/java/revxrsal/commands/exception/SendableException.java @@ -35,6 +35,16 @@ @ThrowableFromCommand public abstract class SendableException extends RuntimeException { + /** + * Constructs a new {@link SendableException} that does not send any message. + *

+ * Use this constructor if you would like to implement your own messaging + * system instead of relying on {@link CommandActor#reply(String)}. + */ + public SendableException() { + this(""); + } + /** * Constructs a new {@link SendableException} with an inferred actor *