From ac12659e845de2cb39df0b9023a834fc8da0ecc3 Mon Sep 17 00:00:00 2001 From: Tech <49742865+DebitCardz@users.noreply.github.com> Date: Sat, 25 Nov 2023 12:42:54 -0500 Subject: [PATCH] refactor: switch package locations (#19) --- README.md | 4 +- build.gradle.kts | 2 +- src/main/kotlin/me/tech/mcchestui/GUI.kt | 6 +++ .../mcchestui/{ => listeners}/GUIListener.kt | 3 +- .../mcchestui/{ => template}/GUITemplate.kt | 47 +++++++++++-------- .../tech/mcchestui/{ => utils}/GUIHelper.kt | 5 +- 6 files changed, 42 insertions(+), 25 deletions(-) rename src/main/kotlin/me/tech/mcchestui/{ => listeners}/GUIListener.kt (99%) rename src/main/kotlin/me/tech/mcchestui/{ => template}/GUITemplate.kt (64%) rename src/main/kotlin/me/tech/mcchestui/{ => utils}/GUIHelper.kt (94%) diff --git a/README.md b/README.md index 0d50e5f..0be3dad 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation("com.github.DebitCardz:mc-chestui-plus:1.2.0") + implementation("com.github.DebitCardz:mc-chestui-plus:1.3.0") } ``` ### Maven @@ -34,7 +34,7 @@ dependencies { com.github.DebitCardz mc-chestui-plus - 1.2.0 + 1.3.0 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 9cdf834..0ac1aad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ val githubActor = project.findProperty("gpr.user") as String? ?: System.getenv(" val githubToken = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") group = "me.tech" -version = "1.2.0" +version = "1.3.0" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/GUI.kt b/src/main/kotlin/me/tech/mcchestui/GUI.kt index fe46337..ed5c06a 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUI.kt +++ b/src/main/kotlin/me/tech/mcchestui/GUI.kt @@ -7,6 +7,12 @@ package me.tech.mcchestui +import me.tech.mcchestui.listeners.GUIListener +import me.tech.mcchestui.utils.GUICloseEvent +import me.tech.mcchestui.utils.GUIDragItemEvent +import me.tech.mcchestui.utils.GUIItemPickupEvent +import me.tech.mcchestui.utils.GUIItemPlaceEvent +import me.tech.mcchestui.utils.GUISlotClickEvent import net.kyori.adventure.text.Component import org.bukkit.entity.Player import org.bukkit.event.* diff --git a/src/main/kotlin/me/tech/mcchestui/GUIListener.kt b/src/main/kotlin/me/tech/mcchestui/listeners/GUIListener.kt similarity index 99% rename from src/main/kotlin/me/tech/mcchestui/GUIListener.kt rename to src/main/kotlin/me/tech/mcchestui/listeners/GUIListener.kt index a2ec50f..a19840e 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUIListener.kt +++ b/src/main/kotlin/me/tech/mcchestui/listeners/GUIListener.kt @@ -1,5 +1,6 @@ -package me.tech.mcchestui +package me.tech.mcchestui.listeners +import me.tech.mcchestui.GUI import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.Cancellable diff --git a/src/main/kotlin/me/tech/mcchestui/GUITemplate.kt b/src/main/kotlin/me/tech/mcchestui/template/GUITemplate.kt similarity index 64% rename from src/main/kotlin/me/tech/mcchestui/GUITemplate.kt rename to src/main/kotlin/me/tech/mcchestui/template/GUITemplate.kt index 0d43f3b..ba8475f 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUITemplate.kt +++ b/src/main/kotlin/me/tech/mcchestui/template/GUITemplate.kt @@ -1,4 +1,7 @@ -package me.tech.mcchestui +package me.tech.mcchestui.template + +import me.tech.mcchestui.GUI +import me.tech.mcchestui.guiSlot /** * Representing the structure of the GUI Template. @@ -10,30 +13,36 @@ data class GUITemplate( var fourthRow: String? = null, var fifthRow: String? = null, var sixthRow: String? = null, + var rows: String? = null ) { - private val usingRows get() = rows != null - /** + * Converts [GUITemplate] into a [Map]. + * + * Will automatically override [rows] with each select row + * so both options work with each other, select rows will take priority over + * [rows] so it can override it. + * * @return list of characters mapped to the row. */ internal fun toMap(): Map> { - if(usingRows) { - return rows - ?.split("\n") - ?.withIndex() - ?.associate { it.index + 1 to toCharList(it.value) } - ?: emptyMap() - } else { - return mapOf( - 1 to toCharList(firstRow), - 2 to toCharList(secondRow), - 3 to toCharList(thirdRow), - 4 to toCharList(fourthRow), - 5 to toCharList(fifthRow), - 6 to toCharList(sixthRow) - ) - } + return rowsMap() + .toMutableMap() + .apply { putAll(selectRowsMap().filterValues { it.isNotEmpty() }) } + } + + private fun rowsMap(): Map> { + return rows + ?.split("\n") + ?.withIndex() + ?.associate { it.index + 1 to toCharList(it.value) } + ?: emptyMap() + } + + private fun selectRowsMap(): Map> { + return listOf(firstRow, secondRow, thirdRow, fourthRow, fifthRow, sixthRow) + .withIndex() + .associate { it.index + 1 to toCharList(it.value) } } /** diff --git a/src/main/kotlin/me/tech/mcchestui/GUIHelper.kt b/src/main/kotlin/me/tech/mcchestui/utils/GUIHelper.kt similarity index 94% rename from src/main/kotlin/me/tech/mcchestui/GUIHelper.kt rename to src/main/kotlin/me/tech/mcchestui/utils/GUIHelper.kt index a22971e..dc8aedf 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUIHelper.kt +++ b/src/main/kotlin/me/tech/mcchestui/utils/GUIHelper.kt @@ -1,5 +1,7 @@ -package me.tech.mcchestui +package me.tech.mcchestui.utils +import me.tech.mcchestui.GUI +import me.tech.mcchestui.GUIType import net.kyori.adventure.text.Component import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player @@ -15,7 +17,6 @@ import org.bukkit.plugin.java.JavaPlugin * @param plugin * @param title Title of the GUI * @param type Type of GUI to generate - * @param rows Amount of rows in the Chest GUI * @return [GUI] Object */ fun gui(