Added blocked item lore

This commit is contained in:
Auxilor
2022-05-29 11:54:59 +01:00
parent 7e36a2d043
commit ad60240e62
2 changed files with 69 additions and 54 deletions

View File

@@ -9,7 +9,10 @@ import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.gui.menu
import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.slot
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.builder.ItemStackBuilder
import com.willfp.eco.core.placeholder.PlayerPlaceholder
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
import com.willfp.eco.util.MenuUtils
import com.willfp.talismans.talismans.util.TalismanChecks
@@ -17,9 +20,11 @@ import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.util.UUID
import kotlin.math.ceil
import kotlin.math.min
object TalismanBag {
private lateinit var menu: Menu
private val menus = mutableMapOf<Int, Menu>()
private lateinit var key: PersistentDataKey<List<String>>
private val savedItems = mutableMapOf<UUID, List<ItemStack>>()
@@ -54,67 +59,77 @@ object TalismanBag {
emptyList()
).player()
val rows = plugin.configYml.getInt("bag.rows")
for (rows in 1..6) {
menus[rows] = menu(rows) {
for (row in 1..rows) {
for (column in 1..9) {
setSlot(row, column, slot({ player, _ ->
val bagSize = player.bagSize
menu = menu(rows) {
for (row in 1..rows) {
for (column in 1..9) {
setSlot(row, column, slot({ player, _ ->
val bagSize = player.bagSize
val inBag = player.profile.read(key).map { Items.lookup(it).item }
val index = MenuUtils.rowColumnToSlot(row, column)
val inBag = player.profile.read(key).map { Items.lookup(it).item }
val index = MenuUtils.rowColumnToSlot(row, column)
if (index >= bagSize) {
ItemStackBuilder(Items.lookup(plugin.configYml.getString("bag.blocked-item")))
.addLoreLines(plugin.configYml.getStrings("bag.blocked-item-lore"))
.build()
} else {
inBag.toList().getOrNull(index)?.clone() ?: ItemStack(Material.AIR)
}
}) {
setCaptive(true)
notCaptiveFor { MenuUtils.rowColumnToSlot(row, column) >= it.bagSize }
})
}
}
if (index >= bagSize) {
Items.lookup(plugin.configYml.getString("bag.blocked-item")).item
} else {
inBag.toList().getOrNull(index)?.clone() ?: ItemStack(Material.AIR)
}
}) {
setCaptive(true)
notCaptiveFor { MenuUtils.rowColumnToSlot(row, column) >= it.bagSize }
})
setTitle(plugin.configYml.getFormattedString("bag.title"))
onRender { player, menu ->
val items = menu.getCaptiveItems(player)
.filterNot { EmptyTestableItem().matches(it) }
val toWrite = items
.filter { TalismanChecks.getTalismanOnItem(it) != null }
savedItems[player.uniqueId] = toWrite.toList()
}
onClose { event, menu ->
val player = event.player as Player
val items = menu.getCaptiveItems(player)
.filterNot { EmptyTestableItem().matches(it) }
val toWrite = items
.filter { TalismanChecks.getTalismanOnItem(it) != null }
savedItems[player.uniqueId] = toWrite.toList()
player.profile.write(key, toWrite.map { Items.toLookupString(it) })
val toDrop = items.filter { TalismanChecks.getTalismanOnItem(it) == null }
DropQueue(player)
.setLocation(player.eyeLocation)
.forceTelekinesis()
.addItems(toDrop)
.push()
}
}
setTitle(plugin.configYml.getFormattedString("bag.title"))
onRender { player, menu ->
val items = menu.getCaptiveItems(player)
.filterNot { EmptyTestableItem().matches(it) }
val toWrite = items
.filter { TalismanChecks.getTalismanOnItem(it) != null }
savedItems[player.uniqueId] = toWrite.toList()
}
onClose { event, menu ->
val player = event.player as Player
val items = menu.getCaptiveItems(player)
.filterNot { EmptyTestableItem().matches(it) }
val toWrite = items
.filter { TalismanChecks.getTalismanOnItem(it) != null }
savedItems[player.uniqueId] = toWrite.toList()
player.profile.write(key, toWrite.map { Items.toLookupString(it) })
val toDrop = items.filter { TalismanChecks.getTalismanOnItem(it) == null }
DropQueue(player)
.setLocation(player.eyeLocation)
.forceTelekinesis()
.addItems(toDrop)
.push()
}
}
PlaceholderManager.registerPlaceholder(
PlayerPlaceholder(
plugin,
"bagsize"
) { it.bagSize.toString() }
)
}
fun open(player: Player) {
menu.open(player)
val bagRows = min(6, ceil(player.bagSize / 9.0).toInt())
menus[bagRows]!!.open(player)
}
fun getTalismans(player: Player): List<ItemStack> {

View File

@@ -15,8 +15,8 @@ offhand-only: false # If talismans or shulkers of talismans need to be in the of
bag:
title: "Talisman Bag"
rows: 4
blocked-item: black_stained_glass_pane name:"&cYour talisman bag is not big enough!"
blocked-item-lore: [ ]
cannot-afford:
in-actionbar: true