From d9511cad24588818c5e46fd61dcd4c003d878dae Mon Sep 17 00:00:00 2001 From: Nils Gereke Date: Sat, 4 Oct 2025 12:48:46 +0200 Subject: [PATCH 1/5] feat: 1.21.9 support --- .github/workflows/buildtools.sh | 3 +- zip-nms/pom.xml | 1 + zip-nms/zip-nms-v1_21_R6/pom.xml | 70 ++++++ .../zip/nms/v1_21_R6/ZipNmsManager.java | 208 ++++++++++++++++++ zip-plugin/pom.xml | 6 + 5 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 zip-nms/zip-nms-v1_21_R6/pom.xml create mode 100644 zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java diff --git a/.github/workflows/buildtools.sh b/.github/workflows/buildtools.sh index c5da7e3..29a1243 100644 --- a/.github/workflows/buildtools.sh +++ b/.github/workflows/buildtools.sh @@ -36,4 +36,5 @@ checkVersion "1.21" "21" checkVersion "1.21.3" "21" checkVersion "1.21.4" "21" checkVersion "1.21.5" "21" -checkVersion "1.21.6" "21" \ No newline at end of file +checkVersion "1.21.6" "21" +checkVersion "1.21.9" "21" \ No newline at end of file diff --git a/zip-nms/pom.xml b/zip-nms/pom.xml index a064cdc..896168c 100644 --- a/zip-nms/pom.xml +++ b/zip-nms/pom.xml @@ -24,5 +24,6 @@ zip-nms-v1_21_R3 zip-nms-v1_21_R4 zip-nms-v1_21_R5 + zip-nms-v1_21_R6 \ No newline at end of file diff --git a/zip-nms/zip-nms-v1_21_R6/pom.xml b/zip-nms/zip-nms-v1_21_R6/pom.xml new file mode 100644 index 0000000..be61515 --- /dev/null +++ b/zip-nms/zip-nms-v1_21_R6/pom.xml @@ -0,0 +1,70 @@ + + 4.0.0 + + + net.imprex + zip-nms + ${revision} + + + zip-nms-v1_21_R5 + + + + net.imprex + zip-nms-api + ${revision} + provided + + + org.spigotmc + spigot + 1.21.9-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + ${plugin.specialsource.version} + + + package + + remap + + remap-obf + + + org.spigotmc:minecraft-server:1.21.9-R0.1-SNAPSHOT:txt:maps-mojang + true + + org.spigotmc:spigot:1.21.9-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + + org.spigotmc:minecraft-server:1.21.9-R0.1-SNAPSHOT:csrg:maps-spigot + + org.spigotmc:spigot:1.21.9-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + + \ No newline at end of file diff --git a/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java new file mode 100644 index 0000000..4b06adb --- /dev/null +++ b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java @@ -0,0 +1,208 @@ +package net.imprex.zip.nms.v1_21_R6; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.function.BiConsumer; + +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_21_R6.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Dynamic; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.JsonOps; + +import net.imprex.zip.common.BPConstants; +import net.imprex.zip.common.ReflectionUtil; +import net.imprex.zip.nms.api.ItemStackContainerResult; +import net.imprex.zip.nms.api.ItemStackWithSlot; +import net.imprex.zip.nms.api.NmsManager; +import net.minecraft.SharedConstants; +import net.minecraft.core.RegistryAccess; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtAccounter; +import net.minecraft.nbt.NbtIo; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.datafix.DataFixers; +import net.minecraft.util.datafix.fixes.References; +import net.minecraft.world.item.component.ResolvableProfile; + +public class ZipNmsManager implements NmsManager { + + private static final int DATA_VERSION = SharedConstants.getCurrentVersion().dataVersion().version(); + + @SuppressWarnings("deprecation") + private static final RegistryAccess DEFAULT_REGISTRY = MinecraftServer.getServer().registryAccess(); + + private static final DynamicOps DYNAMIC_OPS_NBT = DEFAULT_REGISTRY.createSerializationContext(NbtOps.INSTANCE); + private static final DynamicOps DYNAMIC_OPS_JSON = DEFAULT_REGISTRY.createSerializationContext(JsonOps.INSTANCE); + + private static final BiConsumer SET_PROFILE; + + static { + BiConsumer setProfile = (meta, profile) -> { + throw new NullPointerException("Unable to find 'setProfile' method!"); + }; + + Class craftMetaSkullClass = new ItemStack(Material.PLAYER_HEAD) + .getItemMeta() + .getClass(); + + Method setResolvableProfileMethod = ReflectionUtil.searchMethod(craftMetaSkullClass, void.class, ResolvableProfile.class); + if (setResolvableProfileMethod != null) { + setProfile = (meta, profile) -> { + try { + setResolvableProfileMethod.invoke(meta, new ResolvableProfile(profile)); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + }; + } else { + Method setProfileMethod = ReflectionUtil.searchMethod(craftMetaSkullClass, void.class, GameProfile.class); + if (setProfileMethod != null) { + setProfile = (meta, profile) -> { + try { + setProfileMethod.invoke(meta, profile); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + }; + } + } + + SET_PROFILE = setProfile; + } + + @Override + public JsonObject itemstackToJsonElement(ItemStack[] items) { + JsonArray jsonItems = new JsonArray(); + for (int slot = 0; slot < items.length; slot++) { + ItemStack item = items[slot]; + if (item == null || item.getType() == Material.AIR) { + continue; + } + net.minecraft.world.item.ItemStack minecraftItem = CraftItemStack.asNMSCopy(item); + + DataResult result = net.minecraft.world.item.ItemStack.CODEC.encodeStart(DYNAMIC_OPS_JSON, minecraftItem); + JsonObject resultJson = result.getOrThrow().getAsJsonObject(); + + resultJson.addProperty(BPConstants.KEY_INVENTORY_SLOT, slot); + jsonItems.add(resultJson); + } + + JsonObject outputJson = new JsonObject(); + outputJson.addProperty(BPConstants.KEY_INVENTORY_VERSION, BPConstants.INVENTORY_VERSION); + outputJson.addProperty(BPConstants.KEY_INVENTORY_DATA_VERSION, DATA_VERSION); + outputJson.addProperty(BPConstants.KEY_INVENTORY_ITEMS_SIZE, items.length); + outputJson.add(BPConstants.KEY_INVENTORY_ITEMS, jsonItems); + return outputJson; + } + + @Override + public ItemStackContainerResult jsonElementToItemStack(JsonObject json) { + // check if current version the same + if (json.get(BPConstants.KEY_INVENTORY_VERSION).getAsInt() != BPConstants.INVENTORY_VERSION) { + throw new IllegalStateException("Unable to convert binary to itemstack because zip version is missmatching"); + } + + int dataVersion = json.get(BPConstants.KEY_INVENTORY_DATA_VERSION).getAsInt(); + int itemsSize = json.get(BPConstants.KEY_INVENTORY_ITEMS_SIZE).getAsInt(); + + List items = new ArrayList<>(); + + JsonArray jsonItems = json.get(BPConstants.KEY_INVENTORY_ITEMS).getAsJsonArray(); + for (JsonElement item : jsonItems) { + Dynamic dynamicItem = new Dynamic<>(JsonOps.INSTANCE, item); + Dynamic dynamicItemFixed = DataFixers.getDataFixer() + .update(References.ITEM_STACK, dynamicItem, dataVersion, DATA_VERSION); + + net.minecraft.world.item.ItemStack minecraftItem = net.minecraft.world.item.ItemStack.CODEC + .parse(DYNAMIC_OPS_JSON, dynamicItemFixed.getValue()) + .getOrThrow(); + + ItemStack bukkitItem = CraftItemStack.asCraftMirror(minecraftItem); + int slot = item.getAsJsonObject().get(BPConstants.KEY_INVENTORY_SLOT).getAsInt(); + + items.add(new ItemStackWithSlot(slot, bukkitItem)); + } + + return new ItemStackContainerResult(itemsSize, items); + } + + @Override + public JsonObject migrateToJsonElement(byte[] binary) { + CompoundTag compound; + try (ByteArrayInputStream inputStream = new ByteArrayInputStream(binary)) { + compound = NbtIo.readCompressed(inputStream, NbtAccounter.unlimitedHeap()); + } catch (IOException e) { + throw new IllegalStateException("Unable to parse binary to nbt", e); + } + + ListTag list = compound.getListOrEmpty("i"); + + int currentSlot = 0; + + JsonArray jsonItems = new JsonArray(); + for (Tag base : list) { + if (base instanceof CompoundTag itemTag) { + String itemType = itemTag.getString("id").orElse(""); + if (itemType.equals("minecraft:air")) { + currentSlot++; + continue; + } + + Dynamic dynamicItem = new Dynamic<>(NbtOps.INSTANCE, itemTag); + net.minecraft.world.item.ItemStack minecraftItem = net.minecraft.world.item.ItemStack.CODEC + .parse(DYNAMIC_OPS_NBT, dynamicItem.getValue()) + .getOrThrow(); + + DataResult result = net.minecraft.world.item.ItemStack.CODEC.encodeStart(DYNAMIC_OPS_JSON, minecraftItem); + JsonObject resultJson = result.getOrThrow().getAsJsonObject(); + + resultJson.addProperty(BPConstants.KEY_INVENTORY_SLOT, currentSlot); + jsonItems.add(resultJson); + + currentSlot++; + } + } + + JsonObject json = new JsonObject(); + json.addProperty(BPConstants.KEY_INVENTORY_VERSION, BPConstants.INVENTORY_VERSION); + json.addProperty(BPConstants.KEY_INVENTORY_DATA_VERSION, DATA_VERSION); + json.addProperty(BPConstants.KEY_INVENTORY_ITEMS_SIZE, list.size()); + json.add(BPConstants.KEY_INVENTORY_ITEMS, jsonItems); + return json; + } + + @Override + public void setSkullProfile(SkullMeta meta, String texture) { + try { + GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ""); + gameProfile.getProperties().put("textures", new Property("textures", texture)); + + SET_PROFILE.accept(meta, gameProfile); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public boolean isAir(Material material) { + return material == null || material == Material.AIR; + } +} \ No newline at end of file diff --git a/zip-plugin/pom.xml b/zip-plugin/pom.xml index 7aa6882..cd7515d 100644 --- a/zip-plugin/pom.xml +++ b/zip-plugin/pom.xml @@ -119,5 +119,11 @@ ${revision} compile + + net.imprex + zip-nms-v1_21_R6 + ${revision} + compile + \ No newline at end of file From 77af1859bd98238aca3a6ea1b6934968edebe34f Mon Sep 17 00:00:00 2001 From: Nils Gereke Date: Sat, 4 Oct 2025 12:49:58 +0200 Subject: [PATCH 2/5] fix: wrong pom articact id --- zip-nms/zip-nms-v1_21_R6/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zip-nms/zip-nms-v1_21_R6/pom.xml b/zip-nms/zip-nms-v1_21_R6/pom.xml index be61515..65d0555 100644 --- a/zip-nms/zip-nms-v1_21_R6/pom.xml +++ b/zip-nms/zip-nms-v1_21_R6/pom.xml @@ -7,7 +7,7 @@ ${revision} - zip-nms-v1_21_R5 + zip-nms-v1_21_R6 From 47cafc3dc71160c42f961157d27ecfcc5dd50126 Mon Sep 17 00:00:00 2001 From: Nils Gereke Date: Sat, 4 Oct 2025 13:56:17 +0200 Subject: [PATCH 3/5] fix: profile constructor --- .../main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java index 4b06adb..c7c88be 100644 --- a/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java +++ b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java @@ -67,7 +67,7 @@ public class ZipNmsManager implements NmsManager { if (setResolvableProfileMethod != null) { setProfile = (meta, profile) -> { try { - setResolvableProfileMethod.invoke(meta, new ResolvableProfile(profile)); + setResolvableProfileMethod.invoke(meta, ResolvableProfile.createResolved(profile)); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } @@ -193,7 +193,7 @@ public JsonObject migrateToJsonElement(byte[] binary) { public void setSkullProfile(SkullMeta meta, String texture) { try { GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ""); - gameProfile.getProperties().put("textures", new Property("textures", texture)); + gameProfile.properties().put("textures", new Property("textures", texture)); SET_PROFILE.accept(meta, gameProfile); } catch (Exception e) { From f3ec255e4b996994ab6b401462755c86b53cd6f0 Mon Sep 17 00:00:00 2001 From: Nils Gereke Date: Sat, 4 Oct 2025 14:05:04 +0200 Subject: [PATCH 4/5] fix: missing minecraft version mapping --- .../src/main/java/net/imprex/zip/common/MinecraftVersion.java | 1 + 1 file changed, 1 insertion(+) diff --git a/zip-common/src/main/java/net/imprex/zip/common/MinecraftVersion.java b/zip-common/src/main/java/net/imprex/zip/common/MinecraftVersion.java index 408c70f..590d089 100644 --- a/zip-common/src/main/java/net/imprex/zip/common/MinecraftVersion.java +++ b/zip-common/src/main/java/net/imprex/zip/common/MinecraftVersion.java @@ -18,6 +18,7 @@ private static final class NmsMapping { private static final List MAPPINGS = new ArrayList<>(); static { + MAPPINGS.add(new NmsMapping("1.21.9", "v1_21_R6")); MAPPINGS.add(new NmsMapping("1.21.6", "v1_21_R5")); MAPPINGS.add(new NmsMapping("1.21.5", "v1_21_R4")); MAPPINGS.add(new NmsMapping("1.21.4", "v1_21_R3")); From b5418c38e45532882a716d2dfbcba720ca67bb01 Mon Sep 17 00:00:00 2001 From: Nils Gereke Date: Tue, 7 Oct 2025 23:31:00 +0200 Subject: [PATCH 5/5] fix: gameprofile properties --- .../net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java index c7c88be..be7f15f 100644 --- a/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java +++ b/zip-nms/zip-nms-v1_21_R6/src/main/java/net/imprex/zip/nms/v1_21_R6/ZipNmsManager.java @@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.UUID; import java.util.function.BiConsumer; @@ -14,11 +15,13 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; +import com.google.common.collect.Multimaps; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; import com.mojang.serialization.DataResult; import com.mojang.serialization.Dynamic; import com.mojang.serialization.DynamicOps; @@ -192,8 +195,11 @@ public JsonObject migrateToJsonElement(byte[] binary) { @Override public void setSkullProfile(SkullMeta meta, String texture) { try { - GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ""); - gameProfile.properties().put("textures", new Property("textures", texture)); + HashMap properties = new HashMap<>(); + properties.put("textures", new Property("textures", texture)); + + PropertyMap propertyMap = new PropertyMap(Multimaps.forMap(properties)); + GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "", propertyMap); SET_PROFILE.accept(meta, gameProfile); } catch (Exception e) {