Skip to content

Commit 95b8dbc

Browse files
mbaxjpenilla
andauthored
Handle Paper 26.2 shift in NMS->CraftItemStack. (#158)
* Handle Paper 26.2 shift in NMS->CraftItemStack. Now also looks for the asCraftMirror method which does the same thing. * Rename field --------- Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
1 parent 2ad7f2e commit 95b8dbc

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

cloud-bukkit/src/main/java/org/incendo/cloud/bukkit/parser/ItemStackParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ private static final class ModernParser<C> implements ArgumentParser.FutureArgum
161161
CraftBukkitReflection.findMethod(ITEM_INPUT_CLASS, "createItemStack", int.class, boolean.class),
162162
CraftBukkitReflection.findMethod(ITEM_INPUT_CLASS, "createItemStack", int.class)
163163
);
164-
private static final Method AS_BUKKIT_COPY_METHOD = CraftBukkitReflection
165-
.needMethod(CRAFT_ITEM_STACK_CLASS, "asBukkitCopy", NMS_ITEM_STACK_CLASS);
164+
private static final Method AS_BUKKIT_STACK_METHOD = CraftBukkitReflection.firstNonNullOrThrow(
165+
() -> "Couldn't find asBukkitCopy or asCraftMirror method on CraftItemStack",
166+
CraftBukkitReflection.findMethod(CRAFT_ITEM_STACK_CLASS, "asBukkitCopy", NMS_ITEM_STACK_CLASS),
167+
CraftBukkitReflection.findMethod(CRAFT_ITEM_STACK_CLASS, "asCraftMirror", NMS_ITEM_STACK_CLASS)
168+
);
166169
private static final Field ITEM_FIELD = CraftBukkitReflection.firstNonNullOrThrow(
167170
() -> "Couldn't find item field on ItemInput",
168171
CraftBukkitReflection.findField(ITEM_INPUT_CLASS, "b"),
@@ -278,7 +281,7 @@ public boolean hasExtraData() {
278281
final Object nmsItemStack = CREATE_ITEM_STACK_METHOD.getParameterCount() == 1
279282
? CREATE_ITEM_STACK_METHOD.invoke(this.itemInput, stackSize)
280283
: CREATE_ITEM_STACK_METHOD.invoke(this.itemInput, stackSize, true);
281-
return (ItemStack) AS_BUKKIT_COPY_METHOD.invoke(
284+
return (ItemStack) AS_BUKKIT_STACK_METHOD.invoke(
282285
null,
283286
nmsItemStack
284287
);

0 commit comments

Comments
 (0)