Merge pull request #181 from Hexaoxide/fix/suggestions

This commit is contained in:
Josua Parks authored and GitHub committed 2021-12-25 19:45:26 -08:00
commit 6858da9b66
14 files changed
+62 -31

No files matched your search

@@ -165,14 +165,14 @@ public final class CarbonPlayerArgument extends CommandArgument<Commander, Carbo
commandContext
));
}
inputQueue.remove();
final var playerResult = CarbonChatProvider.carbonChat().server().player(input).join();
if (playerResult.player() == null) {
return ArgumentParseResult.failure(new CarbonPlayerParseException(input, commandContext, this.messageService));
}
inputQueue.remove();
return ArgumentParseResult.success(playerResult.player());
}
@@ -181,19 +181,7 @@ public final class CarbonPlayerArgument extends CommandArgument<Commander, Carbo
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 output;
throw new UnsupportedOperationException("Suggestions provider must be overridden.");
}
}
@@ -0,0 +1,12 @@
package net.draycia.carbon.common.command.argument;
import cloud.commandframework.context.CommandContext;
import java.util.List;
import java.util.function.BiFunction;
import net.draycia.carbon.common.command.Commander;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public interface PlayerSuggestions extends BiFunction<CommandContext<Commander>, String, List<String>> {
}
@@ -28,6 +28,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.JoinConfiguration;
@@ -38,10 +39,11 @@ public class DebugCommand {
@Inject
public DebugCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService
final CarbonMessageService messageService,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("carbondebug", "cdebug")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandDebugArgumentPlayer().component()))
.permission("carbon.debug")
.senderType(PlayerCommander.class)
@@ -20,6 +20,7 @@
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import cloud.commandframework.minecraft.extras.RichDescription;
@@ -31,6 +32,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -42,10 +44,11 @@ public class IgnoreCommand {
public IgnoreCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("ignore", "block")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandIgnoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
@@ -31,6 +31,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -42,10 +43,11 @@ public class MuteCommand {
public MuteCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("mute")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandMuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
@@ -31,6 +31,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -42,10 +43,11 @@ public class MuteInfoCommand {
public MuteInfoCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("muteinfo", "muted")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandMuteInfoArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
@@ -30,6 +30,7 @@ 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.command.argument.OptionValueParser;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -39,14 +40,15 @@ public class NicknameCommand {
@Inject
public NicknameCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService
final CarbonMessageService messageService,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("nickname", "nick")
// TODO: Allow UUID input for target player
.flag(commandManager.flagBuilder("player")
.withAliases("p")
.withDescription(RichDescription.of(messageService.commandNicknameArgumentPlayer().component()))
.withArgument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional())
.withArgument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional())
.withPermission(Permission.of("carbon.nickname.others"))
)
.flag(commandManager.flagBuilder("nickname")
@@ -31,6 +31,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -42,11 +43,12 @@ public class UnignoreCommand {
public UnignoreCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("unignore", "unblock")
// TODO: Filter, and only show muted players, but allow inputting any player name.
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandUnignoreArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
@@ -31,6 +31,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.command.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -42,10 +43,11 @@ public class UnmuteCommand {
public UnmuteCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonChat carbonChat
final CarbonChat carbonChat,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("unmute")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asOptional(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).asOptional(),
RichDescription.of(messageService.commandUnmuteArgumentPlayer().component()))
.flag(commandManager.flagBuilder("uuid")
.withAliases("u")
@@ -30,6 +30,7 @@ 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.argument.CarbonPlayerArgument;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.messages.CarbonMessageService;
import net.draycia.carbon.common.util.CloudUtils;
import net.kyori.adventure.text.Component;
@@ -40,10 +41,11 @@ public class WhisperCommand {
public WhisperCommand(
final CommandManager<Commander> commandManager,
final CarbonMessageService messageService,
final CarbonServer carbonServer
final CarbonServer carbonServer,
final PlayerSuggestions suggestionsParser
) {
final var command = commandManager.commandBuilder("whisper", "w", "message", "msg", "m", "tell")
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).asRequired(),
.argument(CarbonPlayerArgument.newBuilder("player").withMessageService(messageService).withSuggestionsProvider(suggestionsParser).withSuggestionsProvider(suggestionsParser).asRequired(),
RichDescription.of(messageService.commandWhisperArgumentPlayer().component()))
.argument(StringArgument.greedy("message"),
RichDescription.of(messageService.commandWhisperArgumentMessage().component()))