bukkit: Update Minecraft Brigadier argument types to work on Mojang-mapped servers (#267)
This commit is contained in:
parent
db2c3f1724
commit
04e697cca6
9 changed files with 150 additions and 101 deletions
|
|
@ -26,7 +26,6 @@ package cloud.commandframework.bukkit;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.bukkit.internal.MinecraftArgumentTypes;
|
||||
import cloud.commandframework.bukkit.parsers.BlockPredicateArgument;
|
||||
import cloud.commandframework.bukkit.parsers.EnchantmentArgument;
|
||||
|
|
@ -56,8 +55,6 @@ import java.util.logging.Level;
|
|||
*/
|
||||
public final class BukkitBrigadierMapper<C> {
|
||||
|
||||
private static final int UUID_ARGUMENT_VERSION = 16;
|
||||
|
||||
private final BukkitCommandManager<C> commandManager;
|
||||
private final CloudBrigadierManager<C, ?> brigadierManager;
|
||||
|
||||
|
|
@ -74,18 +71,13 @@ public final class BukkitBrigadierMapper<C> {
|
|||
this.commandManager = commandManager;
|
||||
this.brigadierManager = brigadierManager;
|
||||
|
||||
if (!CraftBukkitReflection.craftBukkit()) {
|
||||
this.commandManager.getOwningPlugin().getLogger().warning(
|
||||
"Could not detect relocated CraftBukkit package, NMS brigadier mappings will not be enabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.registerMappings();
|
||||
}
|
||||
|
||||
private void registerMappings() {
|
||||
/* UUID nms argument is a 1.16+ feature */
|
||||
if (CraftBukkitReflection.MAJOR_REVISION >= UUID_ARGUMENT_VERSION) {
|
||||
final Class<? extends ArgumentType<?>> uuid = MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft("uuid"));
|
||||
if (uuid != null) {
|
||||
/* Map UUID */
|
||||
this.mapSimpleNMS(new TypeToken<UUIDArgument.UUIDParser<C>>() {
|
||||
}, "uuid");
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ package cloud.commandframework.bukkit;
|
|||
|
||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||
import cloud.commandframework.bukkit.internal.BukkitBackwardsBrigadierSenderMapper;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
|
@ -53,7 +52,7 @@ final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
|||
BukkitCommandPreprocessor(final @NonNull BukkitCommandManager<C> commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
this.bukkitCapabilities = commandManager.queryCapabilities();
|
||||
if (this.bukkitCapabilities.contains(CloudBukkitCapabilities.BRIGADIER) && CraftBukkitReflection.craftBukkit()) {
|
||||
if (this.bukkitCapabilities.contains(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
this.mapper = new BukkitBackwardsBrigadierSenderMapper<>(this.commandManager);
|
||||
} else {
|
||||
this.mapper = null;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ package cloud.commandframework.bukkit;
|
|||
import cloud.commandframework.Command;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.bukkit.internal.BukkitBackwardsBrigadierSenderMapper;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
|
|
@ -64,10 +63,8 @@ class CloudCommodoreManager<C> extends BukkitPluginRegistrationHandler<C> {
|
|||
|
||||
new BukkitBrigadierMapper<>(this.commandManager, this.brigadierManager);
|
||||
|
||||
if (CraftBukkitReflection.craftBukkit()) {
|
||||
this.brigadierManager.backwardsBrigadierSenderMapper(new BukkitBackwardsBrigadierSenderMapper<>(this.commandManager));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerExternal(
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.lang.reflect.Constructor;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Utilities for doing reflection on CraftBukkit, used by the cloud implementation.
|
||||
|
|
@ -45,7 +46,7 @@ public final class CraftBukkitReflection {
|
|||
private static final String PREFIX_MC = "net.minecraft.";
|
||||
private static final String PREFIX_CRAFTBUKKIT = "org.bukkit.craftbukkit";
|
||||
private static final String CRAFT_SERVER = "CraftServer";
|
||||
private static final String VERSION;
|
||||
private static final String CB_PKG_VERSION;
|
||||
public static final int MAJOR_REVISION;
|
||||
|
||||
static {
|
||||
|
|
@ -54,18 +55,26 @@ public final class CraftBukkitReflection {
|
|||
final String nmsVersion = pkg.substring(pkg.lastIndexOf(".") + 1);
|
||||
if (!nmsVersion.contains("_")) {
|
||||
MAJOR_REVISION = -1;
|
||||
VERSION = null;
|
||||
} else {
|
||||
MAJOR_REVISION = Integer.parseInt(nmsVersion.split("_")[1]);
|
||||
}
|
||||
String name = serverClass.getName();
|
||||
name = name.substring(PREFIX_CRAFTBUKKIT.length());
|
||||
name = name.substring(0, name.length() - CRAFT_SERVER.length());
|
||||
VERSION = name;
|
||||
}
|
||||
CB_PKG_VERSION = name;
|
||||
}
|
||||
|
||||
public static boolean craftBukkit() {
|
||||
return MAJOR_REVISION != -1 && VERSION != null;
|
||||
@SafeVarargs
|
||||
public static <T> @NonNull T firstNonNullOrThrow(
|
||||
final @NonNull Supplier<@NonNull String> errorMessage,
|
||||
final @Nullable T @NonNull... elements
|
||||
) {
|
||||
for (final T element : elements) {
|
||||
if (element != null) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(errorMessage.get());
|
||||
}
|
||||
|
||||
public static @NonNull Class<?> needNMSClassOrElse(
|
||||
|
|
@ -76,17 +85,12 @@ public final class CraftBukkitReflection {
|
|||
if (nmsClass != null) {
|
||||
return nmsClass;
|
||||
}
|
||||
for (final String name : classNames) {
|
||||
final Class<?> maybe = findClass(name);
|
||||
if (maybe != null) {
|
||||
return maybe;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException(String.format(
|
||||
"Couldn't find a class! NMS: '%s' or '%s'.",
|
||||
nms,
|
||||
Arrays.toString(classNames)
|
||||
));
|
||||
return firstNonNullOrThrow(
|
||||
() -> "Couldn't find a class! NMS: '%s' or '%s'.",
|
||||
Arrays.stream(classNames)
|
||||
.map(CraftBukkitReflection::findClass)
|
||||
.toArray(Class[]::new)
|
||||
);
|
||||
}
|
||||
|
||||
public static @NonNull Class<?> needMCClass(final @NonNull String name) throws RuntimeException {
|
||||
|
|
@ -94,11 +98,11 @@ public final class CraftBukkitReflection {
|
|||
}
|
||||
|
||||
public static @NonNull Class<?> needNMSClass(final @NonNull String className) throws RuntimeException {
|
||||
return needClass(PREFIX_NMS + VERSION + className);
|
||||
return needClass(PREFIX_NMS + CB_PKG_VERSION + className);
|
||||
}
|
||||
|
||||
public static @NonNull Class<?> needOBCClass(final @NonNull String className) throws RuntimeException {
|
||||
return needClass(PREFIX_CRAFTBUKKIT + VERSION + className);
|
||||
return needClass(PREFIX_CRAFTBUKKIT + CB_PKG_VERSION + className);
|
||||
}
|
||||
|
||||
public static @Nullable Class<?> findMCClass(final @NonNull String name) throws RuntimeException {
|
||||
|
|
@ -106,11 +110,11 @@ public final class CraftBukkitReflection {
|
|||
}
|
||||
|
||||
public static @Nullable Class<?> findNMSClass(final @NonNull String className) throws RuntimeException {
|
||||
return findClass(PREFIX_NMS + VERSION + className);
|
||||
return findClass(PREFIX_NMS + CB_PKG_VERSION + className);
|
||||
}
|
||||
|
||||
public static @Nullable Class<?> findOBCClass(final @NonNull String className) throws RuntimeException {
|
||||
return findClass(PREFIX_CRAFTBUKKIT + VERSION + className);
|
||||
return findClass(PREFIX_CRAFTBUKKIT + CB_PKG_VERSION + className);
|
||||
}
|
||||
|
||||
public static @NonNull Class<?> needClass(final @NonNull String className) throws RuntimeException {
|
||||
|
|
@ -139,6 +143,14 @@ public final class CraftBukkitReflection {
|
|||
}
|
||||
}
|
||||
|
||||
public static @Nullable Field findField(final @NonNull Class<?> holder, final @NonNull String name) throws RuntimeException {
|
||||
try {
|
||||
return needField(holder, name);
|
||||
} catch (final RuntimeException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull Constructor<?> needConstructor(final @NonNull Class<?> holder, final @NonNull Class<?>... parameters) {
|
||||
try {
|
||||
return holder.getDeclaredConstructor(parameters);
|
||||
|
|
@ -151,6 +163,18 @@ public final class CraftBukkitReflection {
|
|||
return findClass(className) != null;
|
||||
}
|
||||
|
||||
public static @Nullable Method findMethod(
|
||||
final @NonNull Class<?> holder,
|
||||
final @NonNull String name,
|
||||
final @NonNull Class<?>... params
|
||||
) throws RuntimeException {
|
||||
try {
|
||||
return holder.getMethod(name, params);
|
||||
} catch (final NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull Method needMethod(
|
||||
final @NonNull Class<?> holder,
|
||||
final @NonNull String name,
|
||||
|
|
|
|||
|
|
@ -78,12 +78,15 @@ public final class MinecraftArgumentTypes {
|
|||
if (CraftBukkitReflection.findMCClass("resources.ResourceLocation") != null) {
|
||||
minecraftKey = CraftBukkitReflection.needMCClass("resources.ResourceLocation");
|
||||
argumentRegistry = CraftBukkitReflection.needMCClass("commands.synchronization.ArgumentTypes");
|
||||
} else if (CraftBukkitReflection.MAJOR_REVISION > 16) {
|
||||
minecraftKey = CraftBukkitReflection.needMCClass("resources.MinecraftKey");
|
||||
argumentRegistry = CraftBukkitReflection.needMCClass("commands.synchronization.ArgumentRegistry");
|
||||
} else {
|
||||
minecraftKey = CraftBukkitReflection.needNMSClass("MinecraftKey");
|
||||
argumentRegistry = CraftBukkitReflection.needNMSClass("ArgumentRegistry");
|
||||
minecraftKey = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"MinecraftKey",
|
||||
"net.minecraft.resources.MinecraftKey"
|
||||
);
|
||||
argumentRegistry = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentRegistry",
|
||||
"commands.synchronization.ArgumentRegistry"
|
||||
);
|
||||
}
|
||||
|
||||
MINECRAFT_KEY_CONSTRUCTOR = minecraftKey.getConstructor(String.class, String.class);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,11 @@ import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
|||
import cloud.commandframework.bukkit.BukkitCommandManager;
|
||||
import cloud.commandframework.bukkit.data.BlockPredicate;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.bukkit.internal.MinecraftArgumentTypes;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -142,13 +144,15 @@ public final class BlockPredicateArgument<C> extends CommandArgument<C, BlockPre
|
|||
private static final Class<?> TAG_REGISTRY_CLASS;
|
||||
|
||||
static {
|
||||
if (CraftBukkitReflection.MAJOR_REVISION >= 16) {
|
||||
TAG_REGISTRY_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ITagRegistry",
|
||||
"net.minecraft.tags.ITagRegistry"
|
||||
);
|
||||
} else {
|
||||
if (CraftBukkitReflection.MAJOR_REVISION > 12 && CraftBukkitReflection.MAJOR_REVISION < 16) {
|
||||
TAG_REGISTRY_CLASS = CraftBukkitReflection.needNMSClass("TagRegistry");
|
||||
} else {
|
||||
TAG_REGISTRY_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find TagContainer class",
|
||||
CraftBukkitReflection.findNMSClass("ITagRegistry"),
|
||||
CraftBukkitReflection.findMCClass("tags.ITagRegistry"),
|
||||
CraftBukkitReflection.findMCClass("tags.TagContainer")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,42 +161,52 @@ public final class BlockPredicateArgument<C> extends CommandArgument<C, BlockPre
|
|||
"MinecraftServer",
|
||||
"net.minecraft.server.MinecraftServer"
|
||||
);
|
||||
private static final Class<?> COMMAND_LISTENER_WRAPPER_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"CommandListenerWrapper",
|
||||
"net.minecraft.commands.CommandListenerWrapper"
|
||||
private static final Class<?> COMMAND_LISTENER_WRAPPER_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find CommandSourceStack class",
|
||||
CraftBukkitReflection.findNMSClass("CommandListenerWrapper"),
|
||||
CraftBukkitReflection.findMCClass("commands.CommandListenerWrapper"),
|
||||
CraftBukkitReflection.findMCClass("commands.CommandSourceStack")
|
||||
);
|
||||
private static final Class<?> ARGUMENT_BLOCK_PREDICATE_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentBlockPredicate",
|
||||
"net.minecraft.commands.arguments.blocks.ArgumentBlockPredicate"
|
||||
private static final Class<?> ARGUMENT_BLOCK_PREDICATE_CLASS =
|
||||
MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft("block_predicate"));
|
||||
private static final Class<?> ARGUMENT_BLOCK_PREDICATE_RESULT_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find BlockPredicateArgument$Result class",
|
||||
CraftBukkitReflection.findNMSClass("ArgumentBlockPredicate$b"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.blocks.ArgumentBlockPredicate$b"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.blocks.BlockPredicateArgument$Result")
|
||||
);
|
||||
private static final Class<?> ARGUMENT_BLOCK_PREDICATE_RESULT_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentBlockPredicate$b",
|
||||
"net.minecraft.commands.arguments.blocks.ArgumentBlockPredicate$b"
|
||||
private static final Class<?> SHAPE_DETECTOR_BLOCK_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find BlockInWorld class",
|
||||
CraftBukkitReflection.findNMSClass("ShapeDetectorBlock"),
|
||||
CraftBukkitReflection.findMCClass("world.level.block.state.pattern.ShapeDetectorBlock"),
|
||||
CraftBukkitReflection.findMCClass("world.level.block.state.pattern.BlockInWorld")
|
||||
);
|
||||
// BlockInWorld
|
||||
private static final Class<?> SHAPE_DETECTOR_BLOCK_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ShapeDetectorBlock",
|
||||
"net.minecraft.world.level.block.state.pattern.ShapeDetectorBlock"
|
||||
private static final Class<?> LEVEL_READER_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find LevelReader class",
|
||||
CraftBukkitReflection.findNMSClass("IWorldReader"),
|
||||
CraftBukkitReflection.findMCClass("world.level.IWorldReader"),
|
||||
CraftBukkitReflection.findMCClass("world.level.LevelReader")
|
||||
);
|
||||
private static final Class<?> I_WORLD_READER_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"IWorldReader",
|
||||
"net.minecraft.world.level.IWorldReader"
|
||||
);
|
||||
private static final Class<?> BLOCK_POSITION_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"BlockPosition",
|
||||
"net.minecraft.core.BlockPosition"
|
||||
private static final Class<?> BLOCK_POSITION_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find BlockPos class",
|
||||
CraftBukkitReflection.findNMSClass("BlockPosition"),
|
||||
CraftBukkitReflection.findMCClass("core.BlockPosition"),
|
||||
CraftBukkitReflection.findMCClass("core.BlockPos")
|
||||
);
|
||||
private static final Constructor<?> BLOCK_POSITION_CTR =
|
||||
CraftBukkitReflection.needConstructor(BLOCK_POSITION_CLASS, int.class, int.class, int.class);
|
||||
private static final Constructor<?> SHAPE_DETECTOR_BLOCK_CTR = CraftBukkitReflection
|
||||
.needConstructor(SHAPE_DETECTOR_BLOCK_CLASS, I_WORLD_READER_CLASS, BLOCK_POSITION_CLASS, boolean.class);
|
||||
.needConstructor(SHAPE_DETECTOR_BLOCK_CLASS, LEVEL_READER_CLASS, BLOCK_POSITION_CLASS, boolean.class);
|
||||
private static final Method GET_HANDLE_METHOD = CraftBukkitReflection.needMethod(CRAFT_WORLD_CLASS, "getHandle");
|
||||
private static final Method CREATE_PREDICATE_METHOD =
|
||||
CraftBukkitReflection.needMethod(ARGUMENT_BLOCK_PREDICATE_RESULT_CLASS, "create", TAG_REGISTRY_CLASS);
|
||||
private static final Method GET_SERVER_METHOD =
|
||||
CraftBukkitReflection.needMethod(COMMAND_LISTENER_WRAPPER_CLASS, "getServer");
|
||||
private static final Method GET_TAG_REGISTRY_METHOD =
|
||||
CraftBukkitReflection.needMethod(MINECRAFT_SERVER_CLASS, "getTagRegistry");
|
||||
private static final Method GET_TAG_REGISTRY_METHOD = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "getTags method on MinecraftServer",
|
||||
CraftBukkitReflection.findMethod(MINECRAFT_SERVER_CLASS, "getTagRegistry"),
|
||||
CraftBukkitReflection.findMethod(MINECRAFT_SERVER_CLASS, "getTags")
|
||||
);
|
||||
|
||||
private final ArgumentParser<C, BlockPredicate> parser;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,12 @@ import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
|||
import cloud.commandframework.bukkit.BukkitCommandManager;
|
||||
import cloud.commandframework.bukkit.data.ProtoItemStack;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.bukkit.internal.MinecraftArgumentTypes;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -49,6 +51,8 @@ import java.util.Queue;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Argument type for parsing a {@link Material} and optional extra NBT data into a {@link ProtoItemStack}.
|
||||
*
|
||||
|
|
@ -150,10 +154,7 @@ public final class ItemStackArgument<C> extends CommandArgument<C, ProtoItemStac
|
|||
* @since 1.5.0
|
||||
*/
|
||||
public Parser() {
|
||||
if (!CraftBukkitReflection.craftBukkit()) {
|
||||
throw new UnsupportedOperationException("ItemStack parser requires CraftBukkit");
|
||||
}
|
||||
if (CraftBukkitReflection.MAJOR_REVISION >= 13) {
|
||||
if (findItemInputClass() != null) {
|
||||
this.parser = new ModernParser<>();
|
||||
} else {
|
||||
this.parser = new LegacyParser<>();
|
||||
|
|
@ -178,6 +179,20 @@ public final class ItemStackArgument<C> extends CommandArgument<C, ProtoItemStac
|
|||
|
||||
}
|
||||
|
||||
private static @Nullable Class<?> findItemInputClass() {
|
||||
final Class<?>[] classes = new Class<?>[] {
|
||||
CraftBukkitReflection.findNMSClass("ArgumentPredicateItemStack"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.item.ArgumentPredicateItemStack"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.item.ItemInput")
|
||||
};
|
||||
for (final Class<?> clazz : classes) {
|
||||
if (clazz != null) {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final class ModernParser<C> implements ArgumentParser<C, ProtoItemStack> {
|
||||
|
||||
private static final Class<?> NMS_ITEM_STACK_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
|
|
@ -186,14 +201,9 @@ public final class ItemStackArgument<C> extends CommandArgument<C, ProtoItemStac
|
|||
);
|
||||
private static final Class<?> CRAFT_ITEM_STACK_CLASS =
|
||||
CraftBukkitReflection.needOBCClass("inventory.CraftItemStack");
|
||||
private static final Class<?> ARGUMENT_ITEM_STACK_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentItemStack",
|
||||
"net.minecraft.commands.arguments.item.ArgumentItemStack"
|
||||
);
|
||||
private static final Class<?> ARGUMENT_PREDICATE_ITEM_STACK_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentPredicateItemStack",
|
||||
"net.minecraft.commands.arguments.item.ArgumentPredicateItemStack"
|
||||
);
|
||||
private static final Class<?> ARGUMENT_ITEM_STACK_CLASS =
|
||||
MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft("item_stack"));
|
||||
private static final Class<?> ITEM_INPUT_CLASS = requireNonNull(findItemInputClass(), "ItemInput class");
|
||||
private static final Class<?> NMS_ITEM_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"Item",
|
||||
"net.minecraft.world.item.Item"
|
||||
|
|
@ -202,12 +212,23 @@ public final class ItemStackArgument<C> extends CommandArgument<C, ProtoItemStac
|
|||
CraftBukkitReflection.needOBCClass("util.CraftMagicNumbers");
|
||||
private static final Method GET_MATERIAL_METHOD = CraftBukkitReflection
|
||||
.needMethod(CRAFT_MAGIC_NUMBERS_CLASS, "getMaterial", NMS_ITEM_CLASS);
|
||||
private static final Method CREATE_ITEM_STACK_METHOD = CraftBukkitReflection
|
||||
.needMethod(ARGUMENT_PREDICATE_ITEM_STACK_CLASS, "a", int.class, boolean.class);
|
||||
private static final Method CREATE_ITEM_STACK_METHOD = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find createItemStack method on ItemInput",
|
||||
CraftBukkitReflection.findMethod(ITEM_INPUT_CLASS, "a", int.class, boolean.class),
|
||||
CraftBukkitReflection.findMethod(ITEM_INPUT_CLASS, "createItemStack", int.class, boolean.class)
|
||||
);
|
||||
private static final Method AS_BUKKIT_COPY_METHOD = CraftBukkitReflection
|
||||
.needMethod(CRAFT_ITEM_STACK_CLASS, "asBukkitCopy", NMS_ITEM_STACK_CLASS);
|
||||
private static final Field ITEM_FIELD = CraftBukkitReflection.needField(ARGUMENT_PREDICATE_ITEM_STACK_CLASS, "b");
|
||||
private static final Field COMPOUND_TAG_FIELD = CraftBukkitReflection.needField(ARGUMENT_PREDICATE_ITEM_STACK_CLASS, "c");
|
||||
private static final Field ITEM_FIELD = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find item field on ItemInput",
|
||||
CraftBukkitReflection.findField(ITEM_INPUT_CLASS, "b"),
|
||||
CraftBukkitReflection.findField(ITEM_INPUT_CLASS, "item")
|
||||
);
|
||||
private static final Field COMPOUND_TAG_FIELD = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find tag field on ItemInput",
|
||||
CraftBukkitReflection.findField(ITEM_INPUT_CLASS, "c"),
|
||||
CraftBukkitReflection.findField(ITEM_INPUT_CLASS, "tag")
|
||||
);
|
||||
|
||||
private final ArgumentParser<C, ProtoItemStack> parser;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,10 +31,12 @@ import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
|||
import cloud.commandframework.bukkit.BukkitCommandManager;
|
||||
import cloud.commandframework.bukkit.data.ItemStackPredicate;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.bukkit.internal.MinecraftArgumentTypes;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.StringRange;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -142,13 +144,13 @@ public final class ItemStackPredicateArgument<C> extends CommandArgument<C, Item
|
|||
|
||||
private static final Class<?> CRAFT_ITEM_STACK_CLASS =
|
||||
CraftBukkitReflection.needOBCClass("inventory.CraftItemStack");
|
||||
private static final Class<?> ARGUMENT_ITEM_PREDICATE_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentItemPredicate",
|
||||
"net.minecraft.commands.arguments.item.ArgumentItemPredicate"
|
||||
);
|
||||
private static final Class<?> ARGUMENT_ITEM_PREDICATE_RESULT_CLASS = CraftBukkitReflection.needNMSClassOrElse(
|
||||
"ArgumentItemPredicate$b",
|
||||
"net.minecraft.commands.arguments.item.ArgumentItemPredicate$b"
|
||||
private static final Class<?> ARGUMENT_ITEM_PREDICATE_CLASS =
|
||||
MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft("item_predicate"));
|
||||
private static final Class<?> ARGUMENT_ITEM_PREDICATE_RESULT_CLASS = CraftBukkitReflection.firstNonNullOrThrow(
|
||||
() -> "Couldn't find ItemPredicateArgument$Result class",
|
||||
CraftBukkitReflection.findNMSClass("ArgumentItemPredicate$b"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.item.ArgumentItemPredicate$b"),
|
||||
CraftBukkitReflection.findMCClass("commands.arguments.item.ItemPredicateArgument$Result")
|
||||
);
|
||||
private static final Method CREATE_PREDICATE_METHOD = CraftBukkitReflection.needMethod(
|
||||
ARGUMENT_ITEM_PREDICATE_RESULT_CLASS,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.bukkit.BukkitBrigadierMapper;
|
||||
import cloud.commandframework.bukkit.internal.BukkitBackwardsBrigadierSenderMapper;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.permission.CommandPermission;
|
||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||
|
|
@ -58,11 +57,9 @@ class PaperBrigadierListener<C> implements Listener {
|
|||
|
||||
new BukkitBrigadierMapper<>(this.paperCommandManager, this.brigadierManager);
|
||||
|
||||
if (CraftBukkitReflection.craftBukkit()) {
|
||||
this.brigadierManager
|
||||
.backwardsBrigadierSenderMapper(new BukkitBackwardsBrigadierSenderMapper<>(this.paperCommandManager));
|
||||
}
|
||||
}
|
||||
|
||||
protected @NonNull CloudBrigadierManager<C, BukkitBrigadierCommandSource> brigadierManager() {
|
||||
return this.brigadierManager;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue