From 9fe8d4ad150dfb0dd78bf5cb34b1e94e5f35f852 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 28 May 2022 14:36:48 +0100 Subject: [PATCH] Added more slot builders --- .../com/willfp/eco/core/gui/GUIHelpers.kt | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt b/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt index 581a701b..bf3a9b11 100644 --- a/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt +++ b/eco-api/src/main/kotlin/com/willfp/eco/core/gui/GUIHelpers.kt @@ -6,38 +6,29 @@ import com.willfp.eco.core.gui.menu.Menu import com.willfp.eco.core.gui.menu.MenuBuilder import com.willfp.eco.core.gui.slot.Slot import com.willfp.eco.core.gui.slot.SlotBuilder +import com.willfp.eco.core.items.TestableItem import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.InventoryCloseEvent import org.bukkit.inventory.ItemStack -/** - * @see SlotBuilder.onLeftClick - */ +/** @see SlotBuilder.onLeftClick */ fun SlotBuilder.onLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = this.onLeftClick { a, b, c -> action(a, b, c) } -/** - * @see SlotBuilder.onRightClick - */ +/** @see SlotBuilder.onRightClick */ fun SlotBuilder.onRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = this.onRightClick { a, b, c -> action(a, b, c) } -/** - * @see SlotBuilder.onShiftLeftClick - */ +/** @see SlotBuilder.onShiftLeftClick */ fun SlotBuilder.onShiftLeftClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = this.onShiftLeftClick { a, b, c -> action(a, b, c) } -/** - * @see SlotBuilder.onShiftRightClick - */ +/** @see SlotBuilder.onShiftRightClick */ fun SlotBuilder.onShiftRightClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = this.onShiftRightClick { a, b, c -> action(a, b, c) } -/** - * @see SlotBuilder.onShiftRightClick - */ +/** @see SlotBuilder.onShiftRightClick */ fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder = this.onMiddleClick { a, b, c -> action(a, b, c) } @@ -50,20 +41,32 @@ fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit) fun SlotBuilder.setModifier(action: (Player, Menu, ItemStack) -> Unit): SlotBuilder = this.setUpdater { a, b, c -> c.apply { action(a, b, c) } } -/** - * @see SlotBuilder.setUpdater - */ +/** @see SlotBuilder.setUpdater */ fun SlotBuilder.setUpdater(action: (Player, Menu, ItemStack) -> ItemStack): SlotBuilder = this.setUpdater { a, b, c -> action(a, b, c) } -/** - * Kotlin builder for slots. - */ +/** Kotlin builder for slots. */ fun captiveSlot(): Slot = Slot.builder().setCaptive().build() -/** - * Kotlin builder for slots. - */ +/** Kotlin builder for slots. */ +fun captiveSlot( + init: SlotBuilder.() -> Unit +): Slot { + val builder = Slot.builder().setCaptive() + init(builder) + return builder.build() +} + +/** Kotlin builder for slots. */ +fun slot( + init: SlotBuilder.() -> Unit +): Slot { + val builder = Slot.builder() + init(builder) + return builder.build() +} + +/** Kotlin builder for slots. */ fun slot( item: ItemStack, init: SlotBuilder.() -> Unit @@ -73,16 +76,17 @@ fun slot( return builder.build() } -/** - * Kotlin builder for slots. - */ +/** Kotlin builder for slots. */ fun slot( item: ItemStack ): Slot = Slot.builder(item).build() -/** - * Kotlin builder for slots. - */ +/** Kotlin builder for slots. */ +fun slot( + item: TestableItem +): Slot = Slot.builder(item.item).build() + +/** Kotlin builder for slots. */ fun slot( provider: (Player, Menu) -> ItemStack, init: SlotBuilder.() -> Unit @@ -92,34 +96,24 @@ fun slot( return builder.build() } -/** - * Kotlin builder for slots. - */ +/** Kotlin builder for slots. */ fun slot( provider: (Player, Menu) -> ItemStack ): Slot = Slot.builder { a, b -> provider(a, b) }.build() -/** - * @see MenuBuilder.onClose - */ +/** @see MenuBuilder.onClose */ fun MenuBuilder.onClose(action: (InventoryCloseEvent, Menu) -> Unit): MenuBuilder = this.onClose { a, b -> action(a, b) } -/** - * @see MenuBuilder.modify - */ +/** @see MenuBuilder.modify */ fun MenuBuilder.modify(modifier: (MenuBuilder) -> Unit): MenuBuilder = this.modfiy { modifier(it) } -/** - * @see MenuBuilder.onRender - */ +/** @see MenuBuilder.onRender */ fun MenuBuilder.onRender(action: (Player, Menu) -> Unit): MenuBuilder = this.onRender { a, b -> action(a, b) } -/** - * Kotlin builder for menus. - */ +/** Kotlin builder for menus. */ fun menu( rows: Int, init: MenuBuilder.() -> Unit