Fixes for cb pkg ver

This commit is contained in:
Jason Penilla 2024-04-25 11:16:53 -07:00
parent e6eff7111e
commit 0a19a66562
4 changed files with 14 additions and 10 deletions

View File

@ -39,9 +39,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start - ItemFactory#getSpawnEgg (paper had original method that returned ItemStack, upstream added identical but returned Material)
+ if (owner.equals("org/bukkit/inventory/ItemFactory") && name.equals("getSpawnEgg") && desc.equals("(Lorg/bukkit/entity/EntityType;)Lorg/bukkit/inventory/ItemStack;")) {
+ super.visitInsn(Opcodes.SWAP); // has 1 param, this moves the owner instance to the top for the checkcast
+ super.visitTypeInsn(Opcodes.CHECKCAST, CB_PACKAGE_PREFIX + "inventory/CraftItemFactory");
+ super.visitTypeInsn(Opcodes.CHECKCAST, runtimeCbPkgPrefix() + "inventory/CraftItemFactory");
+ super.visitInsn(Opcodes.SWAP); // moves param back to the the top of stack
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CB_PACKAGE_PREFIX + "inventory/CraftItemFactory", "getSpawnEgg0", desc, false);
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, runtimeCbPkgPrefix() + "inventory/CraftItemFactory", "getSpawnEgg0", desc, false);
+ return;
+ }
+ // Paper end - ItemFactory#getSpawnEgg

View File

@ -172,8 +172,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return;
}
+ if (owner.equals("org/bukkit/advancement/Advancement") && name.equals("getDisplay") && desc.endsWith(")Lorg/bukkit/advancement/AdvancementDisplay;")) {
+ super.visitTypeInsn(Opcodes.CHECKCAST, CB_PACKAGE_PREFIX + "advancement/CraftAdvancement");
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CB_PACKAGE_PREFIX + "advancement/CraftAdvancement", "getDisplay0", desc, false);
+ super.visitTypeInsn(Opcodes.CHECKCAST, runtimeCbPkgPrefix() + "advancement/CraftAdvancement");
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, runtimeCbPkgPrefix() + "advancement/CraftAdvancement", "getDisplay0", desc, false);
+ return;
+ }
// Paper end

View File

@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
@@ -0,0 +0,0 @@ public class Commodore {
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CB_PACKAGE_PREFIX + "advancement/CraftAdvancement", "getDisplay0", desc, false);
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, runtimeCbPkgPrefix() + "advancement/CraftAdvancement", "getDisplay0", desc, false);
return;
}
+ if (owner.equals("org/bukkit/WorldCreator") && name.equals("keepSpawnLoaded") && desc.equals("(Lnet/kyori/adventure/util/TriState;)V")) {

View File

@ -360,7 +360,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@DefaultQualifier(NonNull.class)
public final class MappingEnvironment {
+ public static final String LEGACY_CB_VERSION = "v1_20_R3";
+ public static final String LEGACY_CB_VERSION = "v1_20_R4";
private static final @Nullable String MAPPINGS_HASH = readMappingsHash();
private static final boolean REOBF = checkReobf();
@ -677,12 +677,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- final String NMS_REVISION_PACKAGE = "v" + manifest.getMainAttributes().getValue("CraftBukkit-Package-Version") + "/";
-
- getAndRemove.put("org/bukkit/".concat("craftbukkit/" + NMS_REVISION_PACKAGE), NMS_REVISION_PACKAGE);
- }
-
- return getAndRemove;
- }
+ private static final String CB_PACKAGE_PREFIX = "org/bukkit/".concat("craftbukkit/");
+ private static final String LEGACY_CB_PACKAGE_PREFIX = CB_PACKAGE_PREFIX + io.papermc.paper.util.MappingEnvironment.LEGACY_CB_VERSION + "/";
+ private static String runtimeCbPkgPrefix() {
+ if (io.papermc.paper.util.MappingEnvironment.reobf()) {
+ return LEGACY_CB_PACKAGE_PREFIX;
}
-
- return getAndRemove;
+ return CB_PACKAGE_PREFIX;
}
@Nonnull
private static String getOriginalOrRewrite(@Nonnull String original)