bukkit/paper: Fix BukkitBrigadierMapper#mapSimpleContextNMS on 1.18.2
This commit is contained in:
parent
52e6a53175
commit
9f6fb76a2a
1 changed files with 8 additions and 4 deletions
|
|
@ -159,7 +159,8 @@ public final class BukkitBrigadierMapper<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to register a mapping between a cloud argument parser type and an NMS brigadier argument type which
|
* Attempt to register a mapping between a cloud argument parser type and an NMS brigadier argument type which
|
||||||
* has a single-arg constructor taking CommandBuildContext.
|
* has a single-arg constructor taking CommandBuildContext. Will fall back to behavior
|
||||||
|
* of {@link #mapSimpleNMS(TypeToken, String)} on older versions.
|
||||||
*
|
*
|
||||||
* @param type Type to map
|
* @param type Type to map
|
||||||
* @param <T> argument parser type
|
* @param <T> argument parser type
|
||||||
|
|
@ -170,11 +171,14 @@ public final class BukkitBrigadierMapper<C> {
|
||||||
final @NonNull TypeToken<T> type,
|
final @NonNull TypeToken<T> type,
|
||||||
final @NonNull String argumentId
|
final @NonNull String argumentId
|
||||||
) {
|
) {
|
||||||
|
final Constructor<?> ctr = MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft(argumentId))
|
||||||
|
.getDeclaredConstructors()[0];
|
||||||
this.mapNMS(type, () -> {
|
this.mapNMS(type, () -> {
|
||||||
|
final Object[] args = ctr.getParameterCount() == 1
|
||||||
|
? new Object[]{CommandBuildContextSupplier.commandBuildContext()}
|
||||||
|
: new Object[]{};
|
||||||
try {
|
try {
|
||||||
return (ArgumentType<?>) MinecraftArgumentTypes.getClassByKey(NamespacedKey.minecraft(argumentId))
|
return (ArgumentType<?>) ctr.newInstance(args);
|
||||||
.getDeclaredConstructors()[0]
|
|
||||||
.newInstance(CommandBuildContextSupplier.commandBuildContext());
|
|
||||||
} catch (final ReflectiveOperationException e) {
|
} catch (final ReflectiveOperationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue