Remove EnchantmentArgument.java

This commit is contained in:
Len 2024-10-04 22:46:24 +02:00
parent d786ebcff5
commit 434cf6ac15
2 changed files with 2 additions and 53 deletions

View File

@ -1,7 +1,6 @@
package com.alttd.essentia.commands.admin;
import com.alttd.essentia.commands.EssentiaCommand;
import com.alttd.essentia.commands.argumement.EnchantmentArgument;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
@ -9,6 +8,7 @@ import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.bukkit.Material;
@ -33,7 +33,7 @@ public class EnchantCommand implements EssentiaCommand {
commandSourceStack -> commandSourceStack.getSender().hasPermission(adminCommandPermission())
)
.then(
Commands.argument("enchantment", new EnchantmentArgument())
Commands.argument("enchantment", ArgumentTypes.resource(RegistryKey.ENCHANTMENT))
.executes((source) -> {
if (!(source.getSource().getSender() instanceof Player player))
return 1;

View File

@ -1,51 +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 io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
public class EnchantmentArgument implements CustomArgumentType.Converted<Enchantment, String> {
@Override
public @NotNull Enchantment convert(String nativeType) throws CommandSyntaxException {
try {
return Enchantment.getByKey(NamespacedKey.minecraft(nativeType));
} catch (Exception e) {
Message message = MessageComponentSerializer.message().serialize(Component.text("Invalid enchantment %s!".formatted(nativeType), NamedTextColor.RED));
throw new CommandSyntaxException(new SimpleCommandExceptionType(message), message);
}
}
@Override
public @NotNull ArgumentType<String> getNativeType() {
return StringArgumentType.word();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
for (Enchantment enchantment : RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT)) {
builder.suggest(enchantment.getKey().value());
}
return CompletableFuture.completedFuture(
builder.build()
);
}
}