mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Fix locales in command exception messages
This also removes usage of MinecraftExceptionHandler, no point in using it if we basically reimplement the whole thing, and don't even use the decorator function
This commit is contained in:
12 files changed
+78
-65
No files matched your search
+1
-2
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.common.command.arguments;
|
||||
package net.draycia.carbon.common.command.argument;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
@@ -8,7 +8,6 @@ import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Predicate;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.draycia.carbon.common.command.arguments;
|
||||
package net.draycia.carbon.common.command.argument;
|
||||
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
@@ -6,7 +6,7 @@ import java.util.ArrayList;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.arguments.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
@@ -9,7 +9,6 @@ import cloud.commandframework.minecraft.extras.MinecraftHelp;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageSource;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
@@ -81,13 +80,6 @@ public final class HelpCommand {
|
||||
|
||||
help.messageProvider((sender, key, args) -> {
|
||||
final String messageKey = "command.help." + key;
|
||||
final String forAudience;
|
||||
// todo: Should CarbonMessageSource unwrap PlayerCommanders?
|
||||
if (sender instanceof PlayerCommander playerCommander) {
|
||||
forAudience = messageSource.messageOf(playerCommander.carbonPlayer(), messageKey);
|
||||
} else {
|
||||
forAudience = messageSource.messageOf(sender, messageKey);
|
||||
}
|
||||
final TemplateResolver resolver;
|
||||
|
||||
// Total hack but works for now
|
||||
@@ -100,7 +92,7 @@ public final class HelpCommand {
|
||||
resolver = TemplateResolver.empty();
|
||||
}
|
||||
|
||||
return MiniMessage.miniMessage().deserialize(forAudience, resolver);
|
||||
return MiniMessage.miniMessage().deserialize(messageSource.messageOf(sender, messageKey), resolver);
|
||||
});
|
||||
|
||||
return help;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.permission.Permission;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
@@ -12,7 +11,7 @@ import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.punishments.MuteEntry;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.arguments.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ import java.util.regex.Pattern;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.arguments.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.arguments.OptionValueParser;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.OptionValueParser;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
@@ -5,12 +5,11 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiPredicate;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.arguments.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.arguments.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
|
||||
public class WhisperCommand {
|
||||
|
||||
@@ -262,21 +262,22 @@ public interface CarbonMessageService {
|
||||
);
|
||||
|
||||
@Message("error.command.no_permission")
|
||||
Component errorCommandNoPermission();
|
||||
void errorCommandNoPermission(final Audience audience);
|
||||
|
||||
@Message("error.command.command_execution")
|
||||
Component errorCommandCommandExecution(
|
||||
void errorCommandCommandExecution(
|
||||
final Audience audience,
|
||||
final @Placeholder("throwable_message") Component throwableMessage,
|
||||
final @Placeholder String stacktrace
|
||||
);
|
||||
|
||||
@Message("error.command.argument_parsing")
|
||||
Component errorCommandArgumentParsing(final @Placeholder("throwable_message") Component throwableMessage);
|
||||
void errorCommandArgumentParsing(final Audience audience, final @Placeholder("throwable_message") Component throwableMessage);
|
||||
|
||||
@Message("error.command.invalid_sender")
|
||||
Component errorCommandInvalidSender(final @Placeholder String sender_type);
|
||||
void errorCommandInvalidSender(final Audience audience, final @Placeholder String sender_type);
|
||||
|
||||
@Message("error.command.invalid_syntax")
|
||||
Component errorCommandInvalidSyntax(final @Placeholder Component syntax);
|
||||
void errorCommandInvalidSyntax(final Audience audience, final @Placeholder Component syntax);
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.ForCarbon;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
@@ -110,10 +111,17 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
||||
|
||||
@Override
|
||||
public String messageOf(final Audience receiver, final String messageKey) {
|
||||
if (receiver instanceof CarbonPlayer player) {
|
||||
Audience audience = receiver;
|
||||
|
||||
// Unwrap PlayerCommanders
|
||||
if (audience instanceof PlayerCommander playerCommander) {
|
||||
audience = playerCommander.carbonPlayer();
|
||||
}
|
||||
|
||||
if (audience instanceof CarbonPlayer player) {
|
||||
return this.forPlayer(messageKey, player);
|
||||
} else {
|
||||
return this.forAudience(messageKey, receiver);
|
||||
return this.forAudience(messageKey, audience);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user