Skip to content

Commit

Permalink
refactor: switch package locations (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
DebitCardz authored Nov 25, 2023
1 parent c6c9b0e commit ac12659
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +34,7 @@ dependencies {
<dependency>
<groupId>com.github.DebitCardz</groupId>
<artifactId>mc-chestui-plus</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>

```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/me/tech/mcchestui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Int, List<Char>> {
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<Int, List<Char>> {
return rows
?.split("\n")
?.withIndex()
?.associate { it.index + 1 to toCharList(it.value) }
?: emptyMap()
}

private fun selectRowsMap(): Map<Int, List<Char>> {
return listOf(firstRow, secondRow, thirdRow, fourthRow, fifthRow, sixthRow)
.withIndex()
.associate { it.index + 1 to toCharList(it.value) }
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down

0 comments on commit ac12659

Please sign in to comment.