Skip to content

Commit

Permalink
create a no-args constructor that does not send any message
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Apr 1, 2024
1 parent 02e3baa commit f63143c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public class CommandErrorException extends SendableException {

private final Object[] arguments;

/**
* Constructs a new {@link CommandErrorException} that does not send any message.
* <p>
* 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
*
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public class SendMessageException extends SendableException {

private final Object[] arguments;

/**
* Constructs a new {@link SendMessageException} that does not send any message.
* <p>
* 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
*
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
@ThrowableFromCommand
public abstract class SendableException extends RuntimeException {

/**
* Constructs a new {@link SendableException} that does not send any message.
* <p>
* 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
*
Expand Down

0 comments on commit f63143c

Please sign in to comment.