Skip to content

Commit 2c562cb

Browse files
committed
Rename ChannelInjectionManager
1 parent c2fcfa1 commit 2c562cb

5 files changed

Lines changed: 25 additions & 26 deletions

File tree

velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/NetworkThrottleModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.github.rothes.esu.core.util.NetworkUtils
1010
import io.github.rothes.esu.velocity.module.networkthrottle.Analyser
1111
import io.github.rothes.esu.velocity.module.networkthrottle.DynamicChunkSendRate
1212
import io.github.rothes.esu.velocity.module.networkthrottle.TrafficMonitor
13-
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectorController
13+
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectionManager
1414
import io.github.rothes.esu.velocity.util.extension.checkPacketEvents
1515

1616
object NetworkThrottleModule: VelocityModule<NetworkThrottleModule.ModuleConfig, NetworkThrottleModule.ModuleLang>() {
@@ -20,15 +20,15 @@ object NetworkThrottleModule: VelocityModule<NetworkThrottleModule.ModuleConfig,
2020
}
2121

2222
override fun onEnable() {
23-
ChannelInjectorController.enable()
23+
ChannelInjectionManager.enable()
2424
TrafficMonitor.enable()
2525
Analyser.enable()
2626
DynamicChunkSendRate.enable()
2727
}
2828

2929
override fun onDisable() {
3030
super.onDisable()
31-
ChannelInjectorController.disable()
31+
ChannelInjectionManager.disable()
3232
TrafficMonitor.disable()
3333
Analyser.disable()
3434
Analyser.reset()

velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/networkthrottle/Analyser.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.github.rothes.esu.core.util.ComponentUtils.unparsed
1212
import io.github.rothes.esu.core.util.NetworkUtils
1313
import io.github.rothes.esu.velocity.module.NetworkThrottleModule
1414
import io.github.rothes.esu.velocity.module.NetworkThrottleModule.lang
15-
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectorController
15+
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectionManager
1616
import io.github.rothes.esu.velocity.module.networkthrottle.channel.DecoderChannelHandler
1717
import io.github.rothes.esu.velocity.module.networkthrottle.channel.EncoderChannelHandler
1818
import io.github.rothes.esu.velocity.module.networkthrottle.channel.PacketData
@@ -38,8 +38,8 @@ object Analyser {
3838
if (running) return false
3939
running = true
4040
reset()
41-
ChannelInjectorController.registerHandler(EncoderHandler)
42-
ChannelInjectorController.registerHandler(DecoderHandler)
41+
ChannelInjectionManager.registerHandler(EncoderHandler)
42+
ChannelInjectionManager.registerHandler(DecoderHandler)
4343
return true
4444
}
4545

@@ -143,8 +143,8 @@ object Analyser {
143143
if (!running) return false
144144
running = false
145145
stopTime = System.currentTimeMillis()
146-
ChannelInjectorController.unregisterHandler(EncoderHandler)
147-
ChannelInjectorController.unregisterHandler(DecoderHandler)
146+
ChannelInjectionManager.unregisterHandler(EncoderHandler)
147+
ChannelInjectionManager.unregisterHandler(DecoderHandler)
148148
return true
149149
}
150150

velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/networkthrottle/DynamicChunkSendRate.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier
88
import com.velocitypowered.api.scheduler.ScheduledTask
99
import io.github.rothes.esu.velocity.module.NetworkThrottleModule
1010
import io.github.rothes.esu.velocity.module.NetworkThrottleModule.config
11-
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectorController
11+
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectionManager
1212
import io.github.rothes.esu.velocity.module.networkthrottle.channel.EncoderChannelHandler
1313
import io.github.rothes.esu.velocity.module.networkthrottle.channel.PacketData
1414
import io.github.rothes.esu.velocity.plugin
@@ -35,7 +35,7 @@ object DynamicChunkSendRate {
3535
}
3636
}.repeat(Duration.ofSeconds(1)).schedule()
3737
TrafficMonitor.forceRecord()
38-
ChannelInjectorController.registerHandler(EncoderHandler)
38+
ChannelInjectionManager.registerHandler(EncoderHandler)
3939
}
4040
}
4141

@@ -44,7 +44,7 @@ object DynamicChunkSendRate {
4444
task?.cancel()
4545
task = null
4646
TrafficMonitor.cancelForceRecord()
47-
ChannelInjectorController.unregisterHandler(EncoderHandler)
47+
ChannelInjectionManager.unregisterHandler(EncoderHandler)
4848
traffic.clear()
4949
}
5050
}

velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/networkthrottle/TrafficMonitor.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.github.rothes.esu.core.util.NetworkUtils
1111
import io.github.rothes.esu.velocity.module.NetworkThrottleModule
1212
import io.github.rothes.esu.velocity.module.NetworkThrottleModule.config
1313
import io.github.rothes.esu.velocity.module.NetworkThrottleModule.lang
14-
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectorController
14+
import io.github.rothes.esu.velocity.module.networkthrottle.channel.ChannelInjectionManager
1515
import io.github.rothes.esu.velocity.module.networkthrottle.channel.DecoderChannelHandler
1616
import io.github.rothes.esu.velocity.module.networkthrottle.channel.EncoderChannelHandler
1717
import io.github.rothes.esu.velocity.module.networkthrottle.channel.PacketData
@@ -99,30 +99,30 @@ object TrafficMonitor {
9999
NetworkThrottleModule.unregisterListener(Listeners)
100100
if (viewers.isNotEmpty()) {
101101
viewers.clear()
102-
ChannelInjectorController.unregisterHandler(EncoderHandler)
103-
ChannelInjectorController.unregisterHandler(DecoderHandler)
102+
ChannelInjectionManager.unregisterHandler(EncoderHandler)
103+
ChannelInjectionManager.unregisterHandler(DecoderHandler)
104104
}
105105
}
106106

107107
fun forceRecord() {
108108
if (forceRun.getAndAdd(1) == 0) {
109-
ChannelInjectorController.registerHandler(EncoderHandler)
110-
ChannelInjectorController.registerHandler(DecoderHandler)
109+
ChannelInjectionManager.registerHandler(EncoderHandler)
110+
ChannelInjectionManager.registerHandler(DecoderHandler)
111111
}
112112
}
113113

114114
fun cancelForceRecord() {
115115
if (forceRun.addAndGet(-1) == 0 && viewers.isEmpty()) {
116-
ChannelInjectorController.unregisterHandler(EncoderHandler)
117-
ChannelInjectorController.unregisterHandler(DecoderHandler)
116+
ChannelInjectionManager.unregisterHandler(EncoderHandler)
117+
ChannelInjectionManager.unregisterHandler(DecoderHandler)
118118
}
119119
}
120120

121121
fun addViewer(user: User, unit: Unit) {
122122
synchronized(viewers) {
123123
if (viewers.isEmpty()) {
124-
ChannelInjectorController.registerHandler(EncoderHandler)
125-
ChannelInjectorController.registerHandler(DecoderHandler)
124+
ChannelInjectionManager.registerHandler(EncoderHandler)
125+
ChannelInjectionManager.registerHandler(DecoderHandler)
126126
}
127127
viewers[user] = unit
128128
}
@@ -132,8 +132,8 @@ object TrafficMonitor {
132132
synchronized(viewers) {
133133
viewers.remove(user)
134134
if (viewers.isEmpty() && forceRun.get() == 0) {
135-
ChannelInjectorController.unregisterHandler(EncoderHandler)
136-
ChannelInjectorController.unregisterHandler(DecoderHandler)
135+
ChannelInjectionManager.unregisterHandler(EncoderHandler)
136+
ChannelInjectionManager.unregisterHandler(DecoderHandler)
137137
}
138138
}
139139
}

velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/networkthrottle/channel/ChannelInjectorController.kt renamed to velocity/src/main/kotlin/io/github/rothes/esu/velocity/module/networkthrottle/channel/ChannelInjectionManager.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.velocitypowered.api.proxy.Player
1212
import com.velocitypowered.proxy.VelocityServer
1313
import com.velocitypowered.proxy.connection.client.ConnectedPlayer
1414
import com.velocitypowered.proxy.network.ConnectionManager
15+
import io.github.rothes.esu.core.util.ReflectionUtils.accessibleGetT
1516
import io.github.rothes.esu.core.util.ReflectionUtils.handle
1617
import io.github.rothes.esu.velocity.module.NetworkThrottleModule
1718
import io.github.rothes.esu.velocity.module.networkthrottle.UnknownPacketType
@@ -20,14 +21,12 @@ import io.netty.buffer.ByteBuf
2021
import io.netty.channel.*
2122
import com.github.retrooper.packetevents.protocol.player.User as PEUser
2223

23-
object ChannelInjectorController {
24+
object ChannelInjectionManager {
2425

2526
val connectionManager by lazy {
26-
val server = plugin.server as VelocityServer
2727
VelocityServer::class.java.declaredFields
2828
.first { it.type == ConnectionManager::class.java }
29-
.also { it.isAccessible = true }
30-
.get(server) as ConnectionManager
29+
.accessibleGetT<ConnectionManager>(plugin.server as VelocityServer)
3130
}
3231

3332
private val allInjectors = linkedSetOf<ChannelInjector>()

0 commit comments

Comments
 (0)