Skip to content

Commit

Permalink
fix: compare with uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchen5209 committed Aug 25, 2024
1 parent db28aaa commit c9faf35
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import one.oktw.galaxy.proxy.Main.Companion.main
import kotlin.math.max

class ResourcePackHelper {
private val appliedPacks: MutableMap<Player, List<ResourcePack>> = mutableMapOf()
private val appliedPacks: MutableMap<Player, List<ResourcePackInfo>> = mutableMapOf()

fun updatePlayerResourcePacks(player: Player, galaxy: String) {
val targetResourcePacks = main.config.galaxies[galaxy]?.ResourcePacks?.distinct()?.mapNotNull { main.config.resourcePacks[it] } ?: return
val targetResourcePacks = main.config.galaxies[galaxy]?.ResourcePacks?.distinct()?.mapNotNull { main.config.resourcePacks[it]?.packInfo() } ?: return
val appliedResourcePacks = this.appliedPacks.getOrPut(player) { listOf() }

var skipFurtherCheck = false
val packsToQueue = mutableListOf<ResourcePackInfo>()
val packsToRemove = mutableListOf<ResourcePackInfo>()

for (index in 0..max(targetResourcePacks.size, appliedResourcePacks.size)) {
if (targetResourcePacks.getOrNull(index)?.hash.contentEquals(appliedResourcePacks.getOrNull(index)?.hash) && !skipFurtherCheck) continue
if (targetResourcePacks.getOrNull(index)?.id == appliedResourcePacks.getOrNull(index)?.id && !skipFurtherCheck) continue

skipFurtherCheck = true
if (index < appliedResourcePacks.size) packsToRemove.add(appliedResourcePacks[index].packInfo())
if (index < targetResourcePacks.size) packsToQueue.add(targetResourcePacks[index].packInfo())
if (index < appliedResourcePacks.size) packsToRemove.add(appliedResourcePacks[index])
if (index < targetResourcePacks.size) packsToQueue.add(targetResourcePacks[index])
}

main.logger.debug(appliedResourcePacks.map { it.packInfo().id }.toString())
main.logger.debug(targetResourcePacks.map { it.packInfo().id }.toString())
main.logger.debug(appliedResourcePacks.map { it.id }.toString())
main.logger.debug(targetResourcePacks.map { it.id }.toString())
main.logger.info("Removing {} packs, Sending {} packs", packsToRemove.size, packsToQueue.size)
packsToRemove.forEach { pack -> player.removeResourcePacks(pack) }
packsToQueue.forEach { pack -> player.sendResourcePacks(pack) }
Expand Down

0 comments on commit c9faf35

Please sign in to comment.