diff --git a/clients/js/package.json b/clients/js/package.json index cecb151..bc01a8e 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -1,6 +1,6 @@ { "name": "elytra", - "version": "1.5.2", + "version": "1.6.0", "main": "dist/index.js", "types": "dist/index.d.ts", "author": "Tristan Camejo ", diff --git a/clients/js/src/schemas/ItemStack.ts b/clients/js/src/schemas/ItemStack.ts index 21807b5..50cc321 100644 --- a/clients/js/src/schemas/ItemStack.ts +++ b/clients/js/src/schemas/ItemStack.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const ItemStackSchema = z.object({ +const ItemStackNOTShulkerBoxSchema = z.object({ name: z.string().nullable(), id: z.string(), type: z.union([z.literal("item"), z.literal("block")]), @@ -8,4 +8,16 @@ export const ItemStackSchema = z.object({ durability: z.number(), enchantments: z.record(z.number()), b64: z.string(), + lore: z.array(z.string()), +}); + +export const ItemStackSchema = ItemStackNOTShulkerBoxSchema.extend({ + itemsInside: z.array( + z.union([ + ItemStackNOTShulkerBoxSchema.extend({ + itemsInside: z.array(z.null()), + }), + z.null(), + ]) + ), }); diff --git a/clients/js/src/structs/ItemStack.ts b/clients/js/src/structs/ItemStack.ts index 57ae432..0b0280e 100644 --- a/clients/js/src/structs/ItemStack.ts +++ b/clients/js/src/structs/ItemStack.ts @@ -34,6 +34,21 @@ export class ItemStack extends Base { return this.data.enchantments; } + public get lore() { + return this.data.lore; + } + + public get itemsInside(): (ItemStack | null)[] { + return this.data.itemsInside.map((i) => + i === null + ? null + : new ItemStack(this.client, { + ...i, + itemsInside: [], + }) + ); + } + /** * Serialized data of the item encoded in base64 */ diff --git a/src/main/java/com/tristansmp/elytra/routes/Player.kt b/src/main/java/com/tristansmp/elytra/routes/Player.kt index b76426b..be4f14c 100644 --- a/src/main/java/com/tristansmp/elytra/routes/Player.kt +++ b/src/main/java/com/tristansmp/elytra/routes/Player.kt @@ -9,11 +9,16 @@ import io.ktor.server.application.ApplicationCallPipeline.ApplicationPhase.Plugi import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.block.ShulkerBox import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.BlockStateMeta import java.util.* + data class InventoryPOST( val b64: String ) @@ -56,6 +61,23 @@ fun Player.toJson(): Map { } fun ItemStack.toJson(): Map { + + var itemLore: List = listOf() + + if (itemMeta.hasLore()) { + itemLore = itemMeta.lore()!!.map { + LegacyComponentSerializer.legacyAmpersand().serialize(it) + } + } + + var itemsInside = listOf?>() + + if (type == Material.SHULKER_BOX) { + val box = (itemMeta as BlockStateMeta).blockState as ShulkerBox + + itemsInside = box.inventory.contents.map { it?.toJson() } + } + return mapOf( "name" to itemMeta.getName(), "id" to type.name, @@ -64,6 +86,8 @@ fun ItemStack.toJson(): Map { "durability" to durability, "enchantments" to enchantments.map { it.key.name to it.value }.toMap(), "b64" to SerializeUtils.itemStackToBase64(this), + "lore" to itemLore, + "itemsInside" to itemsInside ) } @@ -76,7 +100,7 @@ fun Route.Player() { call.respond(player!!.toJson()) } - get() { + get { call.respond(Bukkit.getOnlinePlayers().map { it.toJson() }) }