From 04824cdbf2f78b03230f9224eafb086c64c10bf6 Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Wed, 7 Jul 2021 17:04:48 +0200 Subject: [PATCH 01/14] Add clarification about Brigardier dependency --- guide/docs/commands/brigardier.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guide/docs/commands/brigardier.md b/guide/docs/commands/brigardier.md index 32d8b406..9b9a65e6 100644 --- a/guide/docs/commands/brigardier.md +++ b/guide/docs/commands/brigardier.md @@ -1,5 +1,8 @@ # Brigardier support +???+ warning "Brigardier dependency" + Whilst spigot itself depends on [Brigardier](https://github.com/Mojang/brigadier#gradle) the Spigot API doesn't so in order for this feature to work you need to add Brigardier as an `compileOnly` dependency. More information on that can be found here: https://github.com/Mojang/brigadier#gradle + ## Create a command ```kotlin From fc0180fba6a99b29c9ad296f635e92a7b1d8d58b Mon Sep 17 00:00:00 2001 From: Jakob K <52456572+bluefireoly@users.noreply.github.com> Date: Mon, 12 Jul 2021 23:06:45 +0200 Subject: [PATCH 02/14] Clarify additional brigardier dependency --- guide/docs/commands/brigardier.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guide/docs/commands/brigardier.md b/guide/docs/commands/brigardier.md index 9b9a65e6..c5e8d9c1 100644 --- a/guide/docs/commands/brigardier.md +++ b/guide/docs/commands/brigardier.md @@ -1,7 +1,8 @@ # Brigardier support ???+ warning "Brigardier dependency" - Whilst spigot itself depends on [Brigardier](https://github.com/Mojang/brigadier#gradle) the Spigot API doesn't so in order for this feature to work you need to add Brigardier as an `compileOnly` dependency. More information on that can be found here: https://github.com/Mojang/brigadier#gradle + You do only have to do the following if you are using the `spigot-api` instead of the `spigot` dependency!
+ Whilst Spigot itself depends on [Brigardier](https://github.com/Mojang/brigadier#gradle) the Spigot API doesn't so in order for this feature to work you need to add Brigardier as an `compileOnly` dependency. More information on that can be found here: [https://github.com/Mojang/brigadier#gradle](https://github.com/Mojang/brigadier#gradle) ## Create a command From f9a5429e48f3049a9f5b0fd0ac8d3be0688cdc87 Mon Sep 17 00:00:00 2001 From: Jakob K <52456572+bluefireoly@users.noreply.github.com> Date: Tue, 13 Jul 2021 16:34:57 +0200 Subject: [PATCH 03/14] Update the Gradle example script --- guide/docs/setup/gradle_example.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guide/docs/setup/gradle_example.md b/guide/docs/setup/gradle_example.md index a7679a58..44df94dd 100644 --- a/guide/docs/setup/gradle_example.md +++ b/guide/docs/setup/gradle_example.md @@ -4,10 +4,10 @@ An example for a `build.gradle.kts` file of a project using KSpigot would be: import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.5.10" + kotlin("jvm") version "1.5.21" } -group = "net.axay" +group = "your.group" version = "1.0-SNAPSHOT" repositories { @@ -17,7 +17,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT") - implementation("net.axay:kspigot:1.17.1") + implementation("net.axay:kspigot:1.17.2") } tasks { From 9bb579e02c81671e0cbc7c03eb5388239f2ea873 Mon Sep 17 00:00:00 2001 From: Jakob K <52456572+bluefireoly@users.noreply.github.com> Date: Tue, 13 Jul 2021 16:36:37 +0200 Subject: [PATCH 04/14] Use the preferred task syntax --- guide/docs/setup/beginners/java_version.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/guide/docs/setup/beginners/java_version.md b/guide/docs/setup/beginners/java_version.md index e7083731..f7ea479f 100644 --- a/guide/docs/setup/beginners/java_version.md +++ b/guide/docs/setup/beginners/java_version.md @@ -9,11 +9,12 @@ You can configure the Java version using Gradle: ```kotlin // set the Java version you are using, Java 16 is the minimum required version for Minecraft -tasks.compileJava { - options.release.set(16) -} - -tasks.compileKotlin { - kotlinOptions.jvmTarget = "16" +tasks { + compileJava { + options.release.set(16) + } + compileKotlin { + kotlinOptions.jvmTarget = "16" + } } ``` From 3664ba2eb1235f9d0ab580c9d124b63279ccfaa0 Mon Sep 17 00:00:00 2001 From: Jakob K <52456572+bluefireoly@users.noreply.github.com> Date: Fri, 16 Jul 2021 16:49:18 +0200 Subject: [PATCH 05/14] Update brigardier.md --- guide/docs/commands/brigardier.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guide/docs/commands/brigardier.md b/guide/docs/commands/brigardier.md index c5e8d9c1..dfc0d193 100644 --- a/guide/docs/commands/brigardier.md +++ b/guide/docs/commands/brigardier.md @@ -1,8 +1,8 @@ # Brigardier support -???+ warning "Brigardier dependency" - You do only have to do the following if you are using the `spigot-api` instead of the `spigot` dependency!
- Whilst Spigot itself depends on [Brigardier](https://github.com/Mojang/brigadier#gradle) the Spigot API doesn't so in order for this feature to work you need to add Brigardier as an `compileOnly` dependency. More information on that can be found here: [https://github.com/Mojang/brigadier#gradle](https://github.com/Mojang/brigadier#gradle) +???+ warning "Brigardier dependency for spigot-api users" + (You do only have to do the following if you are using the `spigot-api` instead of the `spigot` dependency!)
+ Whilst Spigot itself depends on [Brigardier](https://github.com/Mojang/brigadier#gradle) the Spigot API doesn't so in order for this feature to work you need to add Brigardier as a `compileOnly` dependency. More information on that can be found here: [https://github.com/Mojang/brigadier#gradle](https://github.com/Mojang/brigadier#gradle) ## Create a command From 13a89944c8937ce140523decdfffbccb1b218fd3 Mon Sep 17 00:00:00 2001 From: l4zs Date: Sun, 8 Aug 2021 20:46:36 +0200 Subject: [PATCH 06/14] fix some shift clicks not calling GUIClickEvent --- src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt index b8a7d281..4f505e06 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt @@ -77,7 +77,7 @@ object GUIHolder : AutoCloseable { } private val InventoryAction.isGUIClick - get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF + get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE private val InventoryInteractEvent.playerOrCancel: Player? get() = (whoClicked as? Player) ?: kotlin.run { isCancelled = true From 4ea3d67643ab1a6a6f2385a7a3da09d25006f0cf Mon Sep 17 00:00:00 2001 From: l4zs Date: Sun, 8 Aug 2021 21:15:33 +0200 Subject: [PATCH 07/14] fix some shift clicks not calling GUIClickEvent --- src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt index 4f505e06..abd05d11 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt @@ -77,7 +77,7 @@ object GUIHolder : AutoCloseable { } private val InventoryAction.isGUIClick - get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE + get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE || this == InventoryAction.MOVE_TO_OTHER_INVENTORY private val InventoryInteractEvent.playerOrCancel: Player? get() = (whoClicked as? Player) ?: kotlin.run { isCancelled = true From 37235278a7694e4400f3ed3f3203d284e54c4b80 Mon Sep 17 00:00:00 2001 From: l4zs Date: Sun, 8 Aug 2021 21:16:27 +0200 Subject: [PATCH 08/14] fix some shift clicks not calling GUIClickEvent --- src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt index abd05d11..68694a65 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt @@ -77,7 +77,7 @@ object GUIHolder : AutoCloseable { } private val InventoryAction.isGUIClick - get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE || this == InventoryAction.MOVE_TO_OTHER_INVENTORY + get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.MOVE_TO_OTHER_INVENTORY private val InventoryInteractEvent.playerOrCancel: Player? get() = (whoClicked as? Player) ?: kotlin.run { isCancelled = true From d9b3d1d6e15459bf2ae4e8779634fc172478f191 Mon Sep 17 00:00:00 2001 From: l4zs Date: Sun, 8 Aug 2021 21:19:48 +0200 Subject: [PATCH 09/14] fix some shift clicks not calling GUIClickEvent --- src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt index 68694a65..abd05d11 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt @@ -77,7 +77,7 @@ object GUIHolder : AutoCloseable { } private val InventoryAction.isGUIClick - get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.MOVE_TO_OTHER_INVENTORY + get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE || this == InventoryAction.MOVE_TO_OTHER_INVENTORY private val InventoryInteractEvent.playerOrCancel: Player? get() = (whoClicked as? Player) ?: kotlin.run { isCancelled = true From b2c90d424f06b815358f444f6c164a21cdd0a8a7 Mon Sep 17 00:00:00 2001 From: l4zs Date: Sun, 8 Aug 2021 21:37:20 +0200 Subject: [PATCH 10/14] add new line after extension value --- src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt index abd05d11..54c722ee 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIHolder.kt @@ -78,6 +78,7 @@ object GUIHolder : AutoCloseable { private val InventoryAction.isGUIClick get() = this == InventoryAction.PICKUP_ALL || this == InventoryAction.PICKUP_HALF || this == InventoryAction.PICKUP_SOME || this == InventoryAction.PICKUP_ONE || this == InventoryAction.MOVE_TO_OTHER_INVENTORY + private val InventoryInteractEvent.playerOrCancel: Player? get() = (whoClicked as? Player) ?: kotlin.run { isCancelled = true From e4681af82239a6f8d349516f8c4362d818fab7fd Mon Sep 17 00:00:00 2001 From: Skyslycer Date: Mon, 16 Aug 2021 00:30:43 +0200 Subject: [PATCH 11/14] updated spigot and added on close function for closing a gui --- build.gradle.kts | 4 ++-- src/main/kotlin/net/axay/kspigot/gui/GUI.kt | 11 +++++++++-- src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt | 9 ++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5b0fd6a5..4b26a0c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,8 +24,8 @@ repositories { } dependencies { - compileOnly("org.spigotmc", "spigot", "1.17-R0.1-SNAPSHOT") - testCompileOnly("org.spigotmc", "spigot", "1.17-R0.1-SNAPSHOT") + compileOnly("org.spigotmc", "spigot", "1.17.1-R0.1-SNAPSHOT") + testCompileOnly("org.spigotmc", "spigot", "1.17.1-R0.1-SNAPSHOT") api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1") api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0") diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt index a2881441..a213fede 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt @@ -19,6 +19,7 @@ class GUIData( val transitionTo: InventoryChangeEffect?, val transitionFrom: InventoryChangeEffect?, internal val generalOnClick: ((GUIClickEvent) -> Unit)?, + internal val onClose: ((InventoryCloseEvent) -> Unit)? ) abstract class GUI( @@ -95,9 +96,15 @@ class GUIIndividual( } init { - if (resetOnClose) { + if (resetOnClose || data.onClose != null) { listen { - deleteInstance(it.player as? Player ?: return@listen) + if (data.onClose != null && playerInstances[it.player]?.bukkitInventory == it.inventory) { + data.onClose.invoke(it) + } + + if (resetOnClose) { + deleteInstance(it.player as? Player ?: return@listen) + } } } diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt index 6b6b3822..5ba7a8ee 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt @@ -3,6 +3,7 @@ package net.axay.kspigot.gui import net.axay.kspigot.gui.elements.* +import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.inventory.ItemStack import kotlin.math.absoluteValue @@ -46,6 +47,8 @@ class GUIBuilder( private var onClickElement: ((GUIClickEvent) -> Unit)? = null + private var onClose: ((InventoryCloseEvent) -> Unit)? = null + /** * Opens the builder for a new page and adds * the new page to the GUI. @@ -63,8 +66,12 @@ class GUIBuilder( onClickElement = onClick } + fun onClose(onClose: (InventoryCloseEvent) -> Unit) { + this.onClose = onClose + } + internal fun build() = guiCreator.createInstance( - GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement) + GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement, onClose) ) } From 71a6bd5ea834626d5409b73c8c964cb74afd1441 Mon Sep 17 00:00:00 2001 From: Skyslycer <73074974+Skyslycer@users.noreply.github.com> Date: Mon, 16 Aug 2021 00:34:33 +0200 Subject: [PATCH 12/14] Update docs link in readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7919d540..7634754e 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # KSpigot [ ![Latest version](https://img.shields.io/maven-central/v/net.axay/kspigot?color=pink&label=latest%20version&style=for-the-badge) ](https://repo1.maven.org/maven2/net/axay/kspigot/) -[ ![Guide](https://img.shields.io/badge/guide-read-%23c2ff73?style=for-the-badge) ](https://bluefireoly.github.io/KSpigot/) +[ ![Guide](https://img.shields.io/badge/guide-read-%23c2ff73?style=for-the-badge) ](https://jakobkmar.github.io/KSpigot/) [ ![Discord](https://img.shields.io/discord/771140534118383626?color=cyan&label=DISCORD&style=for-the-badge) ](https://discord.gg/CJDUVuJ)
KSpigot is a Kotlin extension for the popular [spigot server software](https://spigotmc.org/) for minecraft. It adds From a204867ff0fa08dcac258db4aedb6834b47324a3 Mon Sep 17 00:00:00 2001 From: Skyslycer Date: Mon, 16 Aug 2021 19:11:34 +0200 Subject: [PATCH 13/14] did requested changes --- src/main/kotlin/net/axay/kspigot/gui/GUI.kt | 4 ++-- src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt | 8 ++++++-- src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt index a213fede..23b35774 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUI.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUI.kt @@ -19,7 +19,7 @@ class GUIData( val transitionTo: InventoryChangeEffect?, val transitionFrom: InventoryChangeEffect?, internal val generalOnClick: ((GUIClickEvent) -> Unit)?, - internal val onClose: ((InventoryCloseEvent) -> Unit)? + internal val onClose: ((GUICloseEvent) -> Unit)? ) abstract class GUI( @@ -99,7 +99,7 @@ class GUIIndividual( if (resetOnClose || data.onClose != null) { listen { if (data.onClose != null && playerInstances[it.player]?.bukkitInventory == it.inventory) { - data.onClose.invoke(it) + data.onClose.invoke(GUICloseEvent(it, playerInstances[it.player]!!, it.player as Player)) } if (resetOnClose) { diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt b/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt index 5ba7a8ee..c199e24c 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUIBuilder.kt @@ -47,7 +47,7 @@ class GUIBuilder( private var onClickElement: ((GUIClickEvent) -> Unit)? = null - private var onClose: ((InventoryCloseEvent) -> Unit)? = null + private var onClose: ((GUICloseEvent) -> Unit)? = null /** * Opens the builder for a new page and adds @@ -66,7 +66,11 @@ class GUIBuilder( onClickElement = onClick } - fun onClose(onClose: (InventoryCloseEvent) -> Unit) { + /** + * A callback executed when the user closes + * the inventory. + */ + fun onClose(onClose: (GUICloseEvent) -> Unit) { this.onClose = onClose } diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt b/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt new file mode 100644 index 00000000..9ac443ae --- /dev/null +++ b/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt @@ -0,0 +1,10 @@ +package net.axay.kspigot.gui + +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryCloseEvent + +class GUICloseEvent( + val bukkitEvent: InventoryCloseEvent, + val guiInstance: GUIInstance, + val player: Player, +) \ No newline at end of file From 10737f1ddbaf24273f04eaffece63354732e1640 Mon Sep 17 00:00:00 2001 From: Skyslycer Date: Mon, 16 Aug 2021 19:33:21 +0200 Subject: [PATCH 14/14] add line break --- src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt b/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt index 9ac443ae..4ea6ec31 100644 --- a/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt +++ b/src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt @@ -7,4 +7,4 @@ class GUICloseEvent( val bukkitEvent: InventoryCloseEvent, val guiInstance: GUIInstance, val player: Player, -) \ No newline at end of file +)