@@ -0,0 +1,2343 @@
+package vg.civcraft.mc.civmodcore.serialization;%0A%0Aimport java.util.UUID;%0Aimport org.bukkit.Bukkit;%0Aimport org.bukkit.Location;%0Aimport org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;%0Aimport org.bukkit.inventory.ItemStack;%0A%0Apublic final class NBTHelper %7B%0A%0A%09// ------------------------------------------------------------%0A%09// Location%0A%09// ------------------------------------------------------------%0A%0A%09private static final String LOCATION_WORLD_KEY = %22world%22;%0A%09private static final String LOCATION_X_KEY = %22x%22;%0A%09private static final String LOCATION_Y_KEY = %22y%22;%0A%09private static final String LOCATION_Z_KEY = %22z%22;%0A%09private static final String LOCATION_YAW_KEY = %22yaw%22;%0A%09private static final String LOCATION_PITCH_KEY = %22pitch%22;%0A%0A%09public static Location locationFromNBT(final NBTCompound nbt) %7B%0A%09%09if (nbt == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09final UUID worldUUID = nbt.getUUID(LOCATION_WORLD_KEY);%0A%09%09return new Location(%0A%09%09%09%09worldUUID == null ? null : Bukkit.getWorld(worldUUID),%0A%09%09%09%09nbt.getDouble(LOCATION_X_KEY),%0A%09%09%09%09nbt.getDouble(LOCATION_Y_KEY),%0A%09%09%09%09nbt.getDouble(LOCATION_Z_KEY),%0A%09%09%09%09nbt.getFloat(LOCATION_YAW_KEY),%0A%09%09%09%09nbt.getFloat(LOCATION_PITCH_KEY));%0A%09%7D%0A%0A%09public static NBTCompound locationToNBT(final Location location) %7B%0A%09%09if (location == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09final var nbt = new NBTCompound();%0A%09%09nbt.setUUID(LOCATION_WORLD_KEY, location.isWorldLoaded() ? location.getWorld().getUID() : null);%0A%09%09nbt.setDouble(LOCATION_X_KEY, location.getX());%0A%09%09nbt.setDouble(LOCATION_Y_KEY, location.getY());%0A%09%09nbt.setDouble(LOCATION_Z_KEY, location.getZ());%0A%09%09if (location.getYaw() != 0) %7B%0A%09%09%09nbt.setFloat(LOCATION_YAW_KEY, location.getYaw());%0A%09%09%7D%0A%09%09if (location.getPitch() != 0) %7B%0A%09%09%09nbt.setFloat(LOCATION_PITCH_KEY, location.getPitch());%0A%09%09%7D%0A%09%09return nbt;%0A%09%7D%0A%0A%09// ------------------------------------------------------------%0A%09// ItemStack%0A%09// ------------------------------------------------------------%0A%0A%09public static ItemStack itemStackFromNBT(final NBTCompound nbt) %7B%0A%09%09if (nbt == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return net.minecraft.server.v1_16_R3.ItemStack.fromCompound(nbt.getRAW()).getBukkitStack();%0A%09%7D%0A%0A%09public static NBTCompound itemStackToNBT(final ItemStack item) %7B%0A%09%09if (item == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09final var nbt = new NBTCompound();%0A%09%09((CraftItemStack) item).getHandle().save(nbt.getRAW());%0A%09%09return nbt;%0A%09%7D%0A%0A%7D%0A

Add NBTHelper for common serialisations