Skip to content

Commit

Permalink
Use UUIDs as keys instead of player instances in KeyTracking state map
Browse files Browse the repository at this point in the history
  • Loading branch information
tth05 authored and Dream-Master committed Nov 16, 2023
1 parent 9cfc4e7 commit 7fc156b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/scala/mrtjp/core/data/KeyTracking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.settings.KeyBinding
import net.minecraft.entity.player.EntityPlayer

import java.util.UUID
import scala.collection.mutable.{HashMap => MHashMap, Map => MMap}

object KeyTracking {
private var idPool = 0
private val map = MHashMap[Int, MMap[EntityPlayer, Boolean]]()
private val map = MHashMap[Int, MMap[UUID, Boolean]]()

def updatePlayerKey(id: Int, player: EntityPlayer, state: Boolean) {
map(id) += player -> state
map(id) += player.getGameProfile.getId -> state
}

def registerTracker(tracker: TServerKeyTracker) {
tracker.id = idPool
idPool += 1
map.getOrElseUpdate(
tracker.id,
MHashMap[EntityPlayer, Boolean]().withDefaultValue(false)
MHashMap[UUID, Boolean]().withDefaultValue(false)
)
}

def isKeyDown(id: Int, player: EntityPlayer) = map(id)(player)
def isKeyDown(id: Int, player: EntityPlayer) =
map(id)(player.getGameProfile.getId)
}

trait TServerKeyTracker {
Expand Down

0 comments on commit 7fc156b

Please sign in to comment.