From 162ffd3599e47241be6dd54f1c5712f20121cee6 Mon Sep 17 00:00:00 2001 From: Len <40720638+destro174@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:47:09 +0200 Subject: [PATCH] Update GameModeCommand to use native GameModeArgument --- .../commands/admin/GameModeCommand.java | 3 +- .../commands/argumement/GameModeArgument.java | 48 ------------------- 2 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 plugin/src/main/java/com/alttd/essentia/commands/argumement/GameModeArgument.java diff --git a/plugin/src/main/java/com/alttd/essentia/commands/admin/GameModeCommand.java b/plugin/src/main/java/com/alttd/essentia/commands/admin/GameModeCommand.java index 46f178a..bc02ba3 100644 --- a/plugin/src/main/java/com/alttd/essentia/commands/admin/GameModeCommand.java +++ b/plugin/src/main/java/com/alttd/essentia/commands/admin/GameModeCommand.java @@ -1,7 +1,6 @@ package com.alttd.essentia.commands.admin; import com.alttd.essentia.commands.EssentiaCommand; -import com.alttd.essentia.commands.argumement.GameModeArgument; import com.alttd.essentia.configuration.Config; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.tree.LiteralCommandNode; @@ -28,7 +27,7 @@ public class GameModeCommand implements EssentiaCommand { commandSourceStack -> commandSourceStack.getSender().hasPermission("essentia.command.admin." + commandName) ) .then( - Commands.argument("gamemode", new GameModeArgument()) + Commands.argument("gamemode", ArgumentTypes.gameMode()) .executes((source) -> { if (!(source.getSource().getSender() instanceof Player player)) return 1; diff --git a/plugin/src/main/java/com/alttd/essentia/commands/argumement/GameModeArgument.java b/plugin/src/main/java/com/alttd/essentia/commands/argumement/GameModeArgument.java deleted file mode 100644 index 3fc603e..0000000 --- a/plugin/src/main/java/com/alttd/essentia/commands/argumement/GameModeArgument.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.alttd.essentia.commands.argumement; - -import com.mojang.brigadier.Message; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import io.papermc.paper.command.brigadier.MessageComponentSerializer; -import io.papermc.paper.command.brigadier.argument.CustomArgumentType; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.bukkit.GameMode; -import org.jetbrains.annotations.NotNull; - -import java.util.concurrent.CompletableFuture; - -public class GameModeArgument implements CustomArgumentType.Converted { - - @Override - public @NotNull GameMode convert(String nativeType) throws CommandSyntaxException { - try { - return GameMode.valueOf(nativeType.toUpperCase()); - } catch (Exception e) { - Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid gamemode %s!".formatted(nativeType), NamedTextColor.RED)); - - throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message); - } - } - - @Override - public @NotNull ArgumentType getNativeType() { - return StringArgumentType.word(); - } - - @Override - public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - for (GameMode gameMode : GameMode.values()) { - builder.suggest(gameMode.name().toLowerCase()); - } - - return CompletableFuture.completedFuture( - builder.build() - ); - } -} \ No newline at end of file