diff --git a/README.md b/README.md index 0be3dad..8f5dd96 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation("com.github.DebitCardz:mc-chestui-plus:1.3.0") + implementation("com.github.DebitCardz:mc-chestui-plus:1.3.1") } ``` ### Maven @@ -34,7 +34,7 @@ dependencies { com.github.DebitCardz mc-chestui-plus - 1.3.0 + 1.3.1 ``` diff --git a/build.gradle.kts b/build.gradle.kts index 0ac1aad..4744fe9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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.3.0" +version = "1.3.1" repositories { mavenCentral() diff --git a/src/main/kotlin/me/tech/mcchestui/GUI.kt b/src/main/kotlin/me/tech/mcchestui/GUI.kt index ed5c06a..151ca91 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUI.kt +++ b/src/main/kotlin/me/tech/mcchestui/GUI.kt @@ -7,6 +7,7 @@ package me.tech.mcchestui +import me.tech.mcchestui.item.GUIItem import me.tech.mcchestui.listeners.GUIListener import me.tech.mcchestui.utils.GUICloseEvent import me.tech.mcchestui.utils.GUIDragItemEvent diff --git a/src/main/kotlin/me/tech/mcchestui/item/GUIHeadItem.kt b/src/main/kotlin/me/tech/mcchestui/item/GUIHeadItem.kt new file mode 100644 index 0000000..7027f72 --- /dev/null +++ b/src/main/kotlin/me/tech/mcchestui/item/GUIHeadItem.kt @@ -0,0 +1,61 @@ +package me.tech.mcchestui.item + +import com.destroystokyo.paper.profile.PlayerProfile +import me.tech.mcchestui.GUI +import org.bukkit.Material +import org.bukkit.OfflinePlayer +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.meta.SkullMeta + +/** + * Construct a [ItemStack] to be placed in a [GUI.Slot]. + * Automatically uses [Material.PLAYER_HEAD]. + * @param builder [GUIHeadItem] builder. + */ +fun GUI.Slot.headItem( + builder: GUIHeadItem.() -> Unit = {} +): GUIHeadItem { + return guiHeadItem(builder) +} + +/** + * Construct a [ItemStack] to be placed in a [GUI.Slot]. + * Automatically uses [Material.PLAYER_HEAD]. + * @param builder [GUIHeadItem] builder. + */ +fun guiHeadItem( + builder: GUIHeadItem.() -> Unit = {} +): GUIHeadItem { + return GUIHeadItem().apply(builder) +} + +class GUIHeadItem : GUIItem(Material.PLAYER_HEAD) { + override val itemMeta: SkullMeta + get() = stack.itemMeta as SkullMeta + + /** + * Current [OfflinePlayer] that owns the player head. + * + * @warning Will only apply on items that inherit [SkullMeta]. + */ + var skullOwner: OfflinePlayer? + get() = itemMeta.owningPlayer + set(value) { + stack.editMeta(SkullMeta::class.java) { + it.owningPlayer = value + } + } + + /** + * Current [PlayerProfile] that owns the player head. + * + * @warning Will only apply on items that inherit [SkullMeta]. + */ + var playerProfile: PlayerProfile? + get() = itemMeta.playerProfile + set(value) { + stack.editMeta(SkullMeta::class.java) { + it.playerProfile = value + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/tech/mcchestui/GUIItem.kt b/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt similarity index 67% rename from src/main/kotlin/me/tech/mcchestui/GUIItem.kt rename to src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt index ec3ca3b..1b46419 100644 --- a/src/main/kotlin/me/tech/mcchestui/GUIItem.kt +++ b/src/main/kotlin/me/tech/mcchestui/item/GUIItem.kt @@ -1,27 +1,24 @@ -package me.tech.mcchestui +package me.tech.mcchestui.item -import com.destroystokyo.paper.profile.PlayerProfile +import me.tech.mcchestui.GUI import net.kyori.adventure.text.Component import net.kyori.adventure.text.format.TextDecoration import org.bukkit.Material -import org.bukkit.OfflinePlayer import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.ItemFlag import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta -import org.bukkit.inventory.meta.SkullMeta /** * Construct a [ItemStack] to be placed in a [GUI.Slot]. * @param type material type. * @param builder [GUIItem] builder. */ -// ensure backwards compatibility. fun GUI.Slot.item( type: Material = Material.AIR, builder: GUIItem.() -> Unit = {} ): GUIItem { - return GUIItem(type).apply(builder) + return guiItem(type, builder) } /** @@ -29,7 +26,6 @@ fun GUI.Slot.item( * @param type material type. * @param builder [GUIItem] builder. */ -// created for prop functions. fun guiItem( type: Material = Material.AIR, builder: GUIItem.() -> Unit = {} @@ -37,7 +33,7 @@ fun guiItem( return GUIItem(type).apply(builder) } -class GUIItem( +open class GUIItem( type: Material ) { /** @@ -48,7 +44,7 @@ class GUIItem( /** * [ItemMeta] of the [GUIItem]. */ - val itemMeta + open val itemMeta: ItemMeta get() = stack.itemMeta /** @@ -64,14 +60,6 @@ class GUIItem( stack.apply(builder) } - /** - * Modify the [ItemMeta] of the [GUIItem]. - * @param builder [ItemMeta] builder. - */ - fun meta(builder: ItemMeta.() -> Unit) { - stack.editMeta(builder) - } - /** * Current display name of the [ItemStack]. */ @@ -84,8 +72,8 @@ class GUIItem( value } - meta { - displayName(name) + stack.editMeta { + it.displayName(name) } } @@ -101,8 +89,8 @@ class GUIItem( value } - meta { - lore(sanitizeLore(lore)) + stack.editMeta { + it.lore(sanitizeLore(lore)) } } @@ -115,48 +103,18 @@ class GUIItem( stack.amount = value } - /** - * Current [OfflinePlayer] that owns the player head. - * - * @warning Will only apply on items that inherit [SkullMeta]. - */ - var skullOwner: OfflinePlayer? - get() = (itemMeta as? SkullMeta)?.owningPlayer - set(value) { - meta { - (this as? SkullMeta)?.owningPlayer = value - } - } - - /** - * Current [PlayerProfile] that owns the player head. - * - * @warning Will only apply on items that inherit [SkullMeta]. - */ - var playerProfile: PlayerProfile? - get() = (itemMeta as? SkullMeta)?.playerProfile - set(value) { - meta { - (this as? SkullMeta)?.playerProfile = value - } - } - /** * Whether the [ItemStack] is glowing. */ var glowing: Boolean = false set(value) { - if(value) { - // Add glow. - meta { - addEnchant(Enchantment.ARROW_INFINITE, 0, true) - addItemFlags(ItemFlag.HIDE_ENCHANTS) - } - } else { - // Remove glow. - meta { - removeEnchant(Enchantment.ARROW_INFINITE) - removeItemFlags(ItemFlag.HIDE_ENCHANTS) + stack.editMeta { + if(value) { + it.addEnchant(Enchantment.ARROW_INFINITE, 0, true) + it.addItemFlags(ItemFlag.HIDE_ENCHANTS) + } else { + it.removeEnchant(Enchantment.ARROW_INFINITE) + it.removeItemFlags(ItemFlag.HIDE_ENCHANTS) } } @@ -169,8 +127,8 @@ class GUIItem( var customModelData: Int get() = itemMeta.customModelData set(value) { - meta { - setCustomModelData(value) + stack.editMeta { + it.setCustomModelData(value) } }