@@ -8,8 +8,12 @@ import com.willfp.libreforge.HolderProvider
8
8
import com.willfp.libreforge.TypedHolderProvider
9
9
import com.willfp.libreforge.TypedProvidedHolder
10
10
import com.willfp.libreforge.get
11
+ import com.willfp.libreforge.ifType
12
+ import com.willfp.libreforge.isType
11
13
import com.willfp.libreforge.registerRefreshFunction
14
+ import com.willfp.libreforge.slot.impl.NumericSlotType
12
15
import org.bukkit.entity.LivingEntity
16
+ import org.bukkit.entity.Player
13
17
import org.bukkit.inventory.ItemStack
14
18
import java.util.UUID
15
19
import java.util.concurrent.TimeUnit
@@ -37,10 +41,6 @@ abstract class ItemHolderFinder<T : Holder> {
37
41
* Find holders on an [entity] for a given [slot].
38
42
*/
39
43
fun findHolders (entity : LivingEntity , slot : SlotType ): List <TypedProvidedHolder <T >> {
40
- return doFindHolders(entity, slot)
41
- }
42
-
43
- private fun doFindHolders (entity : LivingEntity , slot : SlotType ): List <TypedProvidedHolder <T >> {
44
44
val items = slot.getItems(entity)
45
45
46
46
val holders = items.map { item ->
@@ -74,8 +74,15 @@ abstract class ItemHolderFinder<T : Holder> {
74
74
return cache.get(dispatcher.uuid) {
75
75
val entity = dispatcher.get<LivingEntity >() ? : return @get emptyList()
76
76
77
+ val slots = SlotTypes .baseTypes.toMutableSet()
78
+
79
+ // Prevents double scanning of held item slot
80
+ dispatcher.ifType<Player > {
81
+ slots.remove(NumericSlotType (it.inventory.heldItemSlot))
82
+ }
83
+
77
84
// Only check for non-combined slot types
78
- SlotTypes .baseTypes .flatMap { slot -> findHolders(entity, slot) }
85
+ slots .flatMap { slot -> findHolders(entity, slot) }
79
86
}
80
87
}
81
88
}
0 commit comments