diff --git a/api/src/main/kotlin/com/mattmx/ktgui/components/button/GuiButton.kt b/api/src/main/kotlin/com/mattmx/ktgui/components/button/GuiButton.kt index 936d541..683a89d 100644 --- a/api/src/main/kotlin/com/mattmx/ktgui/components/button/GuiButton.kt +++ b/api/src/main/kotlin/com/mattmx/ktgui/components/button/GuiButton.kt @@ -28,6 +28,8 @@ open class GuiButton>( protected set var ifTexturePackActive: ((T) -> Unit)? = null protected set + var postBuild: ((ItemStack) -> Unit)? = null + protected set // todo should remove this once we have no need for it (parent has been declared) private var slots: ArrayList? = null @@ -122,6 +124,13 @@ open class GuiButton>( return this as T } + /** + * Code runs after the [GuiButton] has built an [ItemStack] + */ + infix fun postBuild(block: ItemStack.() -> Unit) = apply { + postBuild = block + } as T + infix fun fromItemBuilder(builder: DslIBuilder) : T { item = builder.build() return this as T @@ -162,9 +171,9 @@ open class GuiButton>( if (player?.hasResourcePack() == true && ifTexturePackActive != null) { val copy = this.copy(this.parent) ifTexturePackActive!!(copy) - return copy.item + return copy.item.apply { this?.let { postBuild?.invoke(it) } } } - return getItemStack()?.clone() + return getItemStack()?.clone().apply { this?.let { postBuild?.invoke(it) } } } override fun slots(): List { diff --git a/api/src/main/kotlin/com/mattmx/ktgui/utils/time.kt b/api/src/main/kotlin/com/mattmx/ktgui/utils/time.kt new file mode 100644 index 0000000..2154e11 --- /dev/null +++ b/api/src/main/kotlin/com/mattmx/ktgui/utils/time.kt @@ -0,0 +1,16 @@ +package com.mattmx.ktgui.utils + +val Int.ticks + get() = this.toLong() + +val Int.seconds + get() = ticks * 20L + +val Double.seconds + get() = (this * 20).toLong() + +val Int.minutes + get() = seconds * 60L + +val Double.minutes + get() = (this * 20 * 60).toLong() \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0c74546..dc4eb35 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ subprojects { } dependencies { compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10") - compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") compileOnly("me.clip:placeholderapi:2.11.1") } diff --git a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt index 703d85b..8b2ace6 100644 --- a/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt +++ b/plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt @@ -1,9 +1,16 @@ package com.mattmx.ktgui import com.mattmx.ktgui.commands.simpleCommand +import com.mattmx.ktgui.dsl.event import com.mattmx.ktgui.examples.* import com.mattmx.ktgui.utils.not import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.NamespacedKey +import org.bukkit.block.Block +import org.bukkit.entity.FallingBlock +import org.bukkit.event.entity.EntityChangeBlockEvent +import org.bukkit.persistence.PersistentDataType import org.bukkit.plugin.java.JavaPlugin import java.util.logging.Logger diff --git a/plugin/src/main/kotlin/com/mattmx/ktgui/examples/GuiHookExample.kt b/plugin/src/main/kotlin/com/mattmx/ktgui/examples/GuiHookExample.kt index e993ff6..5aa18f4 100644 --- a/plugin/src/main/kotlin/com/mattmx/ktgui/examples/GuiHookExample.kt +++ b/plugin/src/main/kotlin/com/mattmx/ktgui/examples/GuiHookExample.kt @@ -12,6 +12,8 @@ import com.mattmx.ktgui.utils.not import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType +import org.bukkit.inventory.meta.PotionMeta +import org.bukkit.potion.PotionType class GuiHookExample : Example { val gui = gui(!"Title", 3) { @@ -23,6 +25,19 @@ class GuiHookExample : Example { add(!"&fThis button was added regularly.") } } slots listOf(11, 13) + + button(Material.LINGERING_POTION) { + named(!"&fA potion") + lore { + add(!"&fThis is a custom potion") + } + // Will run before the button is made into an itemstack + postBuild { + editMeta(PotionMeta::class.java) { meta -> + meta.basePotionType = PotionType.STRONG_STRENGTH + } + } + } slot last() } override fun run(player: Player) = gui.open(player) diff --git a/plugin/src/main/resources/plugin.yml b/plugin/src/main/resources/plugin.yml index c0e775f..5158156 100644 --- a/plugin/src/main/resources/plugin.yml +++ b/plugin/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: KtGUI version: '${version}' main: com.mattmx.ktgui.KotlinGui -api-version: 1.20 +api-version: 1.17 prefix: KtGUI authors: [ MattMX ] description: Declarative GUI Library for Paper.