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

@@ -20,7 +20,9 @@
package net.draycia.carbon.bukkit;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.parser.ArgumentParser;
import cloud.commandframework.brigadier.CloudBrigadierManager;
import cloud.commandframework.bukkit.parsers.PlayerArgument;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.paper.PaperCommandManager;
import com.google.inject.AbstractModule;
@@ -34,6 +36,7 @@ import net.draycia.carbon.bukkit.command.BukkitPlayerCommander;
import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.ForCarbon;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.util.CloudUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -102,6 +105,7 @@ public final class CarbonChatBukkitModule extends AbstractModule {
this.bind(Logger.class).toInstance(this.logger);
this.bind(Path.class).annotatedWith(ForCarbon.class).toInstance(this.dataDirectory);
this.bind(CarbonServer.class).to(CarbonServerBukkit.class);
this.bind(PlayerSuggestions.class).toInstance(new PlayerArgument.PlayerParser<Commander>()::suggestions);
}
}
@@ -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()))
@@ -22,6 +22,7 @@ package net.draycia.carbon.fabric;
import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.fabric.FabricServerCommandManager;
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
@@ -31,6 +32,7 @@ import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.ForCarbon;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.fabric.command.FabricCommander;
import net.draycia.carbon.fabric.command.FabricPlayerCommander;
@@ -86,6 +88,7 @@ public final class CarbonChatFabricModule extends AbstractModule {
this.bind(Logger.class).toInstance(this.logger);
this.bind(Path.class).annotatedWith(ForCarbon.class).toInstance(this.dataDirectory);
this.bind(CarbonServer.class).to(CarbonServerFabric.class);
this.bind(PlayerSuggestions.class).toInstance(FabricArgumentParsers.<Commander>singlePlayerSelector()::suggestions);
}
}
@@ -22,6 +22,8 @@ package net.draycia.carbon.sponge;
import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.sponge.SpongeCommandManager;
import cloud.commandframework.sponge.argument.SingleEntitySelectorArgument;
import cloud.commandframework.sponge.argument.SinglePlayerSelectorArgument;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
@@ -31,6 +33,7 @@ import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.ForCarbon;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.sponge.command.SpongeCommander;
import net.draycia.carbon.sponge.command.SpongePlayerCommander;
@@ -86,6 +89,7 @@ public final class CarbonChatSpongeModule extends AbstractModule {
this.bind(Path.class).annotatedWith(ForCarbon.class).toInstance(this.configDir);
this.bind(CarbonChat.class).toInstance(this.carbonChat);
this.bind(CarbonServer.class).to(CarbonServerSponge.class);
this.bind(PlayerSuggestions.class).toInstance(new SinglePlayerSelectorArgument.Parser<Commander>()::suggestions);
}
}
@@ -22,6 +22,7 @@ package net.draycia.carbon.velocity;
import cloud.commandframework.CommandManager;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.velocity.VelocityCommandManager;
import cloud.commandframework.velocity.arguments.PlayerArgument;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
@@ -34,6 +35,7 @@ import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.ForCarbon;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
import net.draycia.carbon.velocity.command.VelocityCommander;
import net.draycia.carbon.velocity.command.VelocityPlayerCommander;
import org.apache.logging.log4j.Logger;
@@ -94,6 +96,7 @@ public final class CarbonChatVelocityModule extends AbstractModule {
this.bind(Logger.class).toInstance(this.logger);
this.bind(Path.class).annotatedWith(ForCarbon.class).toInstance(this.dataDirectory);
this.bind(CarbonServer.class).to(CarbonServerVelocity.class);
this.bind(PlayerSuggestions.class).toInstance(new PlayerArgument.PlayerParser<Commander>()::suggestions);
}
}