Skip to content

Commit a5501ad

Browse files
committed
feat: optimize matching keyed handlers resolution in PacketLoreListener
1 parent 6724ad3 commit a5501ad

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

  • surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore

surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/packet/lore/PacketLoreListener.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import dev.slne.surf.surfapi.bukkit.server.nms.toNms
1111
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap
1212
import it.unimi.dsi.fastutil.objects.ObjectArrayList
1313
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
14+
import it.unimi.dsi.fastutil.objects.ObjectLists
1415
import net.kyori.adventure.text.format.TextDecoration
1516
import net.minecraft.core.component.DataComponents
1617
import net.minecraft.network.protocol.game.*
@@ -155,17 +156,20 @@ object PacketLoreListener : PacketListener {
155156
}
156157

157158
/*
158-
* We need Bukkit PDC for the current handler API.
159-
* But we only use the original mirror to cheaply determine
160-
* whether any keyed handlers actually match.
159+
* We need Bukkit PDC for the current handler API, but only when there
160+
* are keyed handlers to consider. The original mirror is used to cheaply
161+
* determine whether any keyed handlers actually match.
161162
*/
162-
val originalBukkitStack = original.asBukkitMirror()
163-
val originalPdc = originalBukkitStack.persistentDataContainer
164-
165-
val matchingKeyedHandlers = resolveMatchingKeyedHandlers(
166-
originalPdc.keys,
167-
keyedSnapshot
168-
)
163+
val matchingKeyedHandlers = if (keyedSnapshot.isNotEmpty()) {
164+
val originalBukkitStack = original.asBukkitMirror()
165+
val originalPdc = originalBukkitStack.persistentDataContainer
166+
resolveMatchingKeyedHandlers(
167+
originalPdc.keys,
168+
keyedSnapshot
169+
)
170+
} else {
171+
ObjectLists.emptyList()
172+
}
169173

170174
if (matchingKeyedHandlers.isEmpty() && globalSnapshot.isEmpty()) {
171175
return original

0 commit comments

Comments
 (0)