From 516a5c45335dde114fba04e6ada1ba87baf67bbf Mon Sep 17 00:00:00 2001 From: Vincent Roquelaure Date: Fri, 1 Dec 2023 02:10:04 +0100 Subject: [PATCH 1/2] Added support 1.20.2 --- build.gradle.kts | 2 +- common/build.gradle.kts | 1 + .../customcraft/nms/NmsLoader.java | 1 + nms/v1_20_R2/build.gradle.kts | 9 ++++ .../nms/ItemStackSerializer_1_20_R2.java | 53 +++++++++++++++++++ settings.gradle.kts | 3 +- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 nms/v1_20_R2/build.gradle.kts create mode 100644 nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java diff --git a/build.gradle.kts b/build.gradle.kts index c5aaa1b..54f006c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "fr.fabienhebuterne.customcraft" - version = "1.5.0" + version = "1.5.1" apply(plugin = "base") apply(plugin = "java") diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 62663b7..42c27eb 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { implementation(project(":nms:v1_19_R2")) implementation(project(":nms:v1_19_R3")) implementation(project(":nms:v1_20_R1")) + implementation(project(":nms:v1_20_R2")) } tasks.withType { diff --git a/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java b/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java index a41f55e..8abe138 100644 --- a/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java +++ b/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java @@ -22,6 +22,7 @@ public static ItemStackSerializer loadNms(Plugin plugin) { case "v1_19_R2" -> new ItemStackSerializer_1_19_R2(); case "v1_19_R3" -> new ItemStackSerializer_1_19_R3(); case "v1_20_R1" -> new ItemStackSerializer_1_20_R1(); + case "v1_20_R2" -> new ItemStackSerializer_1_20_R2(); default -> { Bukkit.getLogger().severe("Your server version isn't compatible with CustomCraft"); if (plugin != null) { diff --git a/nms/v1_20_R2/build.gradle.kts b/nms/v1_20_R2/build.gradle.kts new file mode 100644 index 0000000..fed726e --- /dev/null +++ b/nms/v1_20_R2/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("java") +} + +dependencies { + implementation(project(":nms:interfaces")) + compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") + compileOnly(files("../../libs/spigot-1.20.1-R0.1-SNAPSHOT.jar")) +} \ No newline at end of file diff --git a/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java b/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java new file mode 100644 index 0000000..aef7305 --- /dev/null +++ b/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java @@ -0,0 +1,53 @@ +package fr.fabienhebuterne.customcraft.nms; + +import com.google.common.io.BaseEncoding; +import net.minecraft.nbt.NBTCompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class ItemStackSerializer_1_20_R2 implements ItemStackSerializer { + @Override + public String serializeItemStack(ItemStack itemStack) { + if (itemStack == null) { + return "null"; + } + + ByteArrayOutputStream outputStream = null; + + try { + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + net.minecraft.world.item.ItemStack itemStackNms = CraftItemStack.asNMSCopy(itemStack); + NBTTagCompound nbtToSave = itemStackNms.b(nbtTagCompound); + outputStream = new ByteArrayOutputStream(); + NBTCompressedStreamTools.a(nbtToSave, outputStream); + } catch (IOException e) { + e.printStackTrace(); + } + + return BaseEncoding.base64().encode(outputStream.toByteArray()); + } + + @Override + public ItemStack deserializeItemStack(String itemStack) { + if (itemStack.equals("null")) { + return null; + } + + ByteArrayInputStream inputStream = new ByteArrayInputStream(BaseEncoding.base64().decode(itemStack)); + + try { + NBTTagCompound tagCompound = NBTCompressedStreamTools.a(inputStream); + net.minecraft.world.item.ItemStack itemStackNms = net.minecraft.world.item.ItemStack.a(tagCompound); + return CraftItemStack.asBukkitCopy(itemStackNms); + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 6f3a294..58f4722 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -6,5 +6,6 @@ include( "nms:v1_19_R1", "nms:v1_19_R2", "nms:v1_19_R3", - "nms:v1_20_R1" + "nms:v1_20_R1", + "nms:v1_20_R2" ) \ No newline at end of file From 6b15cd8a7ec521b42968ad2b2d6d16ad87546d62 Mon Sep 17 00:00:00 2001 From: Vincent Roquelaure Date: Fri, 1 Dec 2023 02:11:58 +0100 Subject: [PATCH 2/2] Use correct version... --- nms/v1_20_R2/build.gradle.kts | 4 ++-- .../customcraft/nms/ItemStackSerializer_1_20_R2.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nms/v1_20_R2/build.gradle.kts b/nms/v1_20_R2/build.gradle.kts index fed726e..74e0c55 100644 --- a/nms/v1_20_R2/build.gradle.kts +++ b/nms/v1_20_R2/build.gradle.kts @@ -4,6 +4,6 @@ plugins { dependencies { implementation(project(":nms:interfaces")) - compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT") - compileOnly(files("../../libs/spigot-1.20.1-R0.1-SNAPSHOT.jar")) + compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") + compileOnly(files("../../libs/spigot-1.20.2-R0.1-SNAPSHOT.jar")) } \ No newline at end of file diff --git a/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java b/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java index aef7305..340a415 100644 --- a/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java +++ b/nms/v1_20_R2/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R2.java @@ -3,7 +3,7 @@ import com.google.common.io.BaseEncoding; import net.minecraft.nbt.NBTCompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; +import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; import org.bukkit.inventory.ItemStack; import java.io.ByteArrayInputStream;