Skip to content

Commit

Permalink
feat: Anvil Title BaseComponent 지원
Browse files Browse the repository at this point in the history
  • Loading branch information
cccgh5 committed Nov 11, 2023
1 parent 247ddec commit 0a9a796
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ package kr.hqservice.framework.nms.virtual.container

import kr.hqservice.framework.nms.virtual.VirtualMessage
import kr.hqservice.framework.nms.virtual.message.VirtualMessageImpl
import net.md_5.bungee.api.chat.BaseComponent
import net.md_5.bungee.chat.ComponentSerializer
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryType

class VirtualAnvilContainer(
private val player: Player,
private val title: String
) : VirtualContainer(player, title) {
private val title: BaseComponent
) : VirtualContainer(player, ComponentSerializer.toString(title)) {
override fun createVirtualMessage(): VirtualMessage? {
val container = containerService.wrap(player)

val containerType = VirtualContainerType.getType(InventoryType.ANVIL, 3) ?: return null
val virtualContainerType = containerType.getVirtualType(containersClass)

val constructor = packetClass.java.getConstructor(
Int::class.javaPrimitiveType,
containersClass.java,
Expand All @@ -23,7 +26,7 @@ class VirtualAnvilContainer(
constructor.newInstance(
container.getContainerId(),
virtualContainerType,
baseComponentService.wrap(title).getUnwrappedInstance()
baseComponentService.wrap(ComponentSerializer.toString(title)).getUnwrappedInstance()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import kr.hqservice.framework.nms.virtual.handler.impl.VirtualAnvilHandler
import kr.hqservice.framework.nms.virtual.registry.VirtualHandlerRegistry
import kr.hqservice.framework.nms.virtual.world.VirtualWorldBorder
import kr.hqservice.framework.nms.wrapper.NmsReflectionWrapper
import net.md_5.bungee.api.chat.BaseComponent
import net.md_5.bungee.api.chat.TextComponent
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.event.EventPriority
Expand Down Expand Up @@ -36,7 +38,7 @@ abstract class AbstractVirtualScope(
}

suspend fun anvil(
title: String = "",
title: BaseComponent = TextComponent(""),
anvilFactoryScope: VirtualAnvilContainerScope.() -> Unit
) {
viewers.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kr.hqservice.framework.nms.virtual.Virtual
import kr.hqservice.framework.nms.virtual.container.VirtualAnvilContainer
import kr.hqservice.framework.nms.virtual.container.VirtualContainer
import kr.hqservice.framework.nms.virtual.item.VirtualItem
import net.md_5.bungee.api.chat.BaseComponent
import net.md_5.bungee.chat.ComponentSerializer
import org.bukkit.Material
import org.bukkit.entity.Player
Expand All @@ -15,7 +16,7 @@ import java.util.*

class VirtualAnvilContainerScope(
private val receiver: Player,
title: String
title: BaseComponent
) : KoinComponent {
companion object {
private val defaultBaseItems: (Player) -> List<VirtualItem> = {
Expand Down Expand Up @@ -44,7 +45,7 @@ class VirtualAnvilContainerScope(
private var virtualResultSlotHandler: ((String) -> ItemStack)? = null
private var virtualConfirmHandler: ((String) -> Boolean)? = null
private var closeHandler: ((String) -> Unit)? = null
private var anvilPacket: VirtualContainer = VirtualAnvilContainer(receiver, ComponentSerializer.toString(title))
private var anvilPacket: VirtualContainer = VirtualAnvilContainer(receiver, title)

fun setBaseItem(itemStack: ItemStack?) {
baseItem = if (itemStack == null || itemStack.type.isAir) {
Expand Down

0 comments on commit 0a9a796

Please sign in to comment.