feat: fixup paper custom argument types

dependabot/gradle/org.projectlombok-lombok-1.18.34
William 5 months ago
parent 00b3beea32
commit 27ec5a3176
No known key found for this signature in database

@ -179,7 +179,7 @@ public abstract class BaseCommand<S> {
@NotNull
public static <S, T> ArgumentElement<S, T> arg(@NotNull String name, @NotNull ArgumentType<T> type,
@Nullable SuggestionProvider<S> suggestionProvider) {
return new ArgumentElement<>(name, type, suggestionProvider);
return new ArgumentElement<>(name, type, suggestionProvider, false);
}
@NotNull

@ -26,11 +26,26 @@ import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public record ArgumentElement<S, T>(@NotNull String name, @NotNull ArgumentType<T> type,
@Nullable SuggestionProvider<S> suggestionProvider) implements CommandElement<S> {
@Accessors(fluent = true)
@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public final class ArgumentElement<S, T> implements CommandElement<S> {
@NotNull
private final String name;
@NotNull
private final ArgumentType<T> type;
@Nullable
private final SuggestionProvider<S> suggestionProvider;
private boolean custom = true;
@Override
@NotNull

@ -24,11 +24,10 @@ package net.william278.uniform.paper;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command;
import net.william278.uniform.CommandUser;
import net.william278.uniform.Uniform;
import net.william278.uniform.*;
import net.william278.uniform.element.ArgumentElement;
import net.william278.uniform.element.CommandElement;
import net.william278.uniform.paper.element.PaperArgumentElement;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -107,6 +106,28 @@ public class PaperCommand extends BaseCommand<CommandSourceStack> {
});
}
@Override
@NotNull
@SuppressWarnings("unchecked")
public List<CommandSyntax<CommandSourceStack>> getSyntaxes() {
return super.getSyntaxes().stream().map(
syntax -> new CommandSyntax<>(
syntax.condition(),
syntax.executor(),
syntax.elements().stream()
.filter(e -> e instanceof ArgumentElement)
.map(e -> (ArgumentElement<?, ?>) e)
.map(e -> e.custom() ? new ArgumentElement<>(
e.name(),
new PaperArgumentElement<>(e.type()),
e.suggestionProvider()
) : e)
.map(e -> (CommandElement<CommandSourceStack>) e)
.toList()
)
).toList();
}
@Override
public void addSubCommand(@NotNull Command command) {
addSubCommand(new PaperCommand(command));

@ -0,0 +1,50 @@
/*
* This file is part of Uniform, licensed under the GNU General Public License v3.0.
*
* Copyright (c) Tofaa2
* Copyright (c) William278 <will27528@gmail.com>
* Copyright (c) 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.william278.uniform.paper.element;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;
@AllArgsConstructor
@SuppressWarnings("UnstableApiUsage")
public class PaperArgumentElement<T> implements CustomArgumentType<T, String> {
private final ArgumentType<T> wrapped;
@Override
@NotNull
public T parse(@NotNull StringReader reader) throws CommandSyntaxException {
return wrapped.parse(reader);
}
@Override
@NotNull
public ArgumentType<String> getNativeType() {
return StringArgumentType.string();
}
}
Loading…
Cancel
Save