Added Talisman Bag
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user