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.
master
ALI Hamza 2020-03-10 21:15:08 +07:00
parent f2a5f9dc6f
commit 8019ec4ba1
No known key found for this signature in database
GPG Key ID: BCA8A46C87798C4C
4 changed files with 25 additions and 16 deletions

@ -0,0 +1,5 @@
#!/usr/bin/env bash
./gradlew shadowJar
mv build/libs/ShopReborn-1.0-SNAPSHOT.jar ~/Desktop/CodeRelated/server/plugins/

@ -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)
}
}

@ -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

@ -2,7 +2,7 @@ shops:
blocks: "blocks.yml"
startGUI:
shopGUI:
size: 18
title: "&2Select a shop"
blocks: