From 9ab51d2c87abd7b0a23a4e84d9de5827da0e9873 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 24 Jun 2024 18:42:32 +0100 Subject: [PATCH] Added fix for TopInventory on pre-1.21 --- .../eco/internal/gui/menu/RenderedInventory.kt | 18 +++++++++++++++++- .../spigot/proxy/v1_17_R1/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_18_R1/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_18_R2/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_19_R1/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_19_R2/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_19_R3/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_20_R1/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_20_R2/TopInventory.kt | 11 +++++++++++ .../spigot/proxy/v1_20_R3/TopInventory.kt | 11 +++++++++++ 10 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/TopInventory.kt create mode 100644 eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/TopInventory.kt create mode 100644 eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/TopInventory.kt create mode 100644 eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/TopInventory.kt create mode 100644 eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TopInventory.kt create mode 100644 eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R3/TopInventory.kt create mode 100644 eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R1/TopInventory.kt create mode 100644 eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R2/TopInventory.kt create mode 100644 eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R3/TopInventory.kt diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt index 718645ad9..6a52a251b 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/RenderedInventory.kt @@ -1,5 +1,7 @@ package com.willfp.eco.internal.gui.menu +import com.willfp.eco.core.Eco +import com.willfp.eco.core.Prerequisite import com.willfp.eco.core.gui.menu.events.CaptiveItemChangeEvent import com.willfp.eco.core.items.isEcoEmpty import com.willfp.eco.core.recipe.parts.EmptyTestableItem @@ -20,9 +22,23 @@ fun Player.forceRenderedInventory(menu: RenderedInventory) { trackedForceRendered[this.uniqueId] = menu } +// Workaround because 1.21 has OpenInventory as an interface instead of an abstract class like in previous versions +interface TopInventoryProxy { + fun getTopInventory(player: Player): Inventory +} + +private val Player.topInventory: Inventory + get() { + return if (!Prerequisite.HAS_1_21.isMet) { + Eco.get().ecoPlugin.getProxy(TopInventoryProxy::class.java).getTopInventory(this) + } else { + this.openInventory.topInventory + } + } + val Player.renderedInventory: RenderedInventory? get() = trackedForceRendered[this.uniqueId] - ?: this.openInventory.topInventory.asRenderedInventory() + ?: this.topInventory.asRenderedInventory() class RenderedInventory( val menu: EcoMenu, diff --git a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/TopInventory.kt b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/TopInventory.kt new file mode 100644 index 000000000..ee8e5673e --- /dev/null +++ b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_17_R1 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/TopInventory.kt b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/TopInventory.kt new file mode 100644 index 000000000..768cdf6be --- /dev/null +++ b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_18_R1 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/TopInventory.kt b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/TopInventory.kt new file mode 100644 index 000000000..32a9dbac7 --- /dev/null +++ b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_18_R2 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/TopInventory.kt b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/TopInventory.kt new file mode 100644 index 000000000..f56e5c78c --- /dev/null +++ b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R1 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TopInventory.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TopInventory.kt new file mode 100644 index 000000000..b567eebf8 --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R3/TopInventory.kt b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R3/TopInventory.kt new file mode 100644 index 000000000..8899ef897 --- /dev/null +++ b/eco-core/core-nms/v1_19_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R3/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R3 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R1/TopInventory.kt b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R1/TopInventory.kt new file mode 100644 index 000000000..c93d8698d --- /dev/null +++ b/eco-core/core-nms/v1_20_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R1/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_20_R1 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R2/TopInventory.kt b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R2/TopInventory.kt new file mode 100644 index 000000000..df0ec1d7f --- /dev/null +++ b/eco-core/core-nms/v1_20_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R2/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_20_R2 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +} diff --git a/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R3/TopInventory.kt b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R3/TopInventory.kt new file mode 100644 index 000000000..3d3e74681 --- /dev/null +++ b/eco-core/core-nms/v1_20_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_R3/TopInventory.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_20_R3 + +import com.willfp.eco.internal.gui.menu.TopInventoryProxy +import org.bukkit.entity.Player +import org.bukkit.inventory.Inventory + +class TopInventory: TopInventoryProxy { + override fun getTopInventory(player: Player): Inventory { + return player.openInventory.topInventory + } +}