Added Talisman Bag

This commit is contained in:
Auxilor
2022-05-28 16:06:07 +01:00
parent 0162ef4d8a
commit 4f5784b1b4
5 changed files with 84 additions and 2 deletions

View File

@@ -61,7 +61,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:6.35.1'
compileOnly 'com.willfp:eco:6.36.0'
implementation 'com.willfp:libreforge:3.44.2'
compileOnly 'org.jetbrains:annotations:23.0.0'

View File

@@ -0,0 +1,60 @@
package com.willfp.talismans.bag
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.updating.ConfigUpdater
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import com.willfp.eco.core.data.profile
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.items.Items
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object TalismanBag {
private lateinit var menu: Menu
private lateinit var key: PersistentDataKey<List<String>>
@JvmStatic
@ConfigUpdater
fun update(plugin: EcoPlugin) {
key = PersistentDataKey(
plugin.namespacedKeyFactory.create("talisman_bag"),
PersistentDataKeyType.STRING_LIST,
emptyList()
)
menu = menu(6) {
for (row in 1..6) {
for (column in 1..9) {
setSlot(row, column,
slot { player, _ ->
val items = player.profile.read(key).map {
Items.lookup(it).item
}
val index = (row - 1) * 9 + column - 1
items.toList().getOrNull(index) ?: ItemStack(Material.AIR)
}
)
}
}
onClose { event, menu ->
val player = event.player as Player
val items = menu.getCaptiveItems(player).map {
Items.toLookupString(it)
}
player.profile.write(key, items)
}
}
}
fun open(player: Player) {
menu.open(player)
}
}

View File

@@ -0,0 +1,13 @@
package com.willfp.talismans.command
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.Subcommand
import com.willfp.talismans.bag.TalismanBag
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
class CommandBag(plugin: EcoPlugin) : Subcommand(plugin, "bag", "talismans.commands.bag", true) {
override fun onExecute(sender: CommandSender, args: List<String>) {
TalismanBag.open(sender as Player)
}
}

View File

@@ -9,6 +9,7 @@ class CommandTalismans(plugin: EcoPlugin)
init {
addSubcommand(CommandReload(plugin))
.addSubcommand(CommandGive(plugin))
.addSubcommand(CommandBag(plugin))
}
override fun onExecute(sender: CommandSender, args: List<String>) {
@@ -16,4 +17,4 @@ class CommandTalismans(plugin: EcoPlugin)
plugin.langYml.getMessage("invalid-command")
)
}
}
}

View File

@@ -19,6 +19,10 @@ commands:
talismans:
description: Parent command.
permission: talismans.command.talismans
aliases:
- talisman
- talis
- talismen
permissions:
talismans.*:
@@ -27,6 +31,7 @@ permissions:
children:
talismans.command.talismans: true
talismans.command.give: true
talismans.command.bag: true
talismans.command.reload: true
talismans.fromtable.*: true
@@ -36,6 +41,9 @@ permissions:
talismans.command.give:
description: Allows the use of /talismans give.
default: op
talismans.command.bag:
description: Allows the use of /talismans bag.
default: true
talismans.command.talismans:
description: Allows the use of /talismans
default: true