11package dev.slne.surf.cloud.bukkit.netty.network
22
3+ import com.github.shynixn.mccoroutine.folia.entityDispatcher
34import com.github.shynixn.mccoroutine.folia.globalRegionDispatcher
45import com.github.shynixn.mccoroutine.folia.launch
56import dev.slne.surf.cloud.api.common.player.teleport.TeleportCause
@@ -17,7 +18,6 @@ import dev.slne.surf.cloud.core.common.netty.network.protocol.running.Serverboun
1718import dev.slne.surf.surfapi.bukkit.api.extensions.server
1819import dev.slne.surf.surfapi.bukkit.api.nms.NmsUseWithCaution
1920import dev.slne.surf.surfapi.bukkit.api.nms.bridges.nmsCommonBridge
20- import dev.slne.surf.surfapi.bukkit.api.util.dispatcher
2121import kotlinx.coroutines.flow.launchIn
2222import kotlinx.coroutines.flow.map
2323import kotlinx.coroutines.flow.onEach
@@ -26,28 +26,11 @@ import net.kyori.adventure.text.Component
2626import org.bukkit.Bukkit
2727import java.net.InetAddress
2828import java.net.InetSocketAddress
29- import java.nio.charset.StandardCharsets
3029import java.util.*
31- import kotlin.io.path.Path
32- import kotlin.io.path.inputStream
33- import kotlin.io.path.notExists
3430import org.springframework.stereotype.Component as SpringComponent
3531
3632@SpringComponent
3733class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExtension {
38- private val properties by lazy {
39- val propertiesPath = Path (" server.properties" )
40- if (propertiesPath.notExists()) {
41- Properties ()
42- } else {
43- Properties ().apply {
44- propertiesPath.inputStream().use { inputStream ->
45- load(inputStream)
46- }
47- }
48- }
49- }
50-
5134 override val playAddress: InetSocketAddress by lazy {
5235 InetSocketAddress (InetAddress .getByName(server.ip), server.port)
5336 }
@@ -65,7 +48,7 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
6548
6649 override fun disconnectPlayer (playerUuid : UUID , reason : Component ) {
6750 val player = Bukkit .getPlayer(playerUuid) ? : return
68- plugin.launch(player.dispatcher( )) {
51+ plugin.launch(plugin.entityDispatcher(player )) {
6952 player.kick(reason)
7053 }
7154 }
@@ -104,17 +87,6 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
10487 return player.teleportAsync(targetPlayer.location).await()
10588 }
10689
107- @OptIn(NmsUseWithCaution ::class )
108- override fun setVelocitySecret (secret : ByteArray ) {
109- // nmsCommonBridge.setVelocityEnabled(true)
110- // nmsCommonBridge.setVelocitySecret(secret.toString(StandardCharsets.UTF_8))
111- // nmsCommonBridge.setOnlineMode(false)
112-
113- BukkitVelocitySecretManager .currentVelocityEnabled = true
114- BukkitVelocitySecretManager .currentVelocitySecret = secret
115- BukkitVelocitySecretManager .currentOnlineMode = false
116- }
117-
11890 override fun triggerShutdown () {
11991 plugin.launch(plugin.globalRegionDispatcher) {
12092 Bukkit .shutdown()
@@ -129,6 +101,13 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
129101 server.shutdown()
130102 }
131103
104+ @OptIn(NmsUseWithCaution ::class )
105+ override fun setVelocitySecret (secret : ByteArray ) {
106+ BukkitVelocitySecretManager .currentVelocityEnabled = true
107+ BukkitVelocitySecretManager .currentVelocitySecret = secret
108+ BukkitVelocitySecretManager .currentOnlineMode = false
109+ }
110+
132111 @OptIn(NmsUseWithCaution ::class )
133112 object BukkitVelocitySecretManager {
134113
@@ -138,7 +117,7 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
138117 @Volatile
139118 var currentVelocitySecret = nmsCommonBridge
140119 .getVelocitySecret()
141- .toByteArray(StandardCharsets . UTF_8 )
120+ .toByteArray()
142121
143122 @Volatile
144123 var currentOnlineMode = server.onlineMode
@@ -147,22 +126,18 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
147126 observingFlow({ nmsCommonBridge.isVelocityEnabled() })
148127 .onEach { remote ->
149128 if (remote != currentVelocityEnabled) {
150- println (" Updating Velocity enabled state: $remote " )
151129 nmsCommonBridge.setVelocityEnabled(currentVelocityEnabled)
152130 }
153131 }
154132 .launchIn(CommonObservableScope )
155133
156134
157135 observingFlow({ nmsCommonBridge.getVelocitySecret() })
158- .map { it.toByteArray(StandardCharsets . UTF_8 ) }
136+ .map { it.toByteArray() }
159137 .onEach { remote ->
160138 if (! remote.contentEquals(currentVelocitySecret)) {
161- println (" Updating Velocity secret: ${remote.toString(StandardCharsets .UTF_8 )} " )
162139 nmsCommonBridge.setVelocitySecret(
163- currentVelocitySecret.toString(
164- StandardCharsets .UTF_8
165- )
140+ currentVelocitySecret.decodeToString()
166141 )
167142 }
168143 }
@@ -171,7 +146,6 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
171146 observingFlow({ server.onlineMode })
172147 .onEach { remote ->
173148 if (remote != currentOnlineMode) {
174- println (" Updating online mode: $remote " )
175149 nmsCommonBridge.setOnlineMode(remote)
176150 }
177151 }
0 commit comments