From 03407ef0819d89ab199fe35ed759405de752c900 Mon Sep 17 00:00:00 2001 From: Draycia Date: Mon, 6 Dec 2021 22:28:57 -0800 Subject: [PATCH] don't throw exceptions in commands --- .../draycia/carbon/common/command/commands/MuteCommand.java | 5 ++++- .../carbon/common/command/commands/UnmuteCommand.java | 5 ++++- .../carbon/common/messages/CarbonMessageService.java | 6 ++++++ common/src/main/resources/locale/messages-en_US.properties | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/MuteCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/MuteCommand.java index 8ca6243c..5f3a07aa 100644 --- a/common/src/main/java/net/draycia/carbon/common/command/commands/MuteCommand.java +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/MuteCommand.java @@ -22,6 +22,7 @@ package net.draycia.carbon.common.command.commands; import cloud.commandframework.ArgumentDescription; import cloud.commandframework.CommandManager; import cloud.commandframework.arguments.standard.UUIDArgument; +import cloud.commandframework.exceptions.CommandExecutionException; import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys; import com.google.inject.Inject; import java.util.Objects; @@ -67,7 +68,9 @@ public class MuteCommand { final var result = carbonChat.server().player(handler.get("uuid")).join(); target = Objects.requireNonNull(result.player(), "No player found for UUID."); } else { - throw new IllegalStateException("No target found to unmute."); + messageService.muteNoTarget(sender); + // TODO: send command syntax + return; } if (target.hasPermission("carbon.mute.exempt")) { diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/UnmuteCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/UnmuteCommand.java index aabbe695..14dcc313 100644 --- a/common/src/main/java/net/draycia/carbon/common/command/commands/UnmuteCommand.java +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/UnmuteCommand.java @@ -22,6 +22,7 @@ package net.draycia.carbon.common.command.commands; import cloud.commandframework.ArgumentDescription; import cloud.commandframework.CommandManager; import cloud.commandframework.arguments.standard.UUIDArgument; +import cloud.commandframework.exceptions.CommandExecutionException; import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys; import com.google.inject.Inject; import java.util.Objects; @@ -68,7 +69,9 @@ public class UnmuteCommand { final var result = carbonChat.server().player(handler.get("uuid")).join(); target = Objects.requireNonNull(result.player(), "No player found for UUID."); } else { - throw new IllegalStateException("No target found to unmute."); + messageService.unmuteNoTarget(sender); + // TODO: send command syntax + return; } messageService.unmuteAlertRecipient(target); diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java index c4dcd3a4..aaf773d4 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessageService.java @@ -74,6 +74,9 @@ public interface CarbonMessageService { @Message("mute.unmute.alert.players") void unmuteAlertPlayers(final Audience audience, final Component target); + @Message("mute.unmute.no_target") + void unmuteNoTarget(final Audience audience); + @Message("mute.exempt") void muteExempt(final Audience audience); @@ -86,6 +89,9 @@ public interface CarbonMessageService { @Message("mute.cannot_speak") void muteCannotSpeak(final Audience audience); + @Message("mute.no_target") + void muteNoTarget(final Audience audience); + @Message("mute.spy.prefix") RenderedMessage muteSpyPrefix(final Audience audience); diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index 20610bce..0b6d067e 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -32,9 +32,11 @@ mute.info.muted= is muted mute.info.not_muted= is not muted mute.info.self.muted=You are muted mute.info.self.not_muted=You are not muted +mute.no_target=No specified player to mute. mute.spy.prefix=MutedM mute.unmute.alert.players= has been unmuted mute.unmute.alert.target=You have been unmuted +mute.unmute.no_target=No specified player to unmute. nickname.reset.others='s nickname was reset nickname.reset=Your nickname was reset nickname.set.others=You set 's nickname to