Skip to content

Commit

Permalink
feat : add 1.20 compatibility - 1.5.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
fhebuterne committed Sep 9, 2023
1 parent bdd6098 commit a834d58
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

allprojects {
group = "fr.fabienhebuterne.customcraft"
version = "1.4.0"
version = "1.5.0"

apply(plugin = "base")
apply(plugin = "java")
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Jar> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions nms/v1_20_R1/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit a834d58

Please sign in to comment.