Initial commit with basic config file implementation and /shop

master
ALI Hamza 2020-03-10 20:18:38 +07:00
commit f2a5f9dc6f
10 changed files with 170 additions and 0 deletions

6
.gitignore vendored

@ -0,0 +1,6 @@
.gradle/
.idea/
gradle/
gradlew
gradlew.bat
build/

@ -0,0 +1,31 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'com.github.johnrengelman.shadow' version '4.0.4'
}
group 'pw.hamzantal'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
jcenter()
maven { url "https://hub.spigotmc.org/nexus/content/groups/public" }
maven { url "https://jitpack.io" }
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "com.github.hazae41:mc-kutils:master-SNAPSHOT"
compileOnly "org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT"
}
shadowJar {
baseName = "ShopReborn"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

@ -0,0 +1 @@
kotlin.code.style=official

@ -0,0 +1,2 @@
rootProject.name = 'ShopReborn'

@ -0,0 +1,21 @@
package pw.hamzantal.shopreborn
import hazae41.minecraft.kutils.bukkit.msg
import org.bukkit.event.inventory.InventoryClickEvent
fun baseListener(e: InventoryClickEvent) {
if (e.inventory == Configurations.main.inventory) {
mainClick(e)
return
}
}
fun mainClick(e: InventoryClickEvent) {
val main = Configurations.main
e.isCancelled = true;
if (e.rawSlot > e.inventory.size) return
e.whoClicked.msg(e.rawSlot.toString())
}

@ -0,0 +1,53 @@
package pw.hamzantal.shopreborn
import hazae41.minecraft.kutils.bukkit.ConfigFile
import hazae41.minecraft.kutils.bukkit.keys
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.ItemStack
import java.io.File
object Configurations {
lateinit var main: MainConfig
val shops = mutableListOf<ConfigFile>()
}
class MainConfig(file: File) : ConfigFile(file) {
data class Block(val item: ItemStack, val slot: Int, val commands: List<String>)
var shops by section("shops")
var size by int("startGUI.size")
var title by string("startGUI.title")
var blocksRaw by section("shopGUI.blocks")
val blocks = blocksRaw?.keys
?.map { blocksRaw!!.getConfigurationSection(it) }
?.map {
Block(
it.asItem(),
it.getInt("slot"),
it.getStringList("commands")
)
}
?: listOf()
val inventory by lazy {
val inv = Bukkit.createInventory(null, size, title.c)
blocks.forEach {
inv.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", "")
lore = getStringList("lore").map { it.c }
}
return item
}

@ -0,0 +1,26 @@
package pw.hamzantal.shopreborn
import hazae41.minecraft.kutils.bukkit.command
import hazae41.minecraft.kutils.bukkit.listen
import hazae41.minecraft.kutils.get
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.plugin.java.JavaPlugin
class ShopReborn : JavaPlugin() {
override fun onEnable() {
saveDefaultConfig()
Configurations.main =
MainConfig(dataFolder["config.yml"])
listen<InventoryClickEvent>(callback = ::baseListener)
command("shop") { sender, args ->
if (sender !is Player) return@command
if (args.isEmpty())
sender.openInventory(Configurations.main.inventory)
}
}
}

@ -0,0 +1,6 @@
package pw.hamzantal.shopreborn
import org.bukkit.ChatColor
val String.c
get() = ChatColor.translateAlternateColorCodes('&', this)

@ -0,0 +1,16 @@
shops:
blocks: "blocks.yml"
startGUI:
size: 18
title: "&2Select a shop"
blocks:
1:
slot: 0
commands:
- "shop blocks"
item:
material: GRASS
amount: 1 # Default can leave blank if 1
name: "&cBlocks"

@ -0,0 +1,8 @@
name: ShopReborn
version: 1.0.0
description: Custom Shop GUI Plugin created for Premiere Setups
author: hhhapz
main: pw.hamzantal.shopreborn.ShopReborn
commands:
shop:
description: "Shop GUI Basic command"