mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
feat: cloud v2 (#424)
* feat: cloud v2 * updates * ArgumentFactory -> ParserFactory * Use parsing context instead of context hack for player parser input * fix: Allow console to clearchat * revert behavior change to player suggestions * Fixup command/argument description issues * remove unused method * paper: remove redundant command manager config * fix cloud relocation * remove redundant method call * Update cloud * thenCompose -> thenApply in CarbonPlayerParser * bump luckperms * adjust exception handling --------- Co-authored-by: Alexander Söderberg <[email protected]>
This commit is contained in:
1 parent
1110b48f90
commit
048321d17c
40 files changed
+518
-592
No files matched your search
@@ -40,9 +40,9 @@ import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
|
||||
import net.draycia.carbon.common.command.commands.ClearChatCommand;
|
||||
import net.draycia.carbon.common.command.commands.ContinueCommand;
|
||||
@@ -196,7 +196,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
this.install(new FactoryModuleBuilder().build(ArgumentFactory.class));
|
||||
this.install(new FactoryModuleBuilder().build(ParserFactory.class));
|
||||
this.install(factoryModule(PacketFactory.class));
|
||||
this.bind(ServerId.KEY).toInstance(UUID.randomUUID());
|
||||
this.bind(ChannelRegistry.class).to(CarbonChannelRegistry.class);
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -70,11 +67,15 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
||||
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class CarbonChannelRegistry extends ChatListenerInternal implements ChannelRegistry {
|
||||
@@ -354,7 +355,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
|
||||
Command.Builder<Commander> builder = commandManager.commandBuilder(channel.commandName(),
|
||||
channel.commandAliases(), commandManager.createDefaultCommandMeta())
|
||||
.argument(StringArgument.<Commander>builder("message").greedy().asOptional().build());
|
||||
.optional("message", greedyStringParser());
|
||||
|
||||
if (channel.permission() != null) {
|
||||
builder = builder.permission(channel.permission());
|
||||
@@ -371,7 +372,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
|
||||
final Command<Commander> command = builder.senderType(Commander.class)
|
||||
.handler(handler -> {
|
||||
final Commander commander = handler.getSender();
|
||||
final Commander commander = handler.sender();
|
||||
final @Nullable ChatChannel chatChannel = this.channel(channelKey);
|
||||
|
||||
if (!(commander instanceof PlayerCommander playerCommander)) {
|
||||
|
||||
+3
-8
@@ -19,21 +19,18 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command;
|
||||
|
||||
import cloud.commandframework.CommandTree;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.execution.ExecutionCoordinator;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public record ExecutionCoordinatorHolder(
|
||||
Function<CommandTree<Commander>, CommandExecutionCoordinator<Commander>> executionCoordinator,
|
||||
ExecutionCoordinator<Commander> executionCoordinator,
|
||||
ExecutorService executorService
|
||||
) {
|
||||
|
||||
@@ -44,9 +41,7 @@ public record ExecutionCoordinatorHolder(
|
||||
public static ExecutionCoordinatorHolder create(final Logger logger) {
|
||||
final ExecutorService executorService = Executors.newFixedThreadPool(4, ConcurrentUtil.carbonThreadFactory(logger, "Commands"));
|
||||
return new ExecutionCoordinatorHolder(
|
||||
AsynchronousCommandExecutionCoordinator.<Commander>builder()
|
||||
.withExecutor(executorService)
|
||||
.build(),
|
||||
ExecutionCoordinator.coordinatorFor(executorService),
|
||||
executorService
|
||||
);
|
||||
}
|
||||
|
||||
+3
-3
@@ -19,13 +19,13 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command;
|
||||
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerParser;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface ArgumentFactory {
|
||||
public interface ParserFactory {
|
||||
|
||||
CarbonPlayerArgument.Builder carbonPlayer(String name);
|
||||
CarbonPlayerParser carbonPlayer();
|
||||
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2024 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.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.context.CommandContext;
|
||||
import cloud.commandframework.keys.CloudKey;
|
||||
import cloud.commandframework.keys.SimpleCloudKey;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiFunction;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.exception.ComponentException;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonPlayerArgument extends CommandArgument<Commander, CarbonPlayer> {
|
||||
|
||||
private CarbonPlayerArgument(
|
||||
final boolean required,
|
||||
final String name,
|
||||
final String defaultValue,
|
||||
final @Nullable BiFunction<CommandContext<Commander>, String,
|
||||
List<String>> suggestionsProvider,
|
||||
final ArgumentDescription defaultDescription,
|
||||
final Parser parser
|
||||
) {
|
||||
super(required, name, parser, defaultValue, CarbonPlayer.class, suggestionsProvider, defaultDescription);
|
||||
}
|
||||
|
||||
public static final class Builder extends CommandArgument.TypedBuilder<Commander, CarbonPlayer, Builder> {
|
||||
|
||||
private final Parser parser;
|
||||
|
||||
@AssistedInject
|
||||
private Builder(final @Assisted String name, final Parser parser) {
|
||||
super(CarbonPlayer.class, name);
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarbonPlayerArgument build() {
|
||||
return new CarbonPlayerArgument(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider(),
|
||||
this.getDefaultDescription(),
|
||||
this.parser
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class Parser implements ArgumentParser<Commander, CarbonPlayer> {
|
||||
|
||||
// This hack only works properly when there is 0 or 1 CarbonPlayerArguments in a chain, since we don't use the arg name
|
||||
public static CloudKey<String> INPUT_STRING = SimpleCloudKey.of(Parser.class.getSimpleName() + "-input", TypeToken.get(String.class));
|
||||
|
||||
private final PlayerSuggestions suggestions;
|
||||
private final UserManager<?> userManager;
|
||||
private final ProfileResolver profileResolver;
|
||||
private final CarbonMessages messages;
|
||||
|
||||
@Inject
|
||||
private Parser(
|
||||
final PlayerSuggestions suggestions,
|
||||
final UserManager<?> userManager,
|
||||
final ProfileResolver profileResolver,
|
||||
final CarbonMessages messages
|
||||
) {
|
||||
this.suggestions = suggestions;
|
||||
this.userManager = userManager;
|
||||
this.profileResolver = profileResolver;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentParseResult<CarbonPlayer> parse(
|
||||
final CommandContext<Commander> commandContext,
|
||||
final Queue<String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
|
||||
final @Nullable CarbonPlayer join = this.profileResolver.resolveUUID(input, commandContext.isSuggestions()).thenCompose(uuid -> {
|
||||
if (uuid == null) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return this.userManager.user(uuid);
|
||||
}).join();
|
||||
|
||||
if (join == null) {
|
||||
return ArgumentParseResult.failure(new ParseException(input, this.messages));
|
||||
}
|
||||
|
||||
commandContext.store(INPUT_STRING, input);
|
||||
inputQueue.remove();
|
||||
return ArgumentParseResult.success(join);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggestions(
|
||||
final CommandContext<Commander> commandContext,
|
||||
final String input
|
||||
) {
|
||||
return this.suggestions.apply(commandContext, input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class ParseException extends ComponentException {
|
||||
|
||||
private static final long serialVersionUID = -8331761537951077684L;
|
||||
private final String input;
|
||||
|
||||
public ParseException(final String input, final CarbonMessages messages) {
|
||||
super(messages.errorCommandInvalidPlayer(input));
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public String input() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2024 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.command.argument;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.exception.ComponentException;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonPlayerParser implements ArgumentParser.FutureArgumentParser<Commander, CarbonPlayer>, ParserDescriptor<Commander, CarbonPlayer> {
|
||||
|
||||
private final PlayerSuggestions suggestions;
|
||||
private final UserManager<?> userManager;
|
||||
private final ProfileResolver profileResolver;
|
||||
private final CarbonMessages messages;
|
||||
|
||||
@Inject
|
||||
private CarbonPlayerParser(
|
||||
final PlayerSuggestions suggestions,
|
||||
final UserManager<?> userManager,
|
||||
final ProfileResolver profileResolver,
|
||||
final CarbonMessages messages
|
||||
) {
|
||||
this.suggestions = suggestions;
|
||||
this.userManager = userManager;
|
||||
this.profileResolver = profileResolver;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ArgumentParseResult<CarbonPlayer>> parseFuture(
|
||||
final CommandContext<Commander> commandContext,
|
||||
final CommandInput commandInput
|
||||
) {
|
||||
final String input = commandInput.readString();
|
||||
return this.profileResolver.resolveUUID(input, commandContext.isSuggestions()).thenCompose(uuid -> {
|
||||
if (uuid == null) {
|
||||
return ArgumentParseResult.failureFuture(new ParseException(input, this.messages));
|
||||
}
|
||||
return this.userManager.user(uuid).thenApply(ArgumentParseResult::success);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull SuggestionProvider<Commander> suggestionProvider() {
|
||||
return this.suggestions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull TypeToken<CarbonPlayer> valueType() {
|
||||
return TypeToken.get(CarbonPlayer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParser<Commander, CarbonPlayer> parser() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static final class ParseException extends ComponentException {
|
||||
|
||||
private static final long serialVersionUID = -8331761537951077684L;
|
||||
private final String input;
|
||||
|
||||
public ParseException(final String input, final CarbonMessages messages) {
|
||||
super(messages.errorCommandInvalidPlayer(input));
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
public String input() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -19,13 +19,11 @@
|
||||
*/
|
||||
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;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface PlayerSuggestions extends BiFunction<CommandContext<Commander>, String, List<String>> {
|
||||
public interface PlayerSuggestions extends SuggestionProvider<Commander> {
|
||||
}
|
||||
+5
-5
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -33,6 +31,9 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ClearChatCommand extends CarbonCommand {
|
||||
@@ -69,8 +70,7 @@ public final class ClearChatCommand extends CarbonCommand {
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.permission("carbon.clearchat.clear")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandClearChatDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandClearChatDescription()))
|
||||
.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?
|
||||
@@ -85,7 +85,7 @@ public final class ClearChatCommand extends CarbonCommand {
|
||||
final Component senderName;
|
||||
final String username;
|
||||
|
||||
if (handler.getSender() instanceof PlayerCommander player) {
|
||||
if (handler.sender() instanceof PlayerCommander player) {
|
||||
senderName = player.carbonPlayer().displayName();
|
||||
username = player.carbonPlayer().username();
|
||||
} else {
|
||||
|
||||
+7
-8
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
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 java.util.UUID;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
@@ -37,6 +33,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ContinueCommand extends CarbonCommand {
|
||||
@@ -72,13 +72,12 @@ public final class ContinueCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.greedy("message"),
|
||||
RichDescription.of(this.messages.commandContinueArgumentMessage()))
|
||||
.required("message", greedyStringParser(), richDescription(this.messages.commandContinueArgumentMessage()))
|
||||
.permission("carbon.whisper.continue")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.commandContinueDescription())
|
||||
.commandDescription(richDescription(this.messages.commandContinueDescription()))
|
||||
.handler(ctx -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = ctx.sender().carbonPlayer();
|
||||
|
||||
if (sender.muted()) {
|
||||
this.messages.muteCannotSpeak(sender);
|
||||
|
||||
@@ -19,16 +19,13 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
@@ -37,23 +34,26 @@ import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class DebugCommand extends CarbonCommand {
|
||||
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public DebugCommand(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,13 +69,13 @@ public final class DebugCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandDebugArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(),
|
||||
richDescription(this.carbonMessages.commandDebugArgumentPlayer()))
|
||||
.permission("carbon.debug")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandDebugDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandDebugDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
@@ -19,15 +19,9 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandHelpHandler;
|
||||
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.MinecraftHelp;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
@@ -35,16 +29,26 @@ import net.draycia.carbon.common.messages.CarbonMessageSource;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.help.result.CommandEntry;
|
||||
import org.incendo.cloud.minecraft.extras.AudienceProvider;
|
||||
import org.incendo.cloud.minecraft.extras.MinecraftHelp;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
import static net.kyori.adventure.text.format.TextColor.color;
|
||||
import static org.incendo.cloud.minecraft.extras.MinecraftHelp.helpColors;
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class HelpCommand extends CarbonCommand {
|
||||
@@ -77,12 +81,10 @@ public final class HelpCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.literal("help",
|
||||
RichDescription.of(this.carbonMessages.commandHelpDescription()))
|
||||
.argument(StringArgument.<Commander>builder("query")
|
||||
.greedy().withSuggestionsProvider(this::suggestQueries).asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandHelpArgumentQuery()))
|
||||
.literal("help")
|
||||
.optional("query", greedyStringParser(), richDescription(this.carbonMessages.commandHelpArgumentQuery()), this::suggestQueries)
|
||||
.permission("carbon.help")
|
||||
.commandDescription(richDescription(this.carbonMessages.commandHelpDescription()))
|
||||
.handler(this::execute)
|
||||
.build();
|
||||
|
||||
@@ -90,50 +92,41 @@ public final class HelpCommand extends CarbonCommand {
|
||||
}
|
||||
|
||||
private void execute(final CommandContext<Commander> ctx) {
|
||||
this.minecraftHelp.queryCommands(ctx.getOrDefault("query", ""), ctx.getSender());
|
||||
this.minecraftHelp.queryCommands(ctx.getOrDefault("query", ""), ctx.sender());
|
||||
}
|
||||
|
||||
private List<String> suggestQueries(final CommandContext<Commander> ctx, final String input) {
|
||||
final var topic = this.commandManager.createCommandHelpHandler().queryRootIndex(ctx.getSender());
|
||||
return topic.getEntries().stream().map(CommandHelpHandler.VerboseHelpEntry::getSyntaxString).toList();
|
||||
private CompletableFuture<Iterable<Suggestion>> suggestQueries(final CommandContext<Commander> ctx, final CommandInput input) {
|
||||
final var result = this.commandManager.createHelpHandler().queryRootIndex(ctx.sender());
|
||||
return CompletableFuture.completedFuture(result.entries().stream().map(CommandEntry::syntax).map(Suggestion::suggestion).toList());
|
||||
}
|
||||
|
||||
private static MinecraftHelp<Commander> createHelp(
|
||||
final CommandManager<Commander> manager,
|
||||
final CarbonMessageSource messageSource
|
||||
) {
|
||||
final MinecraftHelp<Commander> help = new MinecraftHelp<>(
|
||||
"/carbon help",
|
||||
AudienceProvider.nativeAudience(),
|
||||
manager
|
||||
);
|
||||
|
||||
help.setHelpColors(
|
||||
MinecraftHelp.HelpColors.of(
|
||||
return MinecraftHelp.<Commander>builder()
|
||||
.commandManager(manager)
|
||||
.audienceProvider(AudienceProvider.nativeAudience())
|
||||
.commandPrefix("/carbon help")
|
||||
.colors(helpColors(
|
||||
color(0xE099FF),
|
||||
WHITE,
|
||||
color(0xDD1BC4),
|
||||
GRAY,
|
||||
DARK_GRAY
|
||||
)
|
||||
);
|
||||
))
|
||||
.messageProvider((sender, key, args) -> {
|
||||
final String messageKey = "command.help.misc." + key;
|
||||
final TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
|
||||
help.messageProvider((sender, key, args) -> {
|
||||
final String messageKey = "command.help.misc." + key;
|
||||
final TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
for (final Map.Entry<String, String> entry : args.entrySet()) {
|
||||
@Subst("key") final String k = entry.getKey();
|
||||
tagResolver.resolver(Placeholder.parsed(k, entry.getValue()));
|
||||
}
|
||||
|
||||
// Total hack but works for now
|
||||
if (args.length == 2) {
|
||||
tagResolver
|
||||
.tag("page", Tag.selfClosingInserting(text(args[0])))
|
||||
.tag("max_pages", Tag.selfClosingInserting(text(args[1]))
|
||||
);
|
||||
}
|
||||
|
||||
return MiniMessage.miniMessage().deserialize(messageSource.messageOf(sender, messageKey), tagResolver.build());
|
||||
});
|
||||
|
||||
return help;
|
||||
return MiniMessage.miniMessage().deserialize(messageSource.messageOf(sender, messageKey), tagResolver.build());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
+13
-14
@@ -19,22 +19,22 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class IgnoreCommand extends CarbonCommand {
|
||||
@@ -42,19 +42,19 @@ public final class IgnoreCommand extends CarbonCommand {
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public IgnoreCommand(
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,18 +70,17 @@ public final class IgnoreCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandIgnoreArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandIgnoreArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.carbonMessages.commandIgnoreArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.carbonMessages.commandIgnoreArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.ignore")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandIgnoreDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandIgnoreDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+10
-8
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.function.Supplier;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
@@ -37,6 +33,12 @@ import net.draycia.carbon.common.util.PaginationHelper;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.component.DefaultValue;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.IntegerParser.integerParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class IgnoreListCommand extends CarbonCommand {
|
||||
@@ -74,16 +76,16 @@ public final class IgnoreListCommand extends CarbonCommand {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.permission("carbon.ignore")
|
||||
.senderType(PlayerCommander.class)
|
||||
.argument(IntegerArgument.<Commander>builder("page").withMin(1).asOptionalWithDefault(1))
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.commandIgnoreListDescription())
|
||||
.optional("page", integerParser(1), DefaultValue.constant(1))
|
||||
.commandDescription(richDescription(this.messages.commandIgnoreListDescription()))
|
||||
.handler(this::execute)
|
||||
.build();
|
||||
|
||||
this.commandManager.command(command);
|
||||
}
|
||||
|
||||
private void execute(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer sender = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void execute(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer sender = ctx.sender().carbonPlayer();
|
||||
final var elements = sender.ignoring().stream()
|
||||
.sorted() // this way page numbers make sense
|
||||
.map(id -> (Supplier<CarbonPlayer>) () -> this.users.user(id).join())
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
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.channels.ChannelPermissionResult;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -37,6 +33,12 @@ import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class JoinCommand extends CarbonCommand {
|
||||
@@ -69,15 +71,17 @@ public final class JoinCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
||||
return sender.leftChannels().stream().map(Key::value).toList();
|
||||
}), RichDescription.of(this.carbonMessages.commandJoinDescription()))
|
||||
.required("channel", greedyStringParser(), SuggestionProvider.blocking(
|
||||
(context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.sender()).carbonPlayer();
|
||||
return sender.leftChannels().stream().map(Key::value).map(Suggestion::suggestion).toList();
|
||||
}
|
||||
))
|
||||
.permission("carbon.join")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandJoinDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final @Nullable ChatChannel channel = this.channelRegistry.channelByValue(handler.get("channel"));
|
||||
if (channel == null) {
|
||||
this.carbonMessages.channelNotFound(sender);
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
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.channels.ChannelPermissionResult;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -37,6 +33,12 @@ import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
import org.incendo.cloud.suggestion.SuggestionProvider;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class LeaveCommand extends CarbonCommand {
|
||||
@@ -69,19 +71,20 @@ public final class LeaveCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
||||
.required("channel", greedyStringParser(), SuggestionProvider.blocking((context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.sender()).carbonPlayer();
|
||||
return this.channelRegistry.keys().stream()
|
||||
.map(this.channelRegistry::channel)
|
||||
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
|
||||
.map(x -> x.key().value())
|
||||
.map(Suggestion::suggestion)
|
||||
.toList();
|
||||
}), RichDescription.of(this.carbonMessages.commandLeaveDescription()))
|
||||
}))
|
||||
.permission("carbon.join")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandLeaveDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final @Nullable ChatChannel channel = this.channelRegistry.channelByValue(handler.get("channel"));
|
||||
if (channel == null) {
|
||||
this.carbonMessages.channelNotFound(sender);
|
||||
|
||||
@@ -19,23 +19,23 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class MuteCommand extends CarbonCommand {
|
||||
@@ -44,7 +44,7 @@ public final class MuteCommand extends CarbonCommand {
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public MuteCommand(
|
||||
@@ -52,13 +52,13 @@ public final class MuteCommand extends CarbonCommand {
|
||||
final CarbonServer server,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.server = server;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,18 +74,18 @@ public final class MuteCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandMuteArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(),
|
||||
richDescription(this.carbonMessages.commandMuteArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.carbonMessages.commandMuteArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.carbonMessages.commandMuteArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.mute")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandMuteDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandMuteDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+13
-14
@@ -19,22 +19,22 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class MuteInfoCommand extends CarbonCommand {
|
||||
@@ -42,19 +42,19 @@ public final class MuteInfoCommand extends CarbonCommand {
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public MuteInfoCommand(
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,18 +70,17 @@ public final class MuteInfoCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandMuteInfoArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandMuteInfoArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.carbonMessages.commandMuteInfoArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.carbonMessages.commandMuteInfoArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.mute.info")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandMuteInfoDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandMuteInfoDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+23
-23
@@ -19,16 +19,12 @@
|
||||
*/
|
||||
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.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.ConfigManager;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
@@ -40,25 +36,29 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class NicknameCommand extends CarbonCommand {
|
||||
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
private final ConfigManager config;
|
||||
|
||||
@Inject
|
||||
public NicknameCommand(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory,
|
||||
final ParserFactory parserFactory,
|
||||
final ConfigManager config
|
||||
) {
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -81,35 +81,35 @@ public final class NicknameCommand extends CarbonCommand {
|
||||
// TODO: Allow UUID input for target player
|
||||
final var selfRoot = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases());
|
||||
final var othersRoot = selfRoot.literal("player")
|
||||
.argument(this.argumentFactory.carbonPlayer("player"), RichDescription.of(this.carbonMessages.commandNicknameArgumentPlayer()));
|
||||
.required("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandNicknameArgumentPlayer()));
|
||||
|
||||
// Check nickname
|
||||
this.commandManager.command(selfRoot.permission("carbon.nickname")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameDescription())
|
||||
.handler(ctx -> this.checkOwnNickname(CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()))));
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameDescription()))
|
||||
.handler(ctx -> this.checkOwnNickname(CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.sender()))));
|
||||
this.commandManager.command(othersRoot.permission("carbon.nickname.others")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersDescription())
|
||||
.handler(ctx -> this.checkOthersNickname(ctx.getSender(), ctx.get("player"))));
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameOthersDescription()))
|
||||
.handler(ctx -> this.checkOthersNickname(ctx.sender(), ctx.get("player"))));
|
||||
|
||||
// Set nickname
|
||||
this.commandManager.command(selfRoot.permission("carbon.nickname.set")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameSetDescription())
|
||||
.argument(StringArgument.greedy("nickname"), RichDescription.of(this.carbonMessages.commandNicknameArgumentNickname()))
|
||||
.handler(ctx -> this.applyNickname(ctx.getSender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()), ctx.get("nickname"))));
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameSetDescription()))
|
||||
.required("nickname", greedyStringParser(), richDescription(this.carbonMessages.commandNicknameArgumentNickname()))
|
||||
.handler(ctx -> this.applyNickname(ctx.sender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.sender()), ctx.get("nickname"))));
|
||||
this.commandManager.command(othersRoot.permission("carbon.nickname.others.set")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersSetDescription())
|
||||
.argument(StringArgument.greedy("nickname"), RichDescription.of(this.carbonMessages.commandNicknameArgumentNickname()))
|
||||
.handler(ctx -> this.applyNickname(ctx.getSender(), ctx.get("player"), ctx.get("nickname"))));
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameOthersSetDescription()))
|
||||
.required("nickname", greedyStringParser(), richDescription(this.carbonMessages.commandNicknameArgumentNickname()))
|
||||
.handler(ctx -> this.applyNickname(ctx.sender(), ctx.get("player"), ctx.get("nickname"))));
|
||||
|
||||
// Reset/remove nickname
|
||||
this.commandManager.command(selfRoot.permission("carbon.nickname.set")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameResetDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameResetDescription()))
|
||||
.literal("reset")
|
||||
.handler(ctx -> this.resetNickname(ctx.getSender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.getSender()))));
|
||||
.handler(ctx -> this.resetNickname(ctx.sender(), CloudUtils.nonPlayerMustProvidePlayer(this.carbonMessages, ctx.sender()))));
|
||||
this.commandManager.command(othersRoot.permission("carbon.nickname.others.set")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandNicknameOthersResetDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandNicknameOthersResetDescription()))
|
||||
.literal("reset")
|
||||
.handler(ctx -> this.resetNickname(ctx.getSender(), ctx.get("player"))));
|
||||
.handler(ctx -> this.resetNickname(ctx.sender(), ctx.get("player"))));
|
||||
}
|
||||
|
||||
private void resetNickname(final Commander sender, final CarbonPlayer target) {
|
||||
|
||||
+34
-31
@@ -19,11 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Comparator;
|
||||
@@ -33,10 +28,10 @@ import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.Party;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.ConfigManager;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
@@ -52,12 +47,19 @@ 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;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.component.DefaultValue;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.IntegerParser.integerParser;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class PartyCommands extends CarbonCommand {
|
||||
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
private final UserManagerInternal<?> userManager;
|
||||
private final PartyInvites partyInvites;
|
||||
private final ConfigManager config;
|
||||
@@ -68,7 +70,7 @@ public final class PartyCommands extends CarbonCommand {
|
||||
@Inject
|
||||
public PartyCommands(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final ArgumentFactory argumentFactory,
|
||||
final ParserFactory parserFactory,
|
||||
final UserManagerInternal<?> userManager,
|
||||
final PartyInvites partyInvites,
|
||||
final ConfigManager config,
|
||||
@@ -77,7 +79,7 @@ public final class PartyCommands extends CarbonCommand {
|
||||
final NetworkUsers network
|
||||
) {
|
||||
this.commandManager = commandManager;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
this.userManager = userManager;
|
||||
this.partyInvites = partyInvites;
|
||||
this.config = config;
|
||||
@@ -95,36 +97,37 @@ public final class PartyCommands extends CarbonCommand {
|
||||
final var root = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.senderType(PlayerCommander.class)
|
||||
.permission("carbon.parties");
|
||||
final var info = root.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyDesc()).handler(this::info);
|
||||
final var info = root.commandDescription(richDescription(this.messages.partyDesc())).handler(this::info);
|
||||
|
||||
this.commandManager.command(info);
|
||||
this.commandManager.command(info.literal("page")
|
||||
.argument(IntegerArgument.<Commander>builder("page").withMin(1).asOptionalWithDefault(1)));
|
||||
.optional("page", integerParser(1), DefaultValue.constant(1)));
|
||||
this.commandManager.command(
|
||||
root.literal("create")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyCreateDesc())
|
||||
.argument(StringArgument.<Commander>builder("name").greedy().asOptional())
|
||||
.commandDescription(richDescription(this.messages.partyCreateDesc()))
|
||||
.optional("name", greedyStringParser())
|
||||
.handler(this::createParty)
|
||||
);
|
||||
this.commandManager.command(
|
||||
root.literal("invite")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyInviteDesc())
|
||||
.argument(this.argumentFactory.carbonPlayer("player"))
|
||||
.commandDescription(richDescription(this.messages.partyInviteDesc()))
|
||||
.required("player", this.parserFactory.carbonPlayer())
|
||||
.handler(this::invitePlayer)
|
||||
);
|
||||
this.commandManager.command(
|
||||
root.literal("accept")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyAcceptDesc())
|
||||
.argument(this.argumentFactory.carbonPlayer("sender").asOptional())
|
||||
.commandDescription(richDescription(this.messages.partyAcceptDesc()))
|
||||
.optional("sender", this.parserFactory.carbonPlayer())
|
||||
.handler(this::acceptInvite)
|
||||
);
|
||||
this.commandManager.command(
|
||||
root.literal("leave")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyLeaveDesc())
|
||||
.commandDescription(richDescription(this.messages.partyLeaveDesc()))
|
||||
.handler(this::leaveParty)
|
||||
);
|
||||
this.commandManager.command(
|
||||
root.literal("disband")
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.partyDisbandDesc())
|
||||
.commandDescription(richDescription(this.messages.partyDisbandDesc()))
|
||||
.handler(this::disbandParty)
|
||||
);
|
||||
}
|
||||
@@ -139,8 +142,8 @@ public final class PartyCommands extends CarbonCommand {
|
||||
return Key.key("carbon", "party");
|
||||
}
|
||||
|
||||
private void info(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void info(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final @Nullable Party party = player.party().join();
|
||||
if (party == null) {
|
||||
this.messages.notInParty(player);
|
||||
@@ -173,8 +176,8 @@ public final class PartyCommands extends CarbonCommand {
|
||||
pagination.render(elements, page, 6).forEach(player::sendMessage);
|
||||
}
|
||||
|
||||
private void createParty(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void createParty(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final @Nullable Party oldParty = player.party().join();
|
||||
if (oldParty != null) {
|
||||
this.messages.mustLeavePartyFirst(player);
|
||||
@@ -193,8 +196,8 @@ public final class PartyCommands extends CarbonCommand {
|
||||
this.messages.partyCreated(player, party.name());
|
||||
}
|
||||
|
||||
private void invitePlayer(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void invitePlayer(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final CarbonPlayer recipient = ctx.get("player");
|
||||
if (recipient.uuid().equals(player.uuid())) {
|
||||
this.messages.cannotInviteSelf(player);
|
||||
@@ -215,9 +218,9 @@ public final class PartyCommands extends CarbonCommand {
|
||||
this.messages.sentPartyInvite(player, recipient.displayName(), party.name());
|
||||
}
|
||||
|
||||
private void acceptInvite(final CommandContext<Commander> ctx) {
|
||||
private void acceptInvite(final CommandContext<PlayerCommander> ctx) {
|
||||
final @Nullable CarbonPlayer sender = ctx.getOrDefault("sender", null);
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final @Nullable Invite invite = this.findInvite(player, sender);
|
||||
if (invite == null) {
|
||||
return;
|
||||
@@ -232,8 +235,8 @@ public final class PartyCommands extends CarbonCommand {
|
||||
this.messages.joinedParty(player, invite.party().name());
|
||||
}
|
||||
|
||||
private void leaveParty(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void leaveParty(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final @Nullable Party old = player.party().join();
|
||||
if (old == null) {
|
||||
this.messages.mustBeInParty(player);
|
||||
@@ -247,8 +250,8 @@ public final class PartyCommands extends CarbonCommand {
|
||||
this.messages.leftParty(player, old.name());
|
||||
}
|
||||
|
||||
private void disbandParty(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer player = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
private void disbandParty(final CommandContext<PlayerCommander> ctx) {
|
||||
final CarbonPlayer player = ctx.sender().carbonPlayer();
|
||||
final @Nullable Party old = player.party().join();
|
||||
if (old == null) {
|
||||
this.messages.mustBeInParty(player);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -31,6 +29,9 @@ import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ReloadCommand extends CarbonCommand {
|
||||
@@ -66,11 +67,11 @@ public final class ReloadCommand extends CarbonCommand {
|
||||
.literal("reload")
|
||||
.permission("carbon.reload")
|
||||
.senderType(Commander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandReloadDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandReloadDescription()))
|
||||
.handler(handler -> {
|
||||
// TODO: Check if all listeners succeeded
|
||||
this.events.emit(new CarbonReloadEvent());
|
||||
this.carbonMessages.configReloaded(handler.getSender());
|
||||
this.carbonMessages.configReloaded(handler.sender());
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
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 java.util.UUID;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
@@ -37,6 +33,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ReplyCommand extends CarbonCommand {
|
||||
@@ -72,13 +72,12 @@ public final class ReplyCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.greedy("message"),
|
||||
RichDescription.of(this.messages.commandReplyArgumentMessage()))
|
||||
.required("message", greedyStringParser(), richDescription(this.messages.commandReplyArgumentMessage()))
|
||||
.permission("carbon.whisper.reply")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.commandReplyDescription())
|
||||
.commandDescription(richDescription(this.messages.commandReplyDescription()))
|
||||
.handler(ctx -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = ctx.sender().carbonPlayer();
|
||||
|
||||
if (sender.muted()) {
|
||||
this.messages.muteCannotSpeak(sender);
|
||||
|
||||
+9
-8
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -29,6 +27,9 @@ import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
|
||||
public class ToggleMessagesCommand extends CarbonCommand {
|
||||
|
||||
@@ -59,9 +60,9 @@ public class ToggleMessagesCommand extends CarbonCommand {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.permission("carbon.togglemsg")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandToggleMsgDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final boolean nowIgnoring = !sender.ignoringDirectMessages();
|
||||
sender.ignoringDirectMessages(nowIgnoring);
|
||||
|
||||
@@ -79,9 +80,9 @@ public class ToggleMessagesCommand extends CarbonCommand {
|
||||
.permission("carbon.togglemsg")
|
||||
.literal("on", "allow")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandToggleMsgDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
sender.ignoringDirectMessages(false);
|
||||
this.carbonMessages.whispersToggledOn(sender);
|
||||
})
|
||||
@@ -93,9 +94,9 @@ public class ToggleMessagesCommand extends CarbonCommand {
|
||||
.permission("carbon.togglemsg")
|
||||
.literal("off", "ignore")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandToggleMsgDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
sender.ignoringDirectMessages(true);
|
||||
this.carbonMessages.whispersToggledOff(sender);
|
||||
})
|
||||
|
||||
+14
-14
@@ -19,22 +19,22 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class UnignoreCommand extends CarbonCommand {
|
||||
@@ -42,19 +42,19 @@ public final class UnignoreCommand extends CarbonCommand {
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public UnignoreCommand(
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,18 +71,18 @@ public final class UnignoreCommand extends CarbonCommand {
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
// TODO: Filter, and only show muted players, but allow inputting any player name.
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandUnignoreArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(),
|
||||
richDescription(this.carbonMessages.commandUnignoreArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.carbonMessages.commandUnignoreArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.carbonMessages.commandUnignoreArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.ignore.unignore")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandUnignoreDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandUnignoreDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+14
-14
@@ -19,23 +19,23 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class UnmuteCommand extends CarbonCommand {
|
||||
@@ -44,7 +44,7 @@ public final class UnmuteCommand extends CarbonCommand {
|
||||
private final CarbonServer server;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
|
||||
@Inject
|
||||
public UnmuteCommand(
|
||||
@@ -52,13 +52,13 @@ public final class UnmuteCommand extends CarbonCommand {
|
||||
final CarbonServer server,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
final ParserFactory parserFactory
|
||||
) {
|
||||
this.users = userManager;
|
||||
this.server = server;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,18 +74,18 @@ public final class UnmuteCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.carbonMessages.commandUnmuteArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(),
|
||||
richDescription(this.carbonMessages.commandUnmuteArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.carbonMessages.commandUnmuteArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.carbonMessages.commandUnmuteArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.mute.unmute")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandUnmuteDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandUnmuteDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = handler.sender().carbonPlayer();
|
||||
final CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+14
-14
@@ -19,18 +19,14 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
|
||||
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 net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
@@ -39,6 +35,10 @@ import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class UpdateUsernameCommand extends CarbonCommand {
|
||||
@@ -46,7 +46,7 @@ public final class UpdateUsernameCommand extends CarbonCommand {
|
||||
private final UserManager<?> userManager;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages messageService;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
private final ProfileResolver profileResolver;
|
||||
|
||||
@Inject
|
||||
@@ -54,13 +54,13 @@ public final class UpdateUsernameCommand extends CarbonCommand {
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages messageService,
|
||||
final ArgumentFactory argumentFactory,
|
||||
final ParserFactory parserFactory,
|
||||
final ProfileResolver profileResolver
|
||||
) {
|
||||
this.userManager = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.messageService = messageService;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
this.profileResolver = profileResolver;
|
||||
}
|
||||
|
||||
@@ -77,18 +77,18 @@ public final class UpdateUsernameCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player").asOptional(),
|
||||
RichDescription.of(this.messageService.commandUpdateUsernameArgumentPlayer()))
|
||||
.optional("player", this.parserFactory.carbonPlayer(),
|
||||
richDescription(this.messageService.commandUpdateUsernameArgumentPlayer()))
|
||||
.flag(this.commandManager.flagBuilder("uuid")
|
||||
.withAliases("u")
|
||||
.withDescription(RichDescription.of(this.messageService.commandUpdateUsernameArgumentUUID()))
|
||||
.withArgument(UUIDArgument.optional("uuid"))
|
||||
.withDescription(richDescription(this.messageService.commandUpdateUsernameArgumentUUID()))
|
||||
.withComponent(uuidParser())
|
||||
)
|
||||
.permission("carbon.updateusername")
|
||||
.senderType(Commander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messageService.commandUpdateUsernameDescription())
|
||||
.commandDescription(richDescription(this.messageService.commandUpdateUsernameDescription()))
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.sender()).carbonPlayer();
|
||||
CarbonPlayer target;
|
||||
|
||||
if (handler.contains("player")) {
|
||||
|
||||
+15
-17
@@ -19,10 +19,6 @@
|
||||
*/
|
||||
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 com.google.inject.Provider;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
@@ -30,12 +26,12 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ParserFactory;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||
import net.draycia.carbon.common.command.argument.CarbonPlayerParser;
|
||||
import net.draycia.carbon.common.config.ConfigManager;
|
||||
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
@@ -52,25 +48,29 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
|
||||
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
|
||||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class WhisperCommand extends CarbonCommand {
|
||||
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ParserFactory parserFactory;
|
||||
private final WhisperHandler whisper;
|
||||
|
||||
@Inject
|
||||
public WhisperCommand(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory,
|
||||
final ParserFactory parserFactory,
|
||||
final WhisperHandler whisper
|
||||
) {
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
this.parserFactory = parserFactory;
|
||||
this.whisper = whisper;
|
||||
}
|
||||
|
||||
@@ -87,15 +87,13 @@ public final class WhisperCommand extends CarbonCommand {
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(this.argumentFactory.carbonPlayer("player"),
|
||||
RichDescription.of(this.carbonMessages.commandWhisperArgumentPlayer()))
|
||||
.argument(StringArgument.greedy("message"),
|
||||
RichDescription.of(this.carbonMessages.commandWhisperArgumentMessage()))
|
||||
.required("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandWhisperArgumentPlayer()))
|
||||
.required("message", greedyStringParser(), richDescription(this.carbonMessages.commandWhisperArgumentMessage()))
|
||||
.permission("carbon.whisper.message")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandWhisperDescription())
|
||||
.commandDescription(richDescription(this.carbonMessages.commandWhisperDescription()))
|
||||
.handler(ctx -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
final CarbonPlayer sender = ctx.sender().carbonPlayer();
|
||||
|
||||
if (sender.muted()) {
|
||||
this.carbonMessages.muteCannotSpeak(sender);
|
||||
@@ -105,7 +103,7 @@ public final class WhisperCommand extends CarbonCommand {
|
||||
final String message = ctx.get("message");
|
||||
final CarbonPlayer recipient = ctx.get("player");
|
||||
|
||||
this.whisper.whisper(sender, recipient, message, ctx.getOrDefault(CarbonPlayerArgument.Parser.INPUT_STRING, null));
|
||||
this.whisper.whisper(sender, recipient, message, ctx.parsingContext("player").consumedInput());
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -173,7 +171,7 @@ public final class WhisperCommand extends CarbonCommand {
|
||||
|
||||
final String recipientUsername = recipient.username();
|
||||
if (!this.network.online(recipient) || !sender.awareOf(recipient) && !sender.hasPermission("carbon.whisper.vanished")) {
|
||||
final var exception = new CarbonPlayerArgument.ParseException(
|
||||
final var exception = new CarbonPlayerParser.ParseException(
|
||||
recipientInputString == null ? recipientUsername : recipientInputString,
|
||||
this.messages
|
||||
);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.List;
|
||||
@@ -43,6 +42,9 @@ import net.draycia.carbon.common.util.Exceptions;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.context.CommandInput;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
|
||||
/**
|
||||
* Eventually consistent store of who is on each server in the network (besides self).
|
||||
@@ -97,15 +99,18 @@ public final class NetworkUsers implements PlayerSuggestions {
|
||||
|
||||
// PlayerSuggestions impl
|
||||
@Override
|
||||
public List<String> apply(final CommandContext<Commander> ctx, final String input) {
|
||||
final Commander commander = ctx.getSender();
|
||||
public CompletableFuture<Iterable<Suggestion>> suggestionsFuture(final CommandContext<Commander> ctx, final CommandInput input) {
|
||||
final Commander commander = ctx.sender();
|
||||
|
||||
final List<? extends CarbonPlayer> local = this.server.players();
|
||||
|
||||
if (!(commander instanceof PlayerCommander player)) {
|
||||
return Stream.concat(local.stream().map(CarbonPlayer::username), this.map.values().stream().flatMap(m -> m.values().stream()))
|
||||
.distinct()
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(
|
||||
Stream.concat(local.stream().map(CarbonPlayer::username), this.map.values().stream().flatMap(m -> m.values().stream()))
|
||||
.distinct()
|
||||
.map(Suggestion::suggestion)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
final CarbonPlayer carbonPlayer = player.carbonPlayer();
|
||||
|
||||
@@ -125,11 +130,14 @@ public final class NetworkUsers implements PlayerSuggestions {
|
||||
.map(future -> future.getNow(null))
|
||||
.filter(Objects::nonNull);
|
||||
|
||||
return Stream.concat(local.stream(), remote)
|
||||
.filter(carbonPlayer::awareOf)
|
||||
.map(CarbonPlayer::username)
|
||||
.distinct()
|
||||
.toList();
|
||||
return CompletableFuture.completedFuture(
|
||||
Stream.concat(local.stream(), remote)
|
||||
.filter(carbonPlayer::awareOf)
|
||||
.map(CarbonPlayer::username)
|
||||
.distinct()
|
||||
.map(Suggestion::suggestion)
|
||||
.toList()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean online(final CarbonPlayer player) {
|
||||
|
||||
@@ -19,19 +19,11 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.util;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.exceptions.ArgumentParseException;
|
||||
import cloud.commandframework.exceptions.CommandExecutionException;
|
||||
import cloud.commandframework.exceptions.InvalidCommandSenderException;
|
||||
import cloud.commandframework.exceptions.InvalidSyntaxException;
|
||||
import cloud.commandframework.exceptions.NoPermissionException;
|
||||
import cloud.commandframework.execution.FilteringCommandSuggestionProcessor;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -46,9 +38,19 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.util.ComponentMessageThrowable;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.incendo.cloud.CommandManager;
|
||||
import org.incendo.cloud.exception.ArgumentParseException;
|
||||
import org.incendo.cloud.exception.CommandExecutionException;
|
||||
import org.incendo.cloud.exception.InvalidCommandSenderException;
|
||||
import org.incendo.cloud.exception.InvalidSyntaxException;
|
||||
import org.incendo.cloud.exception.NoPermissionException;
|
||||
import org.incendo.cloud.util.TypeUtils;
|
||||
|
||||
import static org.incendo.cloud.exception.handling.ExceptionHandler.unwrappingHandler;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CloudUtils {
|
||||
@@ -88,75 +90,49 @@ public final class CloudUtils {
|
||||
return msg == null ? NULL : msg;
|
||||
}
|
||||
|
||||
public static String rawInputByMatchingName(
|
||||
final LinkedList<String> rawInput,
|
||||
final CarbonPlayer recipient
|
||||
) {
|
||||
return rawInput
|
||||
.stream()
|
||||
.filter(it -> it.equalsIgnoreCase(recipient.username()))
|
||||
.findFirst()
|
||||
.orElse(recipient.username());
|
||||
}
|
||||
|
||||
public static void decorateCommandManager(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages
|
||||
final CarbonMessages carbonMessages,
|
||||
final Logger logger
|
||||
) {
|
||||
commandManager.commandSuggestionProcessor(
|
||||
new FilteringCommandSuggestionProcessor<>(
|
||||
FilteringCommandSuggestionProcessor.Filter.<Commander>contains(true).andTrimBeforeLastSpace()
|
||||
)
|
||||
);
|
||||
|
||||
registerExceptionHandlers(commandManager, carbonMessages);
|
||||
registerExceptionHandlers(commandManager, carbonMessages, logger);
|
||||
}
|
||||
|
||||
public static void registerExceptionHandlers(
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages
|
||||
final CarbonMessages carbonMessages,
|
||||
final Logger logger
|
||||
) {
|
||||
commandManager.registerExceptionHandler(ArgumentParseException.class, (sender, exception) -> {
|
||||
final var throwableMessage = CloudUtils.message(exception.getCause());
|
||||
|
||||
carbonMessages.errorCommandArgumentParsing(sender, throwableMessage);
|
||||
});
|
||||
commandManager.registerExceptionHandler(InvalidCommandSenderException.class, (sender, exception) -> {
|
||||
final var senderType = exception.getRequiredSender().getSimpleName();
|
||||
|
||||
carbonMessages.errorCommandInvalidSender(sender, senderType);
|
||||
});
|
||||
commandManager.registerExceptionHandler(InvalidSyntaxException.class, (sender, exception) -> {
|
||||
final var syntax =
|
||||
Component.text(exception.getCorrectSyntax()).replaceText(
|
||||
commandManager.exceptionController()
|
||||
.registerHandler(ArgumentParseException.class, ctx ->
|
||||
carbonMessages.errorCommandArgumentParsing(ctx.context().sender(), CloudUtils.message(ctx.exception().getCause())))
|
||||
.registerHandler(InvalidCommandSenderException.class, ctx ->
|
||||
carbonMessages.errorCommandInvalidSender(ctx.context().sender(), TypeUtils.simpleName(ctx.exception().requiredSender())))
|
||||
.registerHandler(InvalidSyntaxException.class, ctx ->
|
||||
carbonMessages.errorCommandInvalidSyntax(ctx.context().sender(), Component.text(ctx.exception().correctSyntax()).replaceText(
|
||||
config -> config.match(SPECIAL_CHARACTERS_PATTERN)
|
||||
.replacement(match -> match.color(NamedTextColor.WHITE)));
|
||||
.replacement(match -> match.color(NamedTextColor.WHITE)))))
|
||||
.registerHandler(NoPermissionException.class, ctx ->
|
||||
carbonMessages.errorCommandNoPermission(ctx.context().sender()))
|
||||
.registerHandler(CommandExecutionException.class, ctx -> {
|
||||
final Throwable cause = ctx.exception().getCause();
|
||||
|
||||
carbonMessages.errorCommandInvalidSyntax(sender, syntax);
|
||||
});
|
||||
commandManager.registerExceptionHandler(NoPermissionException.class, (sender, exception) -> {
|
||||
carbonMessages.errorCommandNoPermission(sender);
|
||||
});
|
||||
commandManager.registerExceptionHandler(CommandExecutionException.class, (sender, exception) -> {
|
||||
final Throwable cause = exception.getCause();
|
||||
logger.warn("Unexpected exception executing command", cause);
|
||||
|
||||
if (cause instanceof CommandCompleted completed) {
|
||||
final @Nullable Component msg = completed.componentMessage();
|
||||
final StringWriter writer = new StringWriter();
|
||||
cause.printStackTrace(new PrintWriter(writer));
|
||||
final String stackTrace = writer.toString().replaceAll("\t", " ");
|
||||
final @Nullable Component throwableMessage = CloudUtils.message(cause);
|
||||
|
||||
carbonMessages.errorCommandCommandExecution(ctx.context().sender(), throwableMessage, stackTrace);
|
||||
})
|
||||
.registerHandler(CommandExecutionException.class, unwrappingHandler(CommandCompleted.class))
|
||||
.registerHandler(CommandCompleted.class, ctx -> {
|
||||
final @Nullable Component msg = ctx.exception().componentMessage();
|
||||
if (msg != null) {
|
||||
sender.sendMessage(msg);
|
||||
ctx.context().sender().sendMessage(msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cause.printStackTrace();
|
||||
|
||||
final StringWriter writer = new StringWriter();
|
||||
cause.printStackTrace(new PrintWriter(writer));
|
||||
final String stackTrace = writer.toString().replaceAll("\t", " ");
|
||||
final @Nullable Component throwableMessage = CloudUtils.message(cause);
|
||||
|
||||
carbonMessages.errorCommandCommandExecution(sender, throwableMessage, stackTrace);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static CarbonPlayer nonPlayerMustProvidePlayer(final CarbonMessages messages, final Commander commander) {
|
||||
|
||||
Reference in new issue
Block a user