From aa368909ae6e6afe73fd6674229e618f159d3f6e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 12 Aug 2021 13:38:14 +0100 Subject: [PATCH] Finished GUI --- .../willfp/eco/internal/gui/menu/EcoMenu.kt | 1 + .../eco/internal/gui/menu/MenuHandler.kt | 4 +- .../eco/internal/gui/slot/EcoFillerSlot.kt | 1 + .../willfp/eco/internal/gui/slot/EcoSlot.kt | 4 +- .../com/willfp/eco/spigot/EcoSpigotPlugin.kt | 4 +- .../com/willfp/eco/spigot/gui/GUIListener.kt | 4 +- .../com/willfp/eco/spigot/gui/GUITester.kt | 51 ------------------- 7 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUITester.kt diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt index 3f86213d..cda1c741 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt @@ -72,6 +72,7 @@ class EcoMenu( override fun getCaptiveItems(player: Player): MutableList { val inventory = MenuHandler.getExtendedInventory(player.openInventory.topInventory) + inventory ?: return ArrayList() return inventory.captiveItems } } \ No newline at end of file diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/MenuHandler.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/MenuHandler.kt index 3491c5b2..cb881d9b 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/MenuHandler.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/MenuHandler.kt @@ -25,7 +25,7 @@ object MenuHandler { return MENUS[INVS[inventory]] } - fun getExtendedInventory(inventory: Inventory): ExtendedInventory { - return INVS[inventory]!! + fun getExtendedInventory(inventory: Inventory): ExtendedInventory? { + return INVS[inventory] } } \ No newline at end of file diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoFillerSlot.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoFillerSlot.kt index 7b78156a..b43764fb 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoFillerSlot.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoFillerSlot.kt @@ -8,5 +8,6 @@ class EcoFillerSlot(itemStack: ItemStack) : EcoSlot( { _, _, _ -> }, { _, _, _ -> }, { _, _, _ -> }, + { _, _, _ -> }, { _, _, _ -> } ) \ No newline at end of file diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlot.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlot.kt index 9f49ffb8..b831111d 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlot.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/slot/EcoSlot.kt @@ -47,7 +47,9 @@ open class EcoSlot( player: Player, menu: Menu ): ItemStack { - return provider.provide(player, menu) + val prev = provider.provide(player, menu) + modifier.provide(player, menu, prev) + return prev } override fun isCaptive(): Boolean { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt index fdf66957..fd4b17dd 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/EcoSpigotPlugin.kt @@ -17,7 +17,6 @@ import com.willfp.eco.spigot.display.* import com.willfp.eco.spigot.drops.CollatedRunnable import com.willfp.eco.spigot.eventlisteners.* import com.willfp.eco.spigot.gui.GUIListener -import com.willfp.eco.spigot.gui.GUITester import com.willfp.eco.spigot.integrations.anticheat.* import com.willfp.eco.spigot.integrations.antigrief.* import com.willfp.eco.spigot.integrations.customitems.CustomItemsOraxen @@ -142,8 +141,7 @@ abstract class EcoSpigotPlugin : EcoPlugin( PlayerJumpListeners(), GUIListener(this), ArrowDataListener(this), - ArmorChangeEventListeners(this), - GUITester(this) + ArmorChangeEventListeners(this) ) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt index 04a909fa..6a8d5f57 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt @@ -34,7 +34,7 @@ class GUIListener(plugin: EcoPlugin) : PluginDependent(plugin), Liste event.isCancelled = true ecoSlot.handleInventoryClick(event, menu) - plugin.scheduler.run{ MenuHandler.getExtendedInventory(event.clickedInventory!!).refresh(player) } + plugin.scheduler.run{ MenuHandler.getExtendedInventory(event.clickedInventory!!)!!.refresh(player) } } @EventHandler @@ -46,7 +46,7 @@ class GUIListener(plugin: EcoPlugin) : PluginDependent(plugin), Liste val menu = MenuHandler.getMenu(player.openInventory.topInventory) ?: return - plugin.scheduler.run{ MenuHandler.getExtendedInventory(player.openInventory.topInventory).refresh(player) } + plugin.scheduler.run{ MenuHandler.getExtendedInventory(player.openInventory.topInventory)!!.refresh(player) } plugin.scheduler.runLater({ Bukkit.getLogger().info(menu.getCaptiveItems(player).toString()) }, 1) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUITester.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUITester.kt deleted file mode 100644 index 121fdae6..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUITester.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.willfp.eco.spigot.gui - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.PluginDependent -import com.willfp.eco.core.gui.menu.Menu -import com.willfp.eco.core.gui.slot.FillerMask -import com.willfp.eco.core.gui.slot.Slot -import org.bukkit.Material -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener -import org.bukkit.event.player.AsyncPlayerChatEvent -import org.bukkit.inventory.ItemStack - -class GUITester(plugin: EcoPlugin) : PluginDependent(plugin), Listener { - private val menu: Menu = Menu.builder(3) - .setMask( - FillerMask( - Material.BLACK_STAINED_GLASS_PANE, - "111111111", - "100000001", - "111111111" - ) - ).setSlot( - 2, 2, - Slot.builder() - .setCaptive() - .build() - ).modfiy { builder -> - run { - val slot = Slot.builder(ItemStack(Material.RED_STAINED_GLASS_PANE)) - .setModifier{ player, menu, prev -> run { - if (menu.getCaptiveItems(player).isNotEmpty()) { - prev.type = Material.GREEN_STAINED_GLASS_PANE - } - }} - .build() - for (i in 3..8) { - builder.setSlot(2, i, slot) - } - } - }.build() - - @EventHandler - fun test(event: AsyncPlayerChatEvent) { - if (!event.message.equals("testgui", true)) { - return - } - - plugin.scheduler.run { menu.open(event.player) } - } -} \ No newline at end of file