From 8019ec4ba18d85973063593c5a5875156bad71f5 Mon Sep 17 00:00:00 2001 From: Hamza Ali Date: Tue, 10 Mar 2020 21:15:08 +0700 Subject: [PATCH] Fixed the bug of the misname from the default config file. Initially, the configuration section was named startGUI, which was not in the essense of what is was actually doing, and was named to shopGUI. Furthermore, the main shop is set up to perform the command that is listed in the configuration file. The configuration file still does not handle loading up other shops yet. --- compile.sh | 5 +++++ .../pw.hamzantal.shopreborn/ClickListeners.kt | 15 +++++++++------ .../pw.hamzantal.shopreborn/Configuration.kt | 19 ++++++++++--------- src/main/resources/config.yml | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 compile.sh diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..fa081f9 --- /dev/null +++ b/compile.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +./gradlew shadowJar + +mv build/libs/ShopReborn-1.0-SNAPSHOT.jar ~/Desktop/CodeRelated/server/plugins/ \ No newline at end of file diff --git a/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt b/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt index e7c4efd..5fb3864 100644 --- a/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt +++ b/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt @@ -1,6 +1,6 @@ package pw.hamzantal.shopreborn -import hazae41.minecraft.kutils.bukkit.msg +import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent fun baseListener(e: InventoryClickEvent) { @@ -8,14 +8,17 @@ fun baseListener(e: InventoryClickEvent) { mainClick(e) return } - - } fun mainClick(e: InventoryClickEvent) { - val main = Configurations.main - e.isCancelled = true; + e.isCancelled = true if (e.rawSlot > e.inventory.size) return - e.whoClicked.msg(e.rawSlot.toString()) + val main = Configurations.main + val p = e.whoClicked as Player + + val block = main.blocks.firstOrNull { it.slot == e.slot } ?: return + block.commands.forEach { + p.performCommand(it) + } } \ No newline at end of file diff --git a/src/main/kotlin/pw.hamzantal.shopreborn/Configuration.kt b/src/main/kotlin/pw.hamzantal.shopreborn/Configuration.kt index 568a98b..114f167 100644 --- a/src/main/kotlin/pw.hamzantal.shopreborn/Configuration.kt +++ b/src/main/kotlin/pw.hamzantal.shopreborn/Configuration.kt @@ -5,6 +5,7 @@ import hazae41.minecraft.kutils.bukkit.keys import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.configuration.ConfigurationSection +import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack import java.io.File @@ -18,35 +19,35 @@ class MainConfig(file: File) : ConfigFile(file) { var shops by section("shops") - var size by int("startGUI.size") - var title by string("startGUI.title") + var size by int("shopGUI.size") + var title by string("shopGUI.title") var blocksRaw by section("shopGUI.blocks") val blocks = blocksRaw?.keys ?.map { blocksRaw!!.getConfigurationSection(it) } ?.map { Block( - it.asItem(), + it.getConfigurationSection("item").asItem(), it.getInt("slot"), it.getStringList("commands") ) } ?: listOf() - val inventory by lazy { - val inv = Bukkit.createInventory(null, size, title.c) + val inventory: Inventory = Bukkit.createInventory(null, size, title.c).apply { blocks.forEach { - inv.setItem(it.slot, it.item) + println(it) + setItem(it.slot, it.item) } - inv } } fun ConfigurationSection.asItem(): ItemStack { val material = Material.valueOf(getString("material").toUpperCase()) val item = ItemStack(material, getInt("quantity", 1), getInt("data", 0).toShort()) - item.itemMeta.apply { - displayName = getString("name", "") + + item.itemMeta = item.itemMeta.apply { + displayName = getString("name", "").c lore = getStringList("lore").map { it.c } } return item diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e7dd47a..5e65eae 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,7 +2,7 @@ shops: blocks: "blocks.yml" -startGUI: +shopGUI: size: 18 title: "&2Select a shop" blocks: