11package io.github.rothes.esu.bukkit.module
22
33import io.github.retrooper.packetevents.util.SpigotConversionUtil
4- import io.github.rothes.esu.bukkit.module.networkthrottle.Analyser
54import io.github.rothes.esu.bukkit.module.networkthrottle.ChunkDataThrottle
65import io.github.rothes.esu.bukkit.module.networkthrottle.DynamicChunkSendRate
76import io.github.rothes.esu.bukkit.module.networkthrottle.HighLatencyAdjust
87import io.github.rothes.esu.bukkit.plugin
98import io.github.rothes.esu.bukkit.util.ServerCompatibility
10- import io.github.rothes.esu.core.command.annotation.ShortPerm
119import io.github.rothes.esu.core.configuration.ConfigLoader
1210import io.github.rothes.esu.core.configuration.ConfigurationPart
1311import io.github.rothes.esu.core.configuration.data.MessageData
1412import io.github.rothes.esu.core.configuration.data.MessageData.Companion.message
15- import io.github.rothes.esu.core.configuration.serializer.MapSerializer.DefaultedLinkedHashMap
16- import io.github.rothes.esu.core.module.configuration.BaseModuleConfiguration
17- import io.github.rothes.esu.core.user.User
18- import io.github.rothes.esu.core.util.ComponentUtils.bytes
19- import io.github.rothes.esu.core.util.ComponentUtils.duration
20- import io.github.rothes.esu.core.util.ComponentUtils.unparsed
21- import io.github.rothes.esu.core.util.version.Version
2213import io.github.rothes.esu.core.configuration.meta.Comment
2314import io.github.rothes.esu.core.configuration.meta.RemovedNode
2415import io.github.rothes.esu.core.configuration.meta.RenamedFrom
16+ import io.github.rothes.esu.core.configuration.serializer.MapSerializer.DefaultedLinkedHashMap
17+ import io.github.rothes.esu.core.module.configuration.BaseModuleConfiguration
18+ import io.github.rothes.esu.core.util.version.Version
2519import io.github.rothes.esu.lib.org.spongepowered.configurate.objectmapping.meta.PostProcess
2620import org.bukkit.Material
27- import org.incendo.cloud.annotations.Command
2821import java.time.Duration
2922import java.util.*
30- import kotlin.jvm.java
31- import kotlin.time.Duration.Companion.milliseconds
3223import kotlin.time.toJavaDuration
3324
3425object NetworkThrottleModule: BukkitModule<NetworkThrottleModule.ModuleConfig, NetworkThrottleModule.ModuleLang>(
@@ -40,67 +31,6 @@ object NetworkThrottleModule: BukkitModule<NetworkThrottleModule.ModuleConfig, N
4031
4132 override fun enable () {
4233 data = ConfigLoader .load(dataPath)
43- registerCommands(object {
44- @Command(" network analyser start" )
45- @ShortPerm(" analyser" )
46- fun analyserStart (sender : User ) {
47- if (Analyser .start()) {
48- sender.message(locale, { analyser.started })
49- } else {
50- sender.message(locale, { analyser.alreadyStarted })
51- }
52- }
53-
54- @Command(" network analyser stop" )
55- @ShortPerm(" analyser" )
56- fun analyserStop (sender : User ) {
57- if (Analyser .stop()) {
58- sender.message(locale, { analyser.stopped })
59- } else {
60- sender.message(locale, { analyser.alreadyStopped })
61- }
62- }
63-
64- @Command(" network analyser view" )
65- @ShortPerm(" analyser" )
66- fun analyserView (sender : User ) {
67- val entries = Analyser .records
68- .mapValues {
69- val list = it.value.toList()
70- list.size to list.sumOf { it.size.toLong() }
71- }
72- .entries.sortedByDescending { it.value.second }
73- if (entries.isEmpty()) {
74- sender.message(locale, { analyser.view.noData })
75- return
76- }
77- sender.message(locale, { analyser.view.header })
78- for ((k, entry) in entries.take(7 )) {
79- val (counts, bytes) = entry
80- sender.message(locale, { analyser.view.entry },
81- unparsed(" packet-type" , k.name.lowercase()),
82- unparsed(" counts" , counts),
83- bytes(bytes, " size" ),
84- )
85- }
86- sender.message(locale, { analyser.view.footer },
87- duration(
88- (if (Analyser .running) {
89- System .currentTimeMillis() - Analyser .startTime
90- } else {
91- Analyser .stopTime - Analyser .startTime
92- }).milliseconds, sender
93- ))
94- }
95-
96- @Command(" network chunkDataThrottle view" )
97- @ShortPerm(" chunkDataThrottle" )
98- fun chunkDataThrottleView (sender : User ) {
99- val (minimalChunks, resentChunks, resentBlocks) = ChunkDataThrottle .counter
100- sender.message(" minimalChunks: $minimalChunks ; resentChunks: $resentChunks ; resentBlocks: $resentBlocks " )
101- }
102- })
103- Analyser // Init this
10434 HighLatencyAdjust .onEnable()
10535 ChunkDataThrottle .onEnable()
10636 DynamicChunkSendRate .enable()
@@ -111,7 +41,6 @@ object NetworkThrottleModule: BukkitModule<NetworkThrottleModule.ModuleConfig, N
11141 ChunkDataThrottle .onDisable()
11242 HighLatencyAdjust .onDisable()
11343 DynamicChunkSendRate .disable()
114- Analyser .stop()
11544 ConfigLoader .save(dataPath, data)
11645 }
11746
@@ -276,31 +205,16 @@ object NetworkThrottleModule: BukkitModule<NetworkThrottleModule.ModuleConfig, N
276205
277206 data class ModuleLang (
278207 val highLatencyAdjust : HighLatencyAdjust = HighLatencyAdjust (),
279- val analyser : Analyser = Analyser (),
280208 ): ConfigurationPart {
281209
210+ @RemovedNode
211+ val analyser: Unit? = null
212+
282213 data class HighLatencyAdjust (
283214 val adjustedWarning : MessageData = ("<ec><b>Warning : </b><pc>Your network latency seems to be high. \n" +
284215 "To enhance your experience, we have adjusted your view distance. " +
285216 "You can always adjust it yourself in the game options.").message,
286217 )
287-
288- data class Analyser (
289- val started : MessageData = " <pc>Started the analyser." .message,
290- val stopped : MessageData = " <pc>Stopped the analyser." .message,
291- val alreadyStarted : MessageData = " <ec>The analyser is already running." .message,
292- val alreadyStopped : MessageData = " <ec>The analyser is already stopped." .message,
293-
294- val view : View = View (),
295- ) {
296-
297- data class View (
298- val noData : MessageData = " <pc>There's no data for view." .message,
299- val header : MessageData = " <pdc>[Packet Type]<pc> <pc>[count]</pc>: <sc>[size]" .message,
300- val entry : MessageData = " <tdc><packet-type> <pc>x<pdc><counts></pc><tc>: <sdc><size>" .message,
301- val footer : MessageData = " <pc>The analyser has been running for <duration>" .message,
302- )
303- }
304218 }
305219
306220}
0 commit comments