From 4f5784b1b49a82fca0183194d00ab3e9886ffc78 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 28 May 2022 16:06:07 +0100 Subject: [PATCH] Added Talisman Bag --- build.gradle | 2 +- .../com/willfp/talismans/bag/TalismanBag.kt | 60 +++++++++++++++++++ .../willfp/talismans/command/CommandBag.kt | 13 ++++ .../talismans/command/CommandTalismans.kt | 3 +- .../core-plugin/src/main/resources/plugin.yml | 8 +++ 5 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/bag/TalismanBag.kt create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandBag.kt diff --git a/build.gradle b/build.gradle index 8c5bd7c..7239296 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/bag/TalismanBag.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/bag/TalismanBag.kt new file mode 100644 index 0000000..a2b34af --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/bag/TalismanBag.kt @@ -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> + + @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) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandBag.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandBag.kt new file mode 100644 index 0000000..19919e4 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandBag.kt @@ -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) { + TalismanBag.open(sender as Player) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt index f541bcd..7e36a55 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/talismans/command/CommandTalismans.kt @@ -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) { @@ -16,4 +17,4 @@ class CommandTalismans(plugin: EcoPlugin) plugin.langYml.getMessage("invalid-command") ) } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 9b0f028..a8eaaff 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -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