Merge branch 'master' of https://github.com/jakobkmar/KSpigot
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# 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
|
||||
|
||||
```kotlin
|
||||
|
@@ -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"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@@ -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 {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
# KSpigot
|
||||
|
||||
[  ](https://repo1.maven.org/maven2/net/axay/kspigot/)
|
||||
[  ](https://bluefireoly.github.io/KSpigot/)
|
||||
[  ](https://jakobkmar.github.io/KSpigot/)
|
||||
[  ](https://discord.gg/CJDUVuJ) <br>
|
||||
|
||||
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 transitionFrom: InventoryChangeEffect?,
|
||||
internal val generalOnClick: ((GUIClickEvent<T>) -> Unit)?,
|
||||
internal val onClose: ((GUICloseEvent<T>) -> Unit)?
|
||||
)
|
||||
|
||||
abstract class GUI<T : ForInventory>(
|
||||
@@ -95,9 +96,15 @@ class GUIIndividual<T : ForInventory>(
|
||||
}
|
||||
|
||||
init {
|
||||
if (resetOnClose) {
|
||||
if (resetOnClose || data.onClose != null) {
|
||||
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
|
||||
|
||||
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<T : ForInventory>(
|
||||
|
||||
private var onClickElement: ((GUIClickEvent<T>) -> Unit)? = null
|
||||
|
||||
private var onClose: ((GUICloseEvent<T>) -> Unit)? = null
|
||||
|
||||
/**
|
||||
* Opens the builder for a new page and adds
|
||||
* the new page to the GUI.
|
||||
@@ -63,8 +66,16 @@ class GUIBuilder<T : ForInventory>(
|
||||
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(
|
||||
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
|
||||
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?
|
||||
get() = (whoClicked as? Player) ?: kotlin.run {
|
||||
isCancelled = true
|
||||
|
Reference in New Issue
Block a user