From 858cf87a197160434fb9aa5d7b6b5ee70cc06f14 Mon Sep 17 00:00:00 2001 From: BingZi-233 Date: Wed, 3 Jul 2024 12:28:18 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=99=9A=E6=8B=9F=E7=89=A9=E5=93=81?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=BB=E8=BE=91=E6=9B=B4=E6=96=B0(?= =?UTF-8?q?=E6=9C=AA=E5=AE=9E=E8=A3=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../video/internal/helper/ImageHelper.kt | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6255555..4bbde25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=online.bingzi.bilibili.video -version=1.6.2 +version=1.6.3-bate1 kotlin.experimental.tryK2=true kapt.use.k2=true kotlin.incremental=true diff --git a/src/main/kotlin/online/bingzi/bilibili/video/internal/helper/ImageHelper.kt b/src/main/kotlin/online/bingzi/bilibili/video/internal/helper/ImageHelper.kt index 3c63924..8251bd6 100644 --- a/src/main/kotlin/online/bingzi/bilibili/video/internal/helper/ImageHelper.kt +++ b/src/main/kotlin/online/bingzi/bilibili/video/internal/helper/ImageHelper.kt @@ -1,10 +1,15 @@ package online.bingzi.bilibili.video.internal.helper +import com.comphenix.protocol.PacketType +import com.comphenix.protocol.ProtocolLibrary import com.google.zxing.BarcodeFormat import com.google.zxing.qrcode.QRCodeWriter +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack import java.awt.Color import java.awt.image.BufferedImage + /** * To buffered image * 将URL转换为BufferedImage @@ -30,3 +35,29 @@ fun String.toBufferedImage(size: Int): BufferedImage { graphics.dispose() return image } + +/** + * Send virtual item + * 发送虚拟物品给调用玩家 + * + * @param itemStack + * @param slot + */ +fun Player.sendVirtualItem(itemStack: ItemStack, slot: Int) { + // 创建一个装载物品数据的包 + val packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SET_SLOT) + + // 设置包中的数据 + packet.integers.write(0, 0) // 窗口ID,0表示主背包 + packet.integers.write(1, slot) // 插槽ID,指定要放置物品的插槽编号 + + // 将物品堆栈放入包中 + packet.itemModifier.write(0, itemStack) + + try { + // 发送包给指定的玩家 + ProtocolLibrary.getProtocolManager().sendServerPacket(this, packet) + } catch (e: Exception) { + e.printStackTrace() + } +}