Merge branch 'master' of https://github.com/jakobkmar/KSpigot
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Brigardier support
|
# Brigardier support
|
||||||
|
|
||||||
|
???+ 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!) <br>
|
||||||
|
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
|
## Create a command
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
|
@@ -9,11 +9,12 @@ You can configure the Java version using Gradle:
|
|||||||
```kotlin
|
```kotlin
|
||||||
// set the Java version you are using, Java 16 is the minimum required version for Minecraft
|
// set the Java version you are using, Java 16 is the minimum required version for Minecraft
|
||||||
|
|
||||||
tasks.compileJava {
|
tasks {
|
||||||
options.release.set(16)
|
compileJava {
|
||||||
}
|
options.release.set(16)
|
||||||
|
}
|
||||||
tasks.compileKotlin {
|
compileKotlin {
|
||||||
kotlinOptions.jvmTarget = "16"
|
kotlinOptions.jvmTarget = "16"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@@ -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
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.5.10"
|
kotlin("jvm") version "1.5.21"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "net.axay"
|
group = "your.group"
|
||||||
version = "1.0-SNAPSHOT"
|
version = "1.0-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -17,7 +17,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")
|
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 {
|
tasks {
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# KSpigot
|
# KSpigot
|
||||||
|
|
||||||
[  ](https://repo1.maven.org/maven2/net/axay/kspigot/)
|
[  ](https://repo1.maven.org/maven2/net/axay/kspigot/)
|
||||||
[  ](https://bluefireoly.github.io/KSpigot/)
|
[  ](https://jakobkmar.github.io/KSpigot/)
|
||||||
[  ](https://discord.gg/CJDUVuJ) <br>
|
[  ](https://discord.gg/CJDUVuJ) <br>
|
||||||
|
|
||||||
KSpigot is a Kotlin extension for the popular [spigot server software](https://spigotmc.org/) for minecraft. It adds
|
KSpigot is a Kotlin extension for the popular [spigot server software](https://spigotmc.org/) for minecraft. It adds
|
||||||
|
@@ -19,6 +19,7 @@ class GUIData<T : ForInventory>(
|
|||||||
val transitionTo: InventoryChangeEffect?,
|
val transitionTo: InventoryChangeEffect?,
|
||||||
val transitionFrom: InventoryChangeEffect?,
|
val transitionFrom: InventoryChangeEffect?,
|
||||||
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
|
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
|
||||||
|
internal val onClose: ((GUICloseEvent<T>) -> Unit)?
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract class GUI<T : ForInventory>(
|
abstract class GUI<T : ForInventory>(
|
||||||
@@ -95,9 +96,15 @@ class GUIIndividual<T : ForInventory>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (resetOnClose) {
|
if (resetOnClose || data.onClose != null) {
|
||||||
listen<InventoryCloseEvent> {
|
listen<InventoryCloseEvent> {
|
||||||
deleteInstance(it.player as? Player ?: return@listen)
|
if (data.onClose != null && playerInstances[it.player]?.bukkitInventory == it.inventory) {
|
||||||
|
data.onClose.invoke(GUICloseEvent(it, playerInstances[it.player]!!, it.player as Player))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resetOnClose) {
|
||||||
|
deleteInstance(it.player as? Player ?: return@listen)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
package net.axay.kspigot.gui
|
package net.axay.kspigot.gui
|
||||||
|
|
||||||
import net.axay.kspigot.gui.elements.*
|
import net.axay.kspigot.gui.elements.*
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ class GUIBuilder<T : ForInventory>(
|
|||||||
|
|
||||||
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
|
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
|
||||||
|
|
||||||
|
private var onClose: ((GUICloseEvent<T>) -> Unit)? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the builder for a new page and adds
|
* Opens the builder for a new page and adds
|
||||||
* the new page to the GUI.
|
* the new page to the GUI.
|
||||||
@@ -63,8 +66,16 @@ class GUIBuilder<T : ForInventory>(
|
|||||||
onClickElement = onClick
|
onClickElement = onClick
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A callback executed when the user closes
|
||||||
|
* the inventory.
|
||||||
|
*/
|
||||||
|
fun onClose(onClose: (GUICloseEvent<T>) -> Unit) {
|
||||||
|
this.onClose = onClose
|
||||||
|
}
|
||||||
|
|
||||||
internal fun build() = guiCreator.createInstance(
|
internal fun build() = guiCreator.createInstance(
|
||||||
GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement)
|
GUIData(type, title, guiPages, defaultPage, transitionTo, transitionFrom, onClickElement, onClose)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt
Normal file
10
src/main/kotlin/net/axay/kspigot/gui/GUICloseEvent.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package net.axay.kspigot.gui
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||||
|
|
||||||
|
class GUICloseEvent<T : ForInventory>(
|
||||||
|
val bukkitEvent: InventoryCloseEvent,
|
||||||
|
val guiInstance: GUIInstance<T>,
|
||||||
|
val player: Player,
|
||||||
|
)
|
@@ -77,7 +77,8 @@ object GUIHolder : AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val InventoryAction.isGUIClick
|
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 || this == InventoryAction.MOVE_TO_OTHER_INVENTORY
|
||||||
|
|
||||||
private val InventoryInteractEvent.playerOrCancel: Player?
|
private val InventoryInteractEvent.playerOrCancel: Player?
|
||||||
get() = (whoClicked as? Player) ?: kotlin.run {
|
get() = (whoClicked as? Player) ?: kotlin.run {
|
||||||
isCancelled = true
|
isCancelled = true
|
||||||
|
Reference in New Issue
Block a user