diff --git a/build.gradle.kts b/build.gradle.kts index d7ba2d1..c5aaa1b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { group = "fr.fabienhebuterne.customcraft" - version = "1.4.0" + version = "1.5.0" apply(plugin = "base") apply(plugin = "java") diff --git a/common/build.gradle.kts b/common/build.gradle.kts index a494090..62663b7 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { implementation(project(":nms:v1_19_R1")) implementation(project(":nms:v1_19_R2")) implementation(project(":nms:v1_19_R3")) + implementation(project(":nms:v1_20_R1")) } 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 f338152..a41f55e 100644 --- a/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java +++ b/common/src/main/java/fr/fabienhebuterne/customcraft/nms/NmsLoader.java @@ -21,6 +21,7 @@ public static ItemStackSerializer loadNms(Plugin plugin) { case "v1_19_R1" -> new ItemStackSerializer_1_19_R1(); 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(); default -> { Bukkit.getLogger().severe("Your server version isn't compatible with CustomCraft"); if (plugin != null) { diff --git a/nms/v1_20_R1/build.gradle.kts b/nms/v1_20_R1/build.gradle.kts new file mode 100644 index 0000000..fed726e --- /dev/null +++ b/nms/v1_20_R1/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_R1/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R1.java b/nms/v1_20_R1/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R1.java new file mode 100644 index 0000000..2f5f8ec --- /dev/null +++ b/nms/v1_20_R1/src/main/java/fr/fabienhebuterne/customcraft/nms/ItemStackSerializer_1_20_R1.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_R1 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 0106f5f..6f3a294 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,5 +5,6 @@ include( "nms:v1_18_R2", "nms:v1_19_R1", "nms:v1_19_R2", - "nms:v1_19_R3" + "nms:v1_19_R3", + "nms:v1_20_R1" ) \ No newline at end of file