Updated to use libreforge slot system

This commit is contained in:
Auxilor
2023-08-28 15:24:29 +01:00
parent 7b567485e1
commit cb2d5d8850
14 changed files with 11 additions and 157 deletions

View File

@@ -8,11 +8,12 @@ import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.builder.ItemStackBuilder
import com.willfp.eco.core.recipe.Recipes
import com.willfp.eco.core.registry.Registrable
import com.willfp.ecoitems.slot.ItemSlots
import com.willfp.libreforge.Holder
import com.willfp.libreforge.ViolationContext
import com.willfp.libreforge.conditions.Conditions
import com.willfp.libreforge.effects.Effects
import com.willfp.libreforge.slot.SlotTypes
import com.willfp.libreforge.slot.impl.SlotTypeMainhand
import org.bukkit.inventory.ItemStack
import java.util.Objects
@@ -37,7 +38,9 @@ class EcoItem(
val displayName: String = config.getString("item.display-name")
val slot = ItemSlots.getByID(config.getString("slot"))
val slot = if (config.has("slot"))
SlotTypes[config.getString("slot")]
else SlotTypes["mainhand"]
// Defensive copy
private val _itemStack: ItemStack = run {

View File

@@ -3,8 +3,8 @@ package com.willfp.ecoitems.items
import com.willfp.eco.core.fast.FastItemStack
import com.willfp.eco.core.fast.fast
import com.willfp.eco.util.namespacedKeyOf
import com.willfp.ecoitems.slot.ItemSlots
import com.willfp.libreforge.ItemProvidedHolder
import com.willfp.libreforge.slot.SlotTypes
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
@@ -47,9 +47,8 @@ var FastItemStack.ecoItem: EcoItem?
}
val Player.ecoItems: Collection<ItemProvidedHolder>
get() = ItemSlots.flatMap { slot ->
get() = SlotTypes.flatMap { slot ->
slot.getItems(this)
.filterNotNull()
.mapNotNull { item ->
item.ecoItem
?.takeIf { it.slot == slot }

View File

@@ -1,19 +0,0 @@
package com.willfp.ecoitems.slot
import com.willfp.eco.core.registry.KRegistrable
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
abstract class ItemSlot(
override val id: String
) : KRegistrable {
abstract fun getItems(player: Player): List<ItemStack?>
override fun equals(other: Any?): Boolean {
return other is ItemSlot && this.id == other.id
}
override fun hashCode(): Int {
return id.hashCode()
}
}

View File

@@ -1,32 +0,0 @@
package com.willfp.ecoitems.slot
import com.willfp.eco.core.registry.Registry
import com.willfp.ecoitems.slot.impl.ItemSlotAny
import com.willfp.ecoitems.slot.impl.ItemSlotBoots
import com.willfp.ecoitems.slot.impl.ItemSlotChestplate
import com.willfp.ecoitems.slot.impl.ItemSlotHands
import com.willfp.ecoitems.slot.impl.ItemSlotHelmet
import com.willfp.ecoitems.slot.impl.ItemSlotLeggings
import com.willfp.ecoitems.slot.impl.ItemSlotMainhand
import com.willfp.ecoitems.slot.impl.ItemSlotOffhand
object ItemSlots : Registry<ItemSlot>() {
fun getByID(id: String?): ItemSlot {
if (id == null) {
return ItemSlotMainhand // Legacy
}
return get(id) ?: ItemSlotMainhand
}
init {
register(ItemSlotAny)
register(ItemSlotBoots)
register(ItemSlotChestplate)
register(ItemSlotHands)
register(ItemSlotHelmet)
register(ItemSlotLeggings)
register(ItemSlotMainhand)
register(ItemSlotOffhand)
}
}

View File

@@ -1,11 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotAny : ItemSlot("any") {
override fun getItems(player: Player): List<ItemStack?> {
return player.inventory.contents.toList()
}
}

View File

@@ -1,13 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotBoots : ItemSlot("boots") {
override fun getItems(player: Player): List<ItemStack?> {
return listOf(
player.inventory.boots,
)
}
}

View File

@@ -1,13 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotChestplate : ItemSlot("chestplate") {
override fun getItems(player: Player): List<ItemStack?> {
return listOf(
player.inventory.chestplate,
)
}
}

View File

@@ -1,14 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotHands : ItemSlot("hands") {
override fun getItems(player: Player): List<ItemStack> {
return listOf(
player.inventory.itemInMainHand,
player.inventory.itemInOffHand
)
}
}

View File

@@ -1,13 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotHelmet : ItemSlot("helmet") {
override fun getItems(player: Player): List<ItemStack?> {
return listOf(
player.inventory.helmet,
)
}
}

View File

@@ -1,13 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotLeggings : ItemSlot("leggings") {
override fun getItems(player: Player): List<ItemStack?> {
return listOf(
player.inventory.leggings,
)
}
}

View File

@@ -1,11 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotMainhand : ItemSlot("mainhand") {
override fun getItems(player: Player): List<ItemStack> {
return listOf(player.inventory.itemInMainHand)
}
}

View File

@@ -1,11 +0,0 @@
package com.willfp.ecoitems.slot.impl
import com.willfp.ecoitems.slot.ItemSlot
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
object ItemSlotOffhand : ItemSlot("offhand") {
override fun getItems(player: Player): List<ItemStack> {
return listOf(player.inventory.itemInOffHand)
}
}

View File

@@ -34,7 +34,9 @@ item:
effective-durability: 1024 # Optional, set the durability
# The slot the item has to be in to activate its effects.
# Can be mainhand, offhand, hands, helmet, chestplate, leggings, boots, or any.
# The options for slot are mainhand, offhand, hands, helmet, chestplate,
# leggings, boots, armor, any, a number from 0-40 (to specify an exact slot),
# or a list of slots like "9, 10, 11, mainhand"
# Use to choose weather this is a weapon, tool, armor piece, charm, etc.
# If you don't specify this, it will default to mainhand.
slot: mainhand