Make command help translatable

This commit is contained in:
Draycia committed 2021-12-07 15:27:58 -08:00
1 parent 4fa8e66a9c
commit efd547f030
18 files changed
+418 -231

No files matched your search

@@ -1,153 +1,240 @@
/*
* CarbonChat
*
* Copyright (c) 2021 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//
// MIT License
//
// Copyright (c) 2021 Alexander Söderberg & Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package net.draycia.carbon.common.command.argument;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.captions.Caption;
import cloud.commandframework.captions.CaptionVariable;
import cloud.commandframework.context.CommandContext;
import com.google.inject.Inject;
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
import cloud.commandframework.exceptions.parsing.ParserException;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.function.BiPredicate;
import net.draycia.carbon.api.CarbonServer;
import java.util.function.BiFunction;
import net.draycia.carbon.api.CarbonChatProvider;
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.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public class CarbonPlayerArgument {
/**
* Argument that parses into a {@link CarbonPlayer}.
*/
@SuppressWarnings("unused")
public final class CarbonPlayerArgument extends CommandArgument<Commander, CarbonPlayer> {
private final CarbonServer server;
@Inject
public CarbonPlayerArgument(final CarbonServer server) {
this.server = server;
}
public static final BiPredicate<CarbonPlayer, CarbonPlayer> NO_FILTER = (sender, target) -> true;
public static final BiPredicate<CarbonPlayer, CarbonPlayer> NO_SENDER = (sender, target) -> !sender.equals(target);
public CommandArgument<Commander, CarbonPlayer> newInstance(
private CarbonPlayerArgument(
final boolean required,
final String name,
final BiPredicate<CarbonPlayer, CarbonPlayer> filter
final @NonNull String name,
final @NonNull String defaultValue,
final @Nullable BiFunction<@NonNull CommandContext<Commander>, @NonNull String,
@NonNull List<@NonNull String>> suggestionsProvider,
final @NonNull ArgumentDescription defaultDescription,
final @NonNull CarbonMessageService messageService
) {
return new CarbonPlayerArgumentImpl(required, name,
new CarbonPlayerArgumentParser(this.server, filter), CarbonPlayer.class);
super(required, name, new CarbonPlayerParser(messageService), defaultValue, CarbonPlayer.class, suggestionsProvider, defaultDescription);
}
public CommandArgument<Commander, CarbonPlayer> newInstance(
final boolean required,
final String name
) {
return new CarbonPlayerArgumentImpl(required, name,
new CarbonPlayerArgumentParser(this.server, NO_FILTER), CarbonPlayer.class);
/**
* Create a new builder.
*
* @param name name of the component
* @return created builder
*/
public static @NonNull Builder newBuilder(final @NonNull String name) {
return new Builder(name);
}
public static final class CarbonPlayerArgumentImpl extends CommandArgument<Commander, CarbonPlayer> {
/**
* Create a new required command component.
*
* @param name component name
* @return created component
*/
public static @NonNull CommandArgument<Commander, CarbonPlayer> of(final @NonNull String name) {
return CarbonPlayerArgument.newBuilder(name).asRequired().build();
}
CarbonPlayerArgumentImpl(
final boolean required,
final String name,
final ArgumentParser<Commander, CarbonPlayer> parser,
final Class<CarbonPlayer> valueType
) {
super(required, name, parser, valueType);
/**
* Create a new optional command component.
*
* @param name component name
* @return created component
*/
public static @NonNull CommandArgument<Commander, CarbonPlayer> optional(final @NonNull String name) {
return CarbonPlayerArgument.newBuilder(name).asOptional().build();
}
/**
* Create a new required command component with a default value.
*
* @param name component name
* @param defaultCarbonPlayer default player
* @return created component
*/
public static @NonNull CommandArgument<Commander, CarbonPlayer> optional(
final @NonNull String name,
final @NonNull String defaultCarbonPlayer
) {
return CarbonPlayerArgument.newBuilder(name).asOptionalWithDefault(defaultCarbonPlayer).build();
}
public static final class Builder extends CommandArgument.Builder<Commander, CarbonPlayer> {
private CarbonMessageService messageService;
private Builder(final @NonNull String name) {
super(CarbonPlayer.class, name);
}
/**
* Set the message service.
*
* @param messageService the message service
* @return builder instance
*/
public Builder withMessageService(final @NonNull CarbonMessageService messageService) {
this.messageService = messageService;
return this;
}
/**
* Builder a new boolean component.
*
* @return constructed component
*/
@Override
public @NonNull CarbonPlayerArgument build() {
return new CarbonPlayerArgument(
this.isRequired(),
this.getName(),
this.getDefaultValue(),
this.getSuggestionsProvider(),
this.getDefaultDescription(),
this.messageService
);
}
}
private static final class CarbonPlayerArgumentParser implements ArgumentParser<Commander, CarbonPlayer> {
public static final class CarbonPlayerParser implements ArgumentParser<Commander, CarbonPlayer> {
final CarbonServer server;
final BiPredicate<CarbonPlayer, CarbonPlayer> filter;
private final @NonNull CarbonMessageService messageService;
@Inject
CarbonPlayerArgumentParser(
final CarbonServer carbonServer,
final BiPredicate<CarbonPlayer, CarbonPlayer> filter
) {
this.server = carbonServer;
this.filter = filter;
public CarbonPlayerParser(final @NonNull CarbonMessageService messageService) {
this.messageService = messageService;
}
@Override
public ArgumentParseResult<CarbonPlayer> parse(
final CommandContext<Commander> commandContext,
final Queue<String> inputQueue
@SuppressWarnings("deprecation")
public @NonNull ArgumentParseResult<CarbonPlayer> parse(
final @NonNull CommandContext<Commander> commandContext,
final @NonNull Queue<@NonNull String> inputQueue
) {
final @Nullable String input = inputQueue.peek();
final String input = inputQueue.peek();
if (input == null) {
return ArgumentParseResult.failure(new NoInputProvidedException(
CarbonPlayerParser.class,
commandContext
));
}
inputQueue.remove();
for (final var player : this.server.players()) {
if (player.username().equalsIgnoreCase(input)) {
inputQueue.remove();
return ArgumentParseResult.success(player);
final var playerResult = CarbonChatProvider.carbonChat().server().player(input).join();
if (playerResult.player() == null) {
return ArgumentParseResult.failure(new CarbonPlayerParseException(input, commandContext, this.messageService));
}
return ArgumentParseResult.success(playerResult.player());
}
@Override
public @NonNull List<@NonNull String> suggestions(
final @NonNull CommandContext<Commander> commandContext,
final @NonNull String input
) {
final List<String> output = new ArrayList<>();
for (final CarbonPlayer player : CarbonChatProvider.carbonChat().server().players()) {
if (commandContext.getSender() instanceof PlayerCommander playerCommander) {
if (!playerCommander.carbonPlayer().awareOf(player)) {
continue;
}
}
output.add(player.username());
}
return ArgumentParseResult.failure(new PlayerParseException(input));
}
@Override
public List<String> suggestions(
final CommandContext<Commander> commandContext,
final String input
) {
if (commandContext.getSender() instanceof PlayerCommander sender) {
return this.server.players().stream()
.filter(it -> this.filter.test(sender.carbonPlayer(), it))
.filter(sender.carbonPlayer()::awareOf)
.map(CarbonPlayer::username)
.toList();
} else {
return this.server.players().stream()
.map(CarbonPlayer::username)
.toList();
}
return output;
}
}
public static final class PlayerParseException extends RuntimeException {
/**
* CarbonPlayer parse exception.
*/
public static final class CarbonPlayerParseException extends ParserException {
private static final long serialVersionUID = -8703083769083215214L;
private static final long serialVersionUID = -8331761537951077684L;
private final String input;
public PlayerParseException(
final String input
/**
* Construct a new CarbonPlayer parse exception.
*
* @param input string input
* @param context command context
*/
public CarbonPlayerParseException(
final @NonNull String input,
final @NonNull CommandContext<?> context,
final @NonNull CarbonMessageService messageService
) {
super(
CarbonPlayerParser.class,
context,
Caption.of("argument.parse.failure.player"),
CaptionVariable.of("input", input)
);
this.input = input;
}
public String input() {
/**
* Get the supplied input.
*
* @return string value
*/
public @NonNull String input() {
return this.input;
}
@Override
public String getMessage() {
return "No player found for input: '" + this.input + "'";
}
}
}
@@ -27,6 +27,7 @@ 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.config.PrimaryConfig;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
public class ClearChatCommand {
@@ -35,12 +36,13 @@ public class ClearChatCommand {
public ClearChatCommand(
final CarbonChat carbonChat,
final CommandManager<Commander> commandManager,
final PrimaryConfig config
final PrimaryConfig config,
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("clearchat", "chatclear", "cc")
.permission("carbon.clearchat.clear")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Clears the chat window for all players."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandClearChatDescription().component())
.handler(handler -> {
// Not fond of having to send 50 messages to each player
// Are we not able to just paste in 50 newlines and call it a day?
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.UUID;
import net.draycia.carbon.api.CarbonChat;
@@ -47,10 +47,11 @@ public class ContinueCommand {
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("continue", "c")
.argument(StringArgument.greedy("message"), ArgumentDescription.of("The message to send."))
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandContinueArgumentMessage().component()))
.permission("carbon.whisper.continue")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Sends a message to the last person you messaged."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandContinueDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
@@ -81,7 +82,7 @@ public class ContinueCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
@@ -19,15 +19,16 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
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.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -37,14 +38,14 @@ public class DebugCommand {
@Inject
public DebugCommand(
final CommandManager<Commander> commandManager,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("carbondebug", "cdebug")
.argument(carbonPlayerArgument.newInstance(false, "player"),
ArgumentDescription.of("The player to check the groups of."))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandDebugArgumentPlayer().component()))
.permission("carbon.debug")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Shows the permission groups of players."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandDebugDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -24,13 +24,13 @@ import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.minecraft.extras.AudienceProvider;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.List;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.messages.CarbonMessageSource;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.text.minimessage.template.TemplateResolver;
@@ -52,19 +52,19 @@ public final class HelpCommand {
@Inject
public HelpCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageSource messageSource
final CarbonMessageSource messageSource,
final CarbonMessageService messageService
) {
this.manager = commandManager;
this.help = createHelp(commandManager, messageSource);
final var command = commandManager.commandBuilder("carbon")
.literal("help")
.literal("help",
RichDescription.of(messageService.commandHelpDescription().component()))
.argument(StringArgument.<Commander>newBuilder("query")
.greedy()
.withSuggestionsProvider(this::suggestQueries)
.asOptional())
.greedy().withSuggestionsProvider(this::suggestQueries).asOptional(),
RichDescription.of(messageService.commandHelpArgumentQuery().component()))
.permission("carbon.help")
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Carbon command list."))
.handler(this::execute)
.build();
@@ -101,7 +101,7 @@ public final class HelpCommand {
);
help.messageProvider((sender, key, args) -> {
final String messageKey = "command.help." + key;
final String messageKey = "command.help.misc." + key;
final TemplateResolver resolver;
// Total hack but works for now
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.UUID;
@@ -32,7 +32,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -43,20 +42,19 @@ public class IgnoreCommand {
public IgnoreCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("ignore", "block")
.argument(carbonPlayerArgument.newInstance(false, "player", CarbonPlayerArgument.NO_SENDER),
ArgumentDescription.of("The name of the player to ignore."))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandIgnoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(ArgumentDescription.of("The UUID of the player to ignore."))
.withDescription(RichDescription.of(messageService.commandIgnoreArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.ignore.ignore")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Hides all incoming messages from ignored players."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandIgnoreDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.UUID;
@@ -32,7 +32,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -43,20 +42,19 @@ public class MuteCommand {
public MuteCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("mute")
.argument(carbonPlayerArgument.newInstance(false, "player", CarbonPlayerArgument.NO_SENDER),
ArgumentDescription.of("The name of the player to mute."))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandMuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(ArgumentDescription.of("The UUID of the player to mute."))
.withDescription(RichDescription.of(messageService.commandMuteArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute.mute")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Mutes players, preventing them from using chat or whispering other players."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandMuteDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.UUID;
@@ -32,7 +32,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -43,19 +42,19 @@ public class MuteInfoCommand {
public MuteInfoCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("muteinfo", "muted")
.argument(carbonPlayerArgument.newInstance(false, "player"), ArgumentDescription.of("The name of the player."))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandMuteInfoArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(ArgumentDescription.of("The UUID of the player."))
.withDescription(RichDescription.of(messageService.commandMuteInfoArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute.info")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Shows if players are muted or not."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandMuteInfoDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.compound.FlagArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import cloud.commandframework.permission.Permission;
import com.google.inject.Inject;
import net.draycia.carbon.api.users.CarbonPlayer;
@@ -31,7 +31,6 @@ import net.draycia.carbon.common.command.PlayerCommander;
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.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -40,19 +39,19 @@ public class NicknameCommand {
@Inject
public NicknameCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonMessageService messageService
) {
final var command = commandManager.commandBuilder("nickname", "nick")
// TODO: Allow UUID input for target player
.flag(commandManager.flagBuilder("player")
.withAliases("p")
.withDescription(ArgumentDescription.of("The name of the target player. Without this flag, the sender is the target."))
.withArgument(carbonPlayerArgument.newInstance(true, "recipient"))
.withDescription(RichDescription.of(messageService.commandNicknameArgumentPlayer().component()))
.withArgument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional())
.withPermission(Permission.of("carbon.nickname.others"))
)
.flag(commandManager.flagBuilder("nickname")
.withAliases("n")
.withDescription(ArgumentDescription.of("The nickname to set."))
.withDescription(RichDescription.of(messageService.commandNicknameArgumentNickname().component()))
.withArgument(FlagArgument.<Commander, String>ofType(String.class, "value")
.withParser(new OptionValueParser<>())
.asOptional()
@@ -61,12 +60,12 @@ public class NicknameCommand {
)
.flag(commandManager.flagBuilder("reset")
.withAliases("r")
.withDescription(ArgumentDescription.of("Removes any set nickname from the player."))
.withDescription(RichDescription.of(messageService.commandNicknameArgumentReset().component()))
.withPermission(Permission.of("carbon.nickname.set"))
)
.permission("carbon.nickname")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Sets and shows player nicknames."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandNicknameDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
@@ -27,7 +27,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.config.PrimaryConfig;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -45,7 +44,7 @@ public class ReloadCommand {
final var command = commandManager.commandBuilder("creload", "carbonreload")
.permission("carbon.reload")
.senderType(Commander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Reloads carbon's config, channel settings, and translations. Will not load or unload any channels."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandReloadDescription().component())
.handler(handler -> {
channelRegistry.reloadRegisteredConfigChannels();
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.UUID;
import net.draycia.carbon.api.CarbonChat;
@@ -50,10 +50,11 @@ public class ReplyCommand {
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("reply", "r")
.argument(StringArgument.greedy("message"), ArgumentDescription.of("The message to reply with."))
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandReplyArgumentMessage().component()))
.permission("carbon.whisper.reply")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Sends a message to the last player that messaged you."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandReplyDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
@@ -83,7 +84,7 @@ public class ReplyCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.UUID;
@@ -32,7 +32,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -43,21 +42,20 @@ public class UnignoreCommand {
public UnignoreCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("unignore", "unblock")
// TODO: Filter, and only show muted players, but allow inputting any player name.
.argument(carbonPlayerArgument.newInstance(false, "player"),
ArgumentDescription.of("The name of the player to unignore."))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandUnignoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(ArgumentDescription.of("The UUID of the player to unignore."))
.withDescription(RichDescription.of(messageService.commandUnignoreArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.ignore.unignore")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Stops hiding messages from the specified player."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandUnignoreDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -19,10 +19,10 @@
*/
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.UUID;
@@ -32,7 +32,6 @@ import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -43,21 +42,19 @@ public class UnmuteCommand {
public UnmuteCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat,
final CarbonPlayerArgument carbonPlayerArgument
final CarbonChat carbonChat
) {
final var command = commandManager.commandBuilder("unmute",
ArgumentDescription.of("The name of the player to unmute."))
.argument(carbonPlayerArgument.newInstance(false, "player",
CarbonPlayerArgument.NO_SENDER.and((sender, player) -> player.muted())))
final var command = commandManager.commandBuilder("unmute")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
RichDescription.of(messageService.commandUnmuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
.withDescription(ArgumentDescription.of("The UUID of the player to unmute."))
.withDescription(RichDescription.of(messageService.commandUnmuteArgumentUUID().component()))
.withArgument(UUIDArgument.optional("uuid"))
)
.permission("carbon.mute.unmute")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, Component.text("Unmutes players, allowing them to use chat and whisper other players."))
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandUnmuteDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer target;
@@ -21,6 +21,8 @@ package net.draycia.carbon.common.command.commands;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer;
@@ -38,14 +40,16 @@ public class WhisperCommand {
public WhisperCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonPlayerArgument carbonPlayerArgument,
final CarbonServer carbonServer
) {
final var command = commandManager.commandBuilder("whisper", "w", "message", "msg")
.argument(carbonPlayerArgument.newInstance(true, "recipient", CarbonPlayerArgument.NO_SENDER))
.argument(StringArgument.greedy("message"))
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asRequired(),
RichDescription.of(messageService.commandWhisperArgumentPlayer().component()))
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandWhisperArgumentMessage().component()))
.permission("carbon.whisper.message")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, messageService.commandWhisperDescription().component())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
@@ -55,7 +59,7 @@ public class WhisperCommand {
}
final String message = handler.get("message");
final CarbonPlayer recipient = handler.get("recipient");
final CarbonPlayer recipient = handler.get("player");
if (sender.equals(recipient)) {
messageService.whisperSelfError(sender, CarbonPlayer.renderName(sender));
@@ -67,7 +71,7 @@ public class WhisperCommand {
&& !sender.hasPermission("carbon.whisper.vanished"))
) {
final var rawNameInput = CloudUtils.rawInputByMatchingName(handler.getRawInput(), recipient);
final var exception = new CarbonPlayerArgument.PlayerParseException(rawNameInput);
final var exception = new CarbonPlayerArgument.CarbonPlayerParseException(rawNameInput, handler, messageService);
messageService.errorCommandArgumentParsing(sender, CloudUtils.message(exception));
return;
@@ -230,10 +230,115 @@ public interface CarbonMessageService {
@Message("error.command.argument_parsing")
void errorCommandArgumentParsing(final Audience audience, @Placeholder("throwable_message") final Component throwableMessage);
@Message("error.command.invalid_player")
RenderedMessage errorCommandInvalidPlayer(final Audience audience, final String input);
@Message("error.command.invalid_sender")
void errorCommandInvalidSender(final Audience audience, final String sender_type);
@Message("error.command.invalid_syntax")
void errorCommandInvalidSyntax(final Audience audience, final Component syntax);
/*
* =============================================================
* =================== Command Documentation ===================
* =============================================================
*/
@Message("command.clearchat.description")
RenderedMessage commandClearChatDescription();
@Message("command.continue.argument.message")
RenderedMessage commandContinueArgumentMessage();
@Message("command.continue.description")
RenderedMessage commandContinueDescription();
@Message("command.debug.argument.player")
RenderedMessage commandDebugArgumentPlayer();
@Message("command.debug.description")
RenderedMessage commandDebugDescription();
@Message("command.help.argument.query")
RenderedMessage commandHelpArgumentQuery();
@Message("command.help.description")
RenderedMessage commandHelpDescription();
@Message("command.ignore.argument.player")
RenderedMessage commandIgnoreArgumentPlayer();
@Message("command.ignore.argument.uuid")
RenderedMessage commandIgnoreArgumentUUID();
@Message("command.ignore.description")
RenderedMessage commandIgnoreDescription();
@Message("command.mute.argument.player")
RenderedMessage commandMuteArgumentPlayer();
@Message("command.mute.argument.uuid")
RenderedMessage commandMuteArgumentUUID();
@Message("command.mute.description")
RenderedMessage commandMuteDescription();
@Message("command.muteinfo.argument.player")
RenderedMessage commandMuteInfoArgumentPlayer();
@Message("command.muteinfo.argument.uuid")
RenderedMessage commandMuteInfoArgumentUUID();
@Message("command.muteinfo.description")
RenderedMessage commandMuteInfoDescription();
@Message("command.nickname.argument.player")
RenderedMessage commandNicknameArgumentPlayer();
@Message("command.nickname.argument.nickname")
RenderedMessage commandNicknameArgumentNickname();
@Message("command.nickname.argument.reset")
RenderedMessage commandNicknameArgumentReset();
@Message("command.nickname.description")
RenderedMessage commandNicknameDescription();
@Message("command.reload.description")
RenderedMessage commandReloadDescription();
@Message("command.reply.argument.message")
RenderedMessage commandReplyArgumentMessage();
@Message("command.reply.description")
RenderedMessage commandReplyDescription();
@Message("command.unignore.argument.player")
RenderedMessage commandUnignoreArgumentPlayer();
@Message("command.unignore.argument.uuid")
RenderedMessage commandUnignoreArgumentUUID();
@Message("command.unignore.description")
RenderedMessage commandUnignoreDescription();
@Message("command.unmute.argument.player")
RenderedMessage commandUnmuteArgumentPlayer();
@Message("command.unmute.argument.uuid")
RenderedMessage commandUnmuteArgumentUUID();
@Message("command.unmute.description")
RenderedMessage commandUnmuteDescription();
@Message("command.whisper.argument.player")
RenderedMessage commandWhisperArgumentPlayer();
@Message("command.whisper.argument.message")
RenderedMessage commandWhisperArgumentMessage();
@Message("command.whisper.description")
RenderedMessage commandWhisperDescription();
}
@@ -1,36 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2021 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.messages;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marker for a message recipient for detection with {@link ReceiverResolver}.
*/
@Documented
@Target({ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Recipient {
}
@@ -1,22 +1,55 @@
channel.change=<green>You are now messaging </green><channel>
channel.format.basic=<display_name>\: <message>
command.help.arguments=Arguments
command.help.available_commands=Available Commands
command.help.click_for_next_page=Click for next page
command.help.click_for_previous_page=Click for previous page
command.help.click_to_show_help=Click to show help for this command
command.help.command=Command
command.help.description=Description
command.help.help=Help
command.help.no_description=No description
command.help.no_results_for_query=No results for query
command.help.optional=Optional
command.help.page_out_of_range=Error: Page <page> is not in range. Must be in range [1, <max_pages>]
command.help.showing_results_for_query=Showing search results for query
command.clearchat.description=Clears the chat window for all players.
command.continue.argument.message=The message to send.
command.continue.description=Sends a message to the last person you messaged.
command.debug.argument.player=The player to check the groups of.
command.debug.description=Shows the permission groups of players.
command.help.argument.query=The search query.
command.help.description=Carbon command list.
command.help.misc.arguments=Arguments
command.help.misc.available_commands=Available Commands
command.help.misc.click_for_next_page=Click for next page
command.help.misc.click_for_previous_page=Click for previous page
command.help.misc.click_to_show_help=Click to show help for this command
command.help.misc.command=Command
command.help.misc.description=Description
command.help.misc.help=Help
command.help.misc.no_description=No description
command.help.misc.no_results_for_query=No results for query
command.help.misc.optional=Optional
command.help.misc.page_out_of_range=Error: Page <page> is not in range. Must be in range [1, <max_pages>]
command.help.misc.showing_results_for_query=Showing search results for query
command.ignore.argument.player=The name of the player to ignore.
command.ignore.argument.uuid=The UUID of the player to ignore.
command.ignore.description=Hides all incoming messages from ignored players.
command.mute.argument.player=The name of the player to mute.
command.mute.argument.uuid=The UUID of the player to mute.
command.mute.description=Mutes players, preventing them from using chat or whispering other players.
command.muteinfo.argument.player=The name of the player.
command.muteinfo.argument.uuid=The UUID of the player.
command.muteinfo.description=Shows if players are muted or not.
command.nickname.argument.nickname=The nickname to set.
command.nickname.argument.player=The name of the target player. Without this flag, the sender is the target.
command.nickname.argument.reset=Removes any set nickname from the target.
command.nickname.description=Sets and shows player nicknames.
command.reload.description=Reloads carbon's config, channel settings, and translations. Will not load or unload any channels.
command.reply.argument.message=The message to reply with.
command.reply.description=Sends a message to the last player that messaged you.
command.unignore.argument.player=The name of the player to unignore.
command.unignore.argument.uuid=The UUID of the player to unignore.
command.unignore.description=Stops hiding messages from the specified player.
command.unmute.argument.player=The name of the player to unmute.
command.unmute.argument.uuid=The UUID of the player to unmute.
command.unmute.description=Unmutes players, allowing them to use chat and whisper other players.
command.whisper.argument.message=The message to send.
command.whisper.argument.player=The name of the player to message.
command.whisper.description=Sends a private message to the specified player.
config.reload.failed=<red>Config failed to reload
config.reload.success=<green>Config reloaded successfully
error.command.argument_parsing=<red>Invalid command argument: <gray><throwable_message>
error.command.command_execution=<hover:show_text:"<throwable_message>\n<stacktrace>\n<gray><italic> Click to copy"><click:copy_to_clipboard:<stacktrace>><red>An internal error occurred while attempting to perform this command.
error.command.invalid_player=No player found for input '<input>'
error.command.invalid_sender=<red>Invalid command sender. You must be of type <gray><senderType>
error.command.invalid_syntax=<red>Invalid command syntax. Correct command syntax is: <white>/</white><gray><syntax></gray>
error.command.no_permission=<red>I'm sorry, but you do not have permission to perform this command.\nPlease contact the server administrators if you believe that this is in error.
@@ -39,8 +72,8 @@ mute.unmute.alert.target=<green>You have been unmuted
mute.unmute.no_target=<red>No specified player to unmute.
nickname.reset.others=<green><username></green><gold>'s nickname was reset
nickname.reset=<gold>Your nickname was reset
nickname.set.others=<green>You set </green><target><green>'s nickname to </green><nickname>
nickname.see.self.error=<red>You cannot see your own nickname
nickname.set.others=<green>You set </green><target><green>'s nickname to </green><nickname>
nickname.set=<green>Your nickname has been set to </green><nickname>
nickname.show.others.unset=<target><red> does not have a nickname set
nickname.show.others=<target><green>'s nickname is </green><nickname>