commit f2a5f9dc6f9ac77526920ab91b74a257e9c0224c Author: Hamza ALI Date: Tue Mar 10 20:18:38 2020 +0700 Initial commit with basic config file implementation and /shop diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5eee92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.gradle/ +.idea/ +gradle/ +gradlew +gradlew.bat +build/ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..e11b49a --- /dev/null +++ b/build.gradle @@ -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" +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..29e08e8 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +kotlin.code.style=official \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c773ccc --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'ShopReborn' + diff --git a/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt b/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt new file mode 100644 index 0000000..e7c4efd --- /dev/null +++ b/src/main/kotlin/pw.hamzantal.shopreborn/ClickListeners.kt @@ -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()) +} \ 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 new file mode 100644 index 0000000..568a98b --- /dev/null +++ b/src/main/kotlin/pw.hamzantal.shopreborn/Configuration.kt @@ -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() +} + +class MainConfig(file: File) : ConfigFile(file) { + data class Block(val item: ItemStack, val slot: Int, val commands: List) + + 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 +} \ No newline at end of file diff --git a/src/main/kotlin/pw.hamzantal.shopreborn/ShopReborn.kt b/src/main/kotlin/pw.hamzantal.shopreborn/ShopReborn.kt new file mode 100644 index 0000000..3c909c4 --- /dev/null +++ b/src/main/kotlin/pw.hamzantal.shopreborn/ShopReborn.kt @@ -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(callback = ::baseListener) + + command("shop") { sender, args -> + if (sender !is Player) return@command + + if (args.isEmpty()) + sender.openInventory(Configurations.main.inventory) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/pw.hamzantal.shopreborn/Util.kt b/src/main/kotlin/pw.hamzantal.shopreborn/Util.kt new file mode 100644 index 0000000..5ea1d6d --- /dev/null +++ b/src/main/kotlin/pw.hamzantal.shopreborn/Util.kt @@ -0,0 +1,6 @@ +package pw.hamzantal.shopreborn + +import org.bukkit.ChatColor + +val String.c + get() = ChatColor.translateAlternateColorCodes('&', this) \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..e7dd47a --- /dev/null +++ b/src/main/resources/config.yml @@ -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" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..bc58769 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -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" \ No newline at end of file