Skip to content

Commit

Permalink
update: 虚拟物品支持逻辑更新(未实装)
Browse files Browse the repository at this point in the history
  • Loading branch information
BingZi-233 committed Jul 3, 2024
1 parent 2c5065f commit 858cf87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
}

0 comments on commit 858cf87

Please sign in to comment.