Skip to content

Commit 52f873a

Browse files
committed
refactor: simplify channel handling
1 parent 5c62df0 commit 52f873a

File tree

8 files changed

+17
-30
lines changed
  • core/src/main/kotlin/kr/toxicity/model/manager
  • nms
    • v1_20_R4/src/main/kotlin/kr/toxicity/model/nms/v1_20_R4
    • v1_21_R1/src/main/kotlin/kr/toxicity/model/nms/v1_21_R1
    • v1_21_R2/src/main/kotlin/kr/toxicity/model/nms/v1_21_R2
    • v1_21_R3/src/main/kotlin/kr/toxicity/model/nms/v1_21_R3
    • v1_21_R4/src/main/kotlin/kr/toxicity/model/nms/v1_21_R4
    • v1_21_R5/src/main/kotlin/kr/toxicity/model/nms/v1_21_R5
    • v1_21_R6/src/main/kotlin/kr/toxicity/model/nms/v1_21_R6

8 files changed

+17
-30
lines changed

core/src/main/kotlin/kr/toxicity/model/manager/PlayerManagerImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import kr.toxicity.model.util.handleFailure
1414
import kr.toxicity.model.util.registerListener
1515
import org.bukkit.entity.Player
1616
import org.bukkit.event.EventHandler
17+
import org.bukkit.event.EventPriority
1718
import org.bukkit.event.Listener
1819
import org.bukkit.event.player.PlayerJoinEvent
1920
import org.bukkit.event.player.PlayerQuitEvent
@@ -26,15 +27,15 @@ object PlayerManagerImpl : PlayerManager, GlobalManager {
2627

2728
override fun start() {
2829
registerListener(object : Listener {
29-
@EventHandler
30+
@EventHandler(priority = EventPriority.HIGHEST)
3031
fun PlayerJoinEvent.join() {
3132
if (player.isOnline) runCatching { //For fake player
3233
player.register()
3334
}.handleFailure {
3435
"Unable to load ${player.name}'s data."
3536
}
3637
}
37-
@EventHandler
38+
@EventHandler(priority = EventPriority.MONITOR)
3839
fun PlayerQuitEvent.quit() {
3940
playerMap.remove(player.uniqueId)?.use {
4041
SkinManagerImpl.removeCache(it.profile())

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ class NMSImpl : NMS {
133133
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
134134

135135
init {
136-
val pipeLine = getConnection(connection).channel.pipeline()
137-
pipeLine.toMap().forEach {
138-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
139-
}
136+
val pipeline = getConnection(connection).channel.pipeline()
137+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
140138
}
141139

142140
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ class NMSImpl : NMS {
133133
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
134134

135135
init {
136-
val pipeLine = getConnection(connection).channel.pipeline()
137-
pipeLine.toMap().forEach {
138-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
139-
}
136+
val pipeline = getConnection(connection).channel.pipeline()
137+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
140138
}
141139

142140
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ class NMSImpl : NMS {
133133
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
134134

135135
init {
136-
val pipeLine = getConnection(connection).channel.pipeline()
137-
pipeLine.toMap().forEach {
138-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
139-
}
136+
val pipeline = getConnection(connection).channel.pipeline()
137+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
140138
}
141139

142140
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ class NMSImpl : NMS {
136136
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
137137

138138
init {
139-
val pipeLine = getConnection(connection).channel.pipeline()
140-
pipeLine.toMap().forEach {
141-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
142-
}
139+
val pipeline = getConnection(connection).channel.pipeline()
140+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
143141
}
144142

145143
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ class NMSImpl : NMS {
135135
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
136136

137137
init {
138-
val pipeLine = getConnection(connection).channel.pipeline()
139-
pipeLine.toMap().forEach {
140-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
141-
}
138+
val pipeline = getConnection(connection).channel.pipeline()
139+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
142140
}
143141

144142
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ class NMSImpl : NMS {
135135
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
136136

137137
init {
138-
val pipeLine = getConnection(connection).channel.pipeline()
139-
pipeLine.toMap().forEach {
140-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
141-
}
138+
val pipeline = getConnection(connection).channel.pipeline()
139+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
142140
}
143141

144142
override fun isSlim(): Boolean = slim

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ class NMSImpl : NMS {
136136
private val slim = BetterModel.plugin().skinManager().isSlim(profile())
137137

138138
init {
139-
val pipeLine = getConnection(connection).channel.pipeline()
140-
pipeLine.toMap().forEach {
141-
if (it.value is Connection) pipeLine.addBefore(it.key, INJECT_NAME, this)
142-
}
139+
val pipeline = getConnection(connection).channel.pipeline()
140+
pipeline.addBefore(pipeline.first { it.value is Connection }.key, INJECT_NAME, this)
143141
}
144142

145143
override fun isSlim(): Boolean = slim

0 commit comments

Comments
 (0)