From d726902616251bbc3dce58fb3cf039d8897d4285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 14 Jun 2023 01:25:49 +0800 Subject: [PATCH] [6.0.11][publish] Experimental > update ItemTag & fix bug --- .../java/taboolib/module/nms/ItemTagData.java | 5 ++++ .../taboolib/module/nms/NMSGenericImpl.java | 2 +- .../kotlin/taboolib/module/nms/ItemTag.kt | 27 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 module/module-nms-util/src/main/kotlin/taboolib/module/nms/ItemTag.kt diff --git a/module/module-nms-util/src/main/java/taboolib/module/nms/ItemTagData.java b/module/module-nms-util/src/main/java/taboolib/module/nms/ItemTagData.java index 039d56b3a..d927ef6f0 100755 --- a/module/module-nms-util/src/main/java/taboolib/module/nms/ItemTagData.java +++ b/module/module-nms-util/src/main/java/taboolib/module/nms/ItemTagData.java @@ -80,6 +80,11 @@ public ItemTagData(ItemTagList data) { this.data = data; } + public ItemTagData(ItemTagType type, Object data) { + this.type = type; + this.data = data; + } + public String toJsonSimplified() { return toJsonSimplified(0); } diff --git a/module/module-nms-util/src/main/java/taboolib/module/nms/NMSGenericImpl.java b/module/module-nms-util/src/main/java/taboolib/module/nms/NMSGenericImpl.java index 7f7ada9ad..0214d8e34 100644 --- a/module/module-nms-util/src/main/java/taboolib/module/nms/NMSGenericImpl.java +++ b/module/module-nms-util/src/main/java/taboolib/module/nms/NMSGenericImpl.java @@ -94,7 +94,7 @@ public NMSGenericImpl() { ); packetPlayOutSignEditorConstructor = net.minecraft.server.v1_16_R1.PacketPlayOutOpenSignEditor.class.getDeclaredConstructor( net.minecraft.server.v1_16_R1.BlockPosition.class, - Boolean.class + Boolean.TYPE ); } else { packetPlayOutLightUpdateConstructor = net.minecraft.server.v1_16_R1.PacketPlayOutLightUpdate.class.getDeclaredConstructor( diff --git a/module/module-nms-util/src/main/kotlin/taboolib/module/nms/ItemTag.kt b/module/module-nms-util/src/main/kotlin/taboolib/module/nms/ItemTag.kt new file mode 100644 index 000000000..c15a235b5 --- /dev/null +++ b/module/module-nms-util/src/main/kotlin/taboolib/module/nms/ItemTag.kt @@ -0,0 +1,27 @@ +package taboolib.module.nms + +fun ItemTagData.clone(): ItemTagData { + return when (type) { + ItemTagType.END -> ItemTagData(type, null) + ItemTagType.BYTE, + ItemTagType.SHORT, + ItemTagType.INT, + ItemTagType.LONG, + ItemTagType.FLOAT, + ItemTagType.DOUBLE, + ItemTagType.STRING -> ItemTagData(type, unsafeData()) + ItemTagType.BYTE_ARRAY -> ItemTagData(type, asByteArray().copyOf()) + ItemTagType.INT_ARRAY -> ItemTagData(type, asIntArray().copyOf()) + ItemTagType.LIST -> { + val list = ItemTagList() + asList().forEach { list.add(it.clone()) } + list + } + ItemTagType.COMPOUND -> { + val compound = ItemTag() + asCompound().forEach { (k, v) -> compound[k] = v.clone() } + compound + } + else -> error("unsupported tag type") + } +} \ No newline at end of file