11package org.polyfrost.polyplus.client.cosmetics
22
3+ import dev.deftu.omnicore.api.client.player
34import net.minecraft.network.play.server.S38PacketPlayerListItem
45import net.minecraftforge.event.world.WorldEvent
56import org.apache.logging.log4j.LogManager
@@ -10,13 +11,18 @@ import org.polyfrost.polyplus.client.network.websocket.ClientboundPacket
1011import org.polyfrost.polyplus.client.network.websocket.PolyConnection
1112import org.polyfrost.polyplus.client.network.websocket.ServerboundPacket
1213import org.polyfrost.polyplus.events.WebSocketMessage
14+ import org.polyfrost.polyplus.utils.Batcher
15+ import java.time.Duration
1316import java.util.UUID
1417import kotlin.collections.component1
1518import kotlin.collections.component2
1619import kotlin.collections.iterator
1720
1821object ApplyCosmetics {
1922 private val LOGGER = LogManager .getLogger()
23+ private val BATCHER = Batcher (Duration .ofMillis(200 ), HashSet <String >()) { players ->
24+ PolyConnection .sendPacket(ServerboundPacket .GetActiveCosmetics (players.toList()))
25+ }
2026
2127 @Subscribe
2228 fun onWorldLoad (event : WorldEvent .Load ) {
@@ -29,9 +35,10 @@ object ApplyCosmetics {
2935 val packet = try { event.getPacket<S38PacketPlayerListItem >() ? : return } catch (e: Exception ) { return }
3036 when (packet.action) {
3137 S38PacketPlayerListItem .Action .ADD_PLAYER -> {
32- val players = packet.entries.mapNotNull { it.profile.id.takeUnless { it.version() == 2 }?.toString() } // mojang only uses UUIDv2 so if its not, its a bot and wont have a cape.
33- PolyConnection .sendPacket(ServerboundPacket .GetActiveCosmetics (players))
34- LOGGER .info(" Requested cosmetics for players: $players " )
38+ packet.entries.forEach {
39+ // mojang doesnt use uuidv2 so if it is, its a bot and wont have a cape.
40+ if (it.profile.id.version() != 2 ) BATCHER .add(it.profile.id.toString())
41+ }
3542 }
3643
3744 S38PacketPlayerListItem .Action .REMOVE_PLAYER -> {
0 commit comments