Skip to content

Commit 1ccb75b

Browse files
committed
fix: equality check with v6 authlib (#238)
1 parent 5748cad commit 1ccb75b

File tree

12 files changed

+60
-60
lines changed

12 files changed

+60
-60
lines changed

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/Functions.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,16 @@ internal inline fun <reified T, reified R> createAdaptedFieldGetter(): (T) -> R
5757
}
5858
}
5959

60-
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T): () -> T {
60+
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T, equalityChecker: (H, H) -> Boolean = { a, b -> a == b }): () -> T {
6161
val lock = Any()
6262
var h = hash()
6363
var value = function(h)
6464
return {
6565
val newH = hash()
66-
when {
67-
h === newH -> value
68-
h == newH -> value
69-
else -> synchronized(lock) {
70-
h = newH
71-
value = function(h)
72-
value
73-
}
66+
if (equalityChecker(h, newH)) value else synchronized(lock) {
67+
h = newH
68+
value = function(h)
69+
value
7470
}
7571
}
7672
}

nms/v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4/NMSImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ class NMSImpl : NMS {
358358
player as CraftPlayer
359359
return BasePlayerImpl(
360360
player,
361-
dirtyChecked({ getGameProfile(player.handle) }, { ModelGameProfile(it) }),
361+
dirtyChecked(
362+
{ getGameProfile(player.handle) },
363+
{ ModelGameProfile(it) },
364+
{ a, b -> a == b && a.properties["texture"] === b.properties["texture"]}
365+
),
362366
dirtyChecked({ player.handle.toCustomisation() }, { PlayerSkinParts(it) })
363367
)
364368
}

nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/Functions.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ internal inline fun <reified T, reified R> createAdaptedFieldGetter(): (T) -> R
5353
}
5454
}
5555

56-
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T): () -> T {
56+
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T, equalityChecker: (H, H) -> Boolean = { a, b -> a == b }): () -> T {
5757
val lock = Any()
5858
var h = hash()
5959
var value = function(h)
6060
return {
6161
val newH = hash()
62-
when {
63-
h === newH -> value
64-
h == newH -> value
65-
else -> synchronized(lock) {
66-
h = newH
67-
value = function(h)
68-
value
69-
}
62+
if (equalityChecker(h, newH)) value else synchronized(lock) {
63+
h = newH
64+
value = function(h)
65+
value
7066
}
7167
}
7268
}

nms/v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1/NMSImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ class NMSImpl : NMS {
358358
player as CraftPlayer
359359
return BasePlayerImpl(
360360
player,
361-
dirtyChecked({ getGameProfile(player.handle) }, { ModelGameProfile(it) }),
361+
dirtyChecked(
362+
{ getGameProfile(player.handle) },
363+
{ ModelGameProfile(it) },
364+
{ a, b -> a == b && a.properties["texture"] === b.properties["texture"]}
365+
),
362366
dirtyChecked({ player.handle.toCustomisation() }, { PlayerSkinParts(it) })
363367
)
364368
}

nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/Functions.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ internal inline fun <reified T, reified R> createAdaptedFieldGetter(): (T) -> R
5353
}
5454
}
5555

56-
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T): () -> T {
56+
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T, equalityChecker: (H, H) -> Boolean = { a, b -> a == b }): () -> T {
5757
val lock = Any()
5858
var h = hash()
5959
var value = function(h)
6060
return {
6161
val newH = hash()
62-
when {
63-
h === newH -> value
64-
h == newH -> value
65-
else -> synchronized(lock) {
66-
h = newH
67-
value = function(h)
68-
value
69-
}
62+
if (equalityChecker(h, newH)) value else synchronized(lock) {
63+
h = newH
64+
value = function(h)
65+
value
7066
}
7167
}
7268
}

nms/v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2/NMSImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ class NMSImpl : NMS {
358358
player as CraftPlayer
359359
return BasePlayerImpl(
360360
player,
361-
dirtyChecked({ getGameProfile(player.handle) }, { ModelGameProfile(it) }),
361+
dirtyChecked(
362+
{ getGameProfile(player.handle) },
363+
{ ModelGameProfile(it) },
364+
{ a, b -> a == b && a.properties["texture"] === b.properties["texture"]}
365+
),
362366
dirtyChecked({ player.handle.toCustomisation() }, { PlayerSkinParts(it) })
363367
)
364368
}

nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/Functions.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ internal inline fun <reified T, reified R> createAdaptedFieldGetter(): (T) -> R
5353
}
5454
}
5555

56-
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T): () -> T {
56+
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T, equalityChecker: (H, H) -> Boolean = { a, b -> a == b }): () -> T {
5757
val lock = Any()
5858
var h = hash()
5959
var value = function(h)
6060
return {
6161
val newH = hash()
62-
when {
63-
h === newH -> value
64-
h == newH -> value
65-
else -> synchronized(lock) {
66-
h = newH
67-
value = function(h)
68-
value
69-
}
62+
if (equalityChecker(h, newH)) value else synchronized(lock) {
63+
h = newH
64+
value = function(h)
65+
value
7066
}
7167
}
7268
}

nms/v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3/NMSImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,11 @@ class NMSImpl : NMS {
364364
player as CraftPlayer
365365
return BasePlayerImpl(
366366
player,
367-
dirtyChecked({ getGameProfile(player.handle) }, { ModelGameProfile(it) }),
367+
dirtyChecked(
368+
{ getGameProfile(player.handle) },
369+
{ ModelGameProfile(it) },
370+
{ a, b -> a == b && a.properties["texture"] === b.properties["texture"]}
371+
),
368372
dirtyChecked({ player.handle.toCustomisation() }, { PlayerSkinParts(it) })
369373
)
370374
}

nms/v1_21_R4/src/main/kotlin/kr/toxicity/model/nms/v1_21_R4/Functions.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,16 @@ internal inline fun <reified T, reified R> createAdaptedFieldGetter(): (T) -> R
5353
}
5454
}
5555

56-
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T): () -> T {
56+
internal fun <H, T> dirtyChecked(hash: () -> H, function: (H) -> T, equalityChecker: (H, H) -> Boolean = { a, b -> a == b }): () -> T {
5757
val lock = Any()
5858
var h = hash()
5959
var value = function(h)
6060
return {
6161
val newH = hash()
62-
when {
63-
h === newH -> value
64-
h == newH -> value
65-
else -> synchronized(lock) {
66-
h = newH
67-
value = function(h)
68-
value
69-
}
62+
if (equalityChecker(h, newH)) value else synchronized(lock) {
63+
h = newH
64+
value = function(h)
65+
value
7066
}
7167
}
7268
}

nms/v1_21_R4/src/main/kotlin/kr/toxicity/model/nms/v1_21_R4/NMSImpl.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ class NMSImpl : NMS {
365365
player as CraftPlayer
366366
return BasePlayerImpl(
367367
player,
368-
dirtyChecked({ getGameProfile(player.handle) }, { ModelGameProfile(it) }),
368+
dirtyChecked(
369+
{ getGameProfile(player.handle) },
370+
{ ModelGameProfile(it) },
371+
{ a, b -> a == b && a.properties["texture"] === b.properties["texture"]}
372+
),
369373
dirtyChecked({ player.handle.toCustomisation() }, { PlayerSkinParts(it) })
370374
)
371375
}

0 commit comments

Comments
 (0)