Skip to content

Commit d3c42ee

Browse files
committed
More SlotType changes, updated eco to 6.70.0
1 parent 4261581 commit d3c42ee

File tree

6 files changed

+41
-10
lines changed

6 files changed

+41
-10
lines changed

core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies {
44
}
55
implementation("com.willfp:ModelEngineBridge:1.3.0")
66

7-
compileOnly("com.willfp:eco:6.69.0")
7+
compileOnly("com.willfp:eco:6.70.0")
88
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
99
compileOnly("net.kyori:adventure-text-minimessage:4.14.0")
1010

core/src/main/kotlin/com/willfp/libreforge/LibreforgeSpigotPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class LibreforgeSpigotPlugin : EcoPlugin() {
190190
}
191191

192192
override fun getMinimumEcoVersion(): String {
193-
return "6.69.0"
193+
return "6.70.0"
194194
}
195195

196196
/**

core/src/main/kotlin/com/willfp/libreforge/slot/ItemHolderFinder.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ abstract class ItemHolderFinder<T : Holder> {
4343
private fun doFindHolders(entity: LivingEntity, slot: SlotType): List<TypedProvidedHolder<T>> {
4444
val items = slot.getItems(entity)
4545

46-
// FIXME: This will lead to holders with the 'any' slot being double-counted.
47-
4846
val holders = items.map { item ->
4947
this.find(item)
5048
.filter { holder -> isValidInSlot(holder, slot) }
@@ -77,8 +75,7 @@ abstract class ItemHolderFinder<T : Holder> {
7775
val entity = dispatcher.get<LivingEntity>() ?: return@get emptyList()
7876

7977
// Only check for non-combined slot types
80-
val slots = SlotTypes.values().filterNot { it is CombinedSlotType }
81-
slots.flatMap { slot -> findHolders(entity, slot) }
78+
SlotTypes.baseTypes.flatMap { slot -> findHolders(entity, slot) }
8279
}
8380
}
8481
}

core/src/main/kotlin/com/willfp/libreforge/slot/SlotTypes.kt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ object SlotTypes : Registry<SlotType>() {
1717
@Deprecated("Use SlotTypeMainhand instead", ReplaceWith("SlotTypeMainhand"), level = DeprecationLevel.ERROR)
1818
val mainHandSlot = SlotTypeMainhand
1919

20+
lateinit var baseTypes: List<SlotType>
21+
private set
22+
2023
override fun get(id: String): SlotType? {
2124
val existing = super.get(id)
2225

@@ -25,6 +28,18 @@ object SlotTypes : Registry<SlotType>() {
2528
return existing
2629
}
2730

31+
// Prevent registering numeric slot types that correspond to armor slots
32+
val idInt = id.toIntOrNull()
33+
if (idInt != null) {
34+
when (idInt) {
35+
40 -> return SlotTypeOffhand
36+
36 -> return SlotTypeBoots
37+
37 -> return SlotTypeLeggings
38+
38 -> return SlotTypeChestplate
39+
39 -> return SlotTypeHelmet
40+
}
41+
}
42+
2843
// Create new slot type if it doesn't exist
2944
return createNew(id)
3045
?.apply { register(this) }
@@ -38,13 +53,22 @@ object SlotTypes : Registry<SlotType>() {
3853
)
3954
}
4055

41-
if (id.toIntOrNull() != null) {
42-
return NumericSlotType(id.toInt())
56+
val idInt = id.toIntOrNull()
57+
if (idInt != null) {
58+
return NumericSlotType(idInt)
4359
}
4460

4561
return null
4662
}
4763

64+
override fun onRegister(element: SlotType) {
65+
baseTypes = values().filter { it !is CombinedSlotType }
66+
}
67+
68+
override fun onRemove(element: SlotType) {
69+
baseTypes = values().filter { it !is CombinedSlotType }
70+
}
71+
4872
init {
4973
register(SlotTypeAny)
5074
register(SlotTypeArmor)
@@ -56,5 +80,10 @@ object SlotTypes : Registry<SlotType>() {
5680
register(SlotTypeHelmet)
5781
register(SlotTypeLeggings)
5882
register(SlotTypeOffhand)
83+
84+
// Register all numeric slots
85+
(0..45).forEach {
86+
get(it.toString())
87+
}
5988
}
6089
}

core/src/main/kotlin/com/willfp/libreforge/slot/impl/SlotTypeAny.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package com.willfp.libreforge.slot.impl
22

33
import com.willfp.eco.core.drops.DropQueue
4+
import com.willfp.libreforge.slot.CombinedSlotType
45
import com.willfp.libreforge.slot.SlotType
6+
import com.willfp.libreforge.slot.SlotTypes
57
import org.bukkit.entity.LivingEntity
68
import org.bukkit.entity.Player
79
import org.bukkit.inventory.ItemStack
810

9-
object SlotTypeAny : SlotType("any") {
11+
object SlotTypeAny : CombinedSlotType("any") {
12+
override val types: List<SlotType>
13+
get() = SlotTypes.baseTypes
14+
1015
override fun addToSlot(player: Player, item: ItemStack): Boolean {
1116
DropQueue(player)
1217
.addItem(item)

loader/src/main/kotlin/com/willfp/libreforge/loader/LibreforgePlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ abstract class LibreforgePlugin : EcoPlugin() {
211211
}
212212

213213
override fun getMinimumEcoVersion(): String {
214-
return "6.63.0"
214+
return "6.67.3"
215215
}
216216

217217
/**

0 commit comments

Comments
 (0)