Skip to content

Commit

Permalink
Added fix for TopInventory on pre-1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jun 24, 2024
1 parent b0de341 commit 9ab51d2
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 9ab51d2

Please sign in to comment.