Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit d35eae2

Browse files
committed
feat: implement pullPlayersToGroup handling in server-client interaction
- Added method `handlePullPlayersToGroup` in `RunningServerPacketListener`. - Updated `ServerboundPullPlayersToGroupPacket` to handle player grouping requests. - Refactored punishment-related logic to use `Either` for result or error handling. - Adjusted collection types to improve consistency (e.g., `List` to `Set`, `Collection` to `Iterable`).
1 parent 25b2c70 commit d35eae2

File tree

12 files changed

+98
-59
lines changed

12 files changed

+98
-59
lines changed

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/server/CloudServerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface CloudServerManager {
6464

6565
suspend fun pullPlayersToGroup(
6666
group: String,
67-
players: Collection<CloudPlayer>
67+
players: Iterable<CloudPlayer>
6868
): @Unmodifiable ObjectList<Pair<CloudPlayer, ConnectionResultEnum>>
6969

7070
suspend fun broadcastToGroup(

surf-cloud-bukkit/src/main/kotlin/dev/slne/surf/cloud/bukkit/command/punish/PunishCommand.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private fun executeBanCommand(
111111
(sender as? Player)?.uniqueId
112112
)
113113
} else {
114+
@Suppress("DEPRECATION")
114115
player.punishmentManager.punish(
115116
PunishType.BAN.Raw,
116117
null,

surf-cloud-bukkit/src/main/kotlin/dev/slne/surf/cloud/bukkit/netty/network/BukkitSpecificPacketListenerExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BukkitSpecificPacketListenerExtension : PlatformSpecificPacketListenerExte
6969
return Companion.teleportPlayer(uuid, location, teleportCause, flags)
7070
}
7171

72-
override fun registerCloudServerToProxy(info: Array<RegistrationInfo>) = Unit
72+
override fun registerCloudServerToProxy(info: RegistrationInfo) = Unit
7373
override fun registerCloudServerToProxy(client: ClientCloudServerImpl) = Unit
7474
override fun unregisterCloudServerFromProxy(client: ClientCloudServerImpl) = Unit
7575

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/player/PunishmentManagerImpl.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package dev.slne.surf.cloud.core.client.player
22

33
import dev.slne.surf.cloud.api.client.netty.packet.awaitOrThrow
44
import dev.slne.surf.cloud.api.client.netty.packet.fireAndAwaitOrThrow
5-
import dev.slne.surf.cloud.api.common.player.punishment.type.PunishmentAttachedIpAddress.PunishmentAttachedIpAddressImpl
5+
import dev.slne.surf.cloud.api.common.player.punishment.type.PunishmentAttachedIpAddress
66
import dev.slne.surf.cloud.api.common.player.punishment.type.PunishmentType
7-
import dev.slne.surf.cloud.api.common.player.punishment.type.note.PunishmentNote.PunishmentNoteImpl
7+
import dev.slne.surf.cloud.api.common.player.punishment.type.note.PunishmentNote
88
import dev.slne.surf.cloud.core.common.netty.network.protocol.running.*
99
import dev.slne.surf.cloud.core.common.player.PunishmentCacheImpl
1010
import dev.slne.surf.cloud.core.common.player.PunishmentManager
1111
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentBanImpl
1212
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentKickImpl
1313
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentMuteImpl
1414
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentWarnImpl
15+
import dev.slne.surf.surfapi.core.api.util.toMutableObjectList
1516
import org.springframework.stereotype.Component
1617
import java.time.ZonedDateTime
1718
import java.util.*
@@ -31,7 +32,7 @@ class PunishmentManagerImpl : PunishmentManager {
3132
punishedUuid,
3233
issuerUuid,
3334
reason,
34-
initialNotes,
35+
initialNotes.toMutableObjectList(),
3536
parentId
3637
).fireAndAwaitOrThrow().punishment as PunishmentKickImpl
3738

@@ -45,7 +46,7 @@ class PunishmentManagerImpl : PunishmentManager {
4546
punishedUuid,
4647
issuerUuid,
4748
reason,
48-
initialNotes,
49+
initialNotes.toMutableObjectList(),
4950
parentId
5051
).fireAndAwaitOrThrow().punishment as PunishmentWarnImpl
5152

@@ -63,7 +64,7 @@ class PunishmentManagerImpl : PunishmentManager {
6364
reason,
6465
permanent,
6566
expirationDate,
66-
initialNotes,
67+
initialNotes.toMutableObjectList(),
6768
parentId
6869
).fireAndAwaitOrThrow().punishment as PunishmentMuteImpl
6970

@@ -86,8 +87,8 @@ class PunishmentManagerImpl : PunishmentManager {
8687
expirationDate,
8788
securityBan,
8889
raw,
89-
initialNotes,
90-
initialIpAddresses,
90+
initialNotes.toMutableObjectList(),
91+
initialIpAddresses.toMutableObjectList(),
9192
parentId
9293
).fireAndAwaitOrThrow().punishment as PunishmentBanImpl
9394

@@ -130,7 +131,7 @@ class PunishmentManagerImpl : PunishmentManager {
130131
override suspend fun attachNoteToBan(
131132
id: Long,
132133
note: String
133-
): PunishmentNoteImpl =
134+
): PunishmentNote =
134135
ServerboundAttachNoteToPunishmentPacket(
135136
id,
136137
note,
@@ -141,7 +142,7 @@ class PunishmentManagerImpl : PunishmentManager {
141142
override suspend fun attachNoteToMute(
142143
id: Long,
143144
note: String
144-
): PunishmentNoteImpl =
145+
): PunishmentNote =
145146
ServerboundAttachNoteToPunishmentPacket(
146147
id,
147148
note,
@@ -151,7 +152,7 @@ class PunishmentManagerImpl : PunishmentManager {
151152
override suspend fun attachNoteToKick(
152153
id: Long,
153154
note: String
154-
): PunishmentNoteImpl =
155+
): PunishmentNote =
155156
ServerboundAttachNoteToPunishmentPacket(
156157
id,
157158
note,
@@ -161,38 +162,38 @@ class PunishmentManagerImpl : PunishmentManager {
161162
override suspend fun attachNoteToWarn(
162163
id: Long,
163164
note: String
164-
): PunishmentNoteImpl =
165+
): PunishmentNote =
165166
ServerboundAttachNoteToPunishmentPacket(
166167
id,
167168
note,
168169
PunishmentType.WARN
169170
).fireAndAwaitOrThrow().note
170171

171-
override suspend fun fetchNotesForBan(id: Long): List<PunishmentNoteImpl> =
172+
override suspend fun fetchNotesForBan(id: Long): List<PunishmentNote> =
172173
ServerboundFetchNotesFromPunishmentPacket(
173174
id,
174175
PunishmentType.BAN
175176
).fireAndAwaitOrThrow().notes
176177

177-
override suspend fun fetchNotesForMute(id: Long): List<PunishmentNoteImpl> =
178+
override suspend fun fetchNotesForMute(id: Long): List<PunishmentNote> =
178179
ServerboundFetchNotesFromPunishmentPacket(
179180
id,
180181
PunishmentType.MUTE
181182
).fireAndAwaitOrThrow().notes
182183

183-
override suspend fun fetchNotesForKick(id: Long): List<PunishmentNoteImpl> =
184+
override suspend fun fetchNotesForKick(id: Long): List<PunishmentNote> =
184185
ServerboundFetchNotesFromPunishmentPacket(
185186
id,
186187
PunishmentType.KICK
187188
).fireAndAwaitOrThrow().notes
188189

189-
override suspend fun fetchNotesForWarn(id: Long): List<PunishmentNoteImpl> =
190+
override suspend fun fetchNotesForWarn(id: Long): List<PunishmentNote> =
190191
ServerboundFetchNotesFromPunishmentPacket(
191192
id,
192193
PunishmentType.WARN
193194
).fireAndAwaitOrThrow().notes
194195

195-
override suspend fun fetchIpAddressesForBan(id: Long): List<PunishmentAttachedIpAddressImpl> {
196+
override suspend fun fetchIpAddressesForBan(id: Long): List<PunishmentAttachedIpAddress> {
196197
return ServerboundFetchIpAddressesForBanPacket(id).fireAndAwaitOrThrow().ipAddresses
197198
}
198199

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/server/ClientCloudServerManagerImpl.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import dev.slne.surf.cloud.api.client.netty.packet.fireAndAwaitOrThrow
55
import dev.slne.surf.cloud.api.client.server.CloudClientServerManager
66
import dev.slne.surf.cloud.api.common.config.properties.CloudProperties
77
import dev.slne.surf.cloud.api.common.player.CloudPlayer
8-
import dev.slne.surf.cloud.api.common.player.CloudPlayerManager
98
import dev.slne.surf.cloud.api.common.player.ConnectionResultEnum
109
import dev.slne.surf.cloud.api.common.server.CloudServer
1110
import dev.slne.surf.cloud.api.common.server.CloudServerManager
@@ -16,6 +15,7 @@ import dev.slne.surf.cloud.core.common.netty.network.protocol.running.Serverboun
1615
import dev.slne.surf.cloud.core.common.server.CommonCloudServerImpl
1716
import dev.slne.surf.cloud.core.common.server.CommonCloudServerManagerImpl
1817
import dev.slne.surf.surfapi.core.api.util.mutableObjectListOf
18+
import dev.slne.surf.surfapi.core.api.util.mutableObjectSetOf
1919
import it.unimi.dsi.fastutil.objects.ObjectList
2020
import org.jetbrains.annotations.Unmodifiable
2121
import kotlin.time.Duration
@@ -45,16 +45,20 @@ class ClientCloudServerManagerImpl : CommonCloudServerManagerImpl<CommonCloudSer
4545

4646
override suspend fun pullPlayersToGroup(
4747
group: String,
48-
players: Collection<CloudPlayer>
48+
players: Iterable<CloudPlayer>
4949
): @Unmodifiable ObjectList<Pair<CloudPlayer, ConnectionResultEnum>> {
50-
return ServerboundPullPlayersToGroupPacket(
51-
group,
52-
players.map { it.uuid }
53-
).fireAndAwaitOrThrow(Duration.INFINITE)
54-
.results
55-
.mapNotNullTo(mutableObjectListOf()) { (uuid, result) ->
56-
CloudPlayerManager.getPlayer(uuid)?.let { it to result }
50+
val uuids = players.mapTo(mutableObjectSetOf()) { it.uuid }
51+
val resultOrException = ServerboundPullPlayersToGroupPacket(group, uuids)
52+
.fireAndAwaitOrThrow(Duration.INFINITE) // we will always get a response or something went terribly wrong
53+
.result
54+
55+
return resultOrException.map({ result ->
56+
result.mapNotNullTo(mutableObjectListOf()) { (uuid, result) ->
57+
CloudPlayer[uuid]?.let { it to result }
5758
}
59+
}, { errorMessage ->
60+
throw IllegalStateException("Failed to pull players to group '$group': $errorMessage")
61+
})
5862
}
5963
}
6064

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/running/RunningServerPacketListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ interface RunningServerPacketListener :
9999

100100
fun handleRefreshWhitelist(packet: ServerboundRefreshWhitelistPacket)
101101

102+
fun handlePullPlayersToGroup(packet: ServerboundPullPlayersToGroupPacket)
103+
102104
fun handleCacheRegisterKeys(packet: ServerboundCacheRegisterKeysPacket)
103105
fun handleCacheOp(packet: ServerboundCacheOpPacket)
104106
fun handleCacheFetch(packet: ServerboundCacheFetchPacket)

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/running/ServerboundFetchPunishmentPackets.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,12 @@ data class ServerboundFetchWarnsPacket(val punishedUuid: UUID) :
135135

136136

137137
@SurfNettyPacket("cloud:clientbound:fetch_punishments_response", PacketFlow.CLIENTBOUND)
138-
class ClientboundFetchedPunishmentsResponsePacket(val punishments: MutableList<AbstractPunishment>) :
138+
class ClientboundFetchedPunishmentsResponsePacket(val punishments: List<AbstractPunishment>) :
139139
ResponseNettyPacket() {
140140
companion object {
141141
val STREAM_CODEC = AbstractPunishment.STREAM_CODEC
142142
.apply(ByteBufCodecs.list())
143+
.apply(ByteBufCodecs.makeImmutableList())
143144
.map(
144145
::ClientboundFetchedPunishmentsResponsePacket,
145146
ClientboundFetchedPunishmentsResponsePacket::punishments

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/running/ServerboundPullPlayersToGroupPacket.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,40 @@ import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
77
import dev.slne.surf.cloud.api.common.netty.packet.RespondingNettyPacket
88
import dev.slne.surf.cloud.api.common.netty.packet.ResponseNettyPacket
99
import dev.slne.surf.cloud.api.common.player.ConnectionResultEnum
10+
import dev.slne.surf.cloud.api.common.util.Either
11+
import dev.slne.surf.cloud.core.common.netty.network.InternalNettyPacket
1012
import java.util.*
1113

1214
@SurfNettyPacket("cloud:serverbound:pull_players_to_group", PacketFlow.SERVERBOUND)
1315
class ServerboundPullPlayersToGroupPacket(
1416
val group: String,
15-
val players: MutableList<UUID>
16-
) : RespondingNettyPacket<PullPlayersToGroupResponsePacket>() {
17+
val players: MutableSet<UUID>
18+
) : RespondingNettyPacket<PullPlayersToGroupResponsePacket>(),
19+
InternalNettyPacket<RunningServerPacketListener> {
1720
companion object {
1821
val STREAM_CODEC = StreamCodec.composite(
1922
ByteBufCodecs.STRING_CODEC,
2023
ServerboundPullPlayersToGroupPacket::group,
21-
ByteBufCodecs.UUID_CODEC.apply(ByteBufCodecs.list()),
24+
ByteBufCodecs.UUID_CODEC.apply(ByteBufCodecs.set()),
2225
ServerboundPullPlayersToGroupPacket::players,
2326
::ServerboundPullPlayersToGroupPacket
2427
)
2528
}
29+
30+
override fun handle(listener: RunningServerPacketListener) {
31+
listener.handlePullPlayersToGroup(this)
32+
}
2633
}
2734

2835
@SurfNettyPacket("cloud:response:pull_players_to_group_response", PacketFlow.CLIENTBOUND)
29-
class PullPlayersToGroupResponsePacket(val results: MutableList<Pair<UUID, ConnectionResultEnum>>) :
36+
class PullPlayersToGroupResponsePacket(val result: Either<MutableList<Pair<UUID, ConnectionResultEnum>>, String?>) :
3037
ResponseNettyPacket() {
3138
companion object {
32-
val STREAM_CODEC = ByteBufCodecs
33-
.pair(ByteBufCodecs.UUID_CODEC, ConnectionResultEnum.STREAM_CODEC)
34-
.apply(ByteBufCodecs.list())
35-
.map(::PullPlayersToGroupResponsePacket, PullPlayersToGroupResponsePacket::results)
39+
val STREAM_CODEC = ByteBufCodecs.either(
40+
ByteBufCodecs
41+
.pair(ByteBufCodecs.UUID_CODEC, ConnectionResultEnum.STREAM_CODEC)
42+
.apply(ByteBufCodecs.list()),
43+
ByteBufCodecs.STRING_CODEC.apply(ByteBufCodecs::nullable),
44+
).map(::PullPlayersToGroupResponsePacket, PullPlayersToGroupResponsePacket::result)
3645
}
3746
}

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/player/PunishmentManager.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.slne.surf.cloud.core.common.player
22

3-
import dev.slne.surf.cloud.api.common.player.punishment.type.PunishmentAttachedIpAddress.PunishmentAttachedIpAddressImpl
4-
import dev.slne.surf.cloud.api.common.player.punishment.type.note.PunishmentNote.PunishmentNoteImpl
3+
import dev.slne.surf.cloud.api.common.player.punishment.type.PunishmentAttachedIpAddress
4+
import dev.slne.surf.cloud.api.common.player.punishment.type.note.PunishmentNote
55
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentBanImpl
66
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentKickImpl
77
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentMuteImpl
@@ -64,17 +64,17 @@ interface PunishmentManager {
6464

6565
suspend fun attachIpAddressToBan(id: Long, rawIp: String): Boolean
6666

67-
suspend fun attachNoteToBan(id: Long, note: String): PunishmentNoteImpl
68-
suspend fun attachNoteToMute(id: Long, note: String): PunishmentNoteImpl
69-
suspend fun attachNoteToKick(id: Long, note: String): PunishmentNoteImpl
70-
suspend fun attachNoteToWarn(id: Long, note: String): PunishmentNoteImpl
67+
suspend fun attachNoteToBan(id: Long, note: String): PunishmentNote
68+
suspend fun attachNoteToMute(id: Long, note: String): PunishmentNote
69+
suspend fun attachNoteToKick(id: Long, note: String): PunishmentNote
70+
suspend fun attachNoteToWarn(id: Long, note: String): PunishmentNote
7171

72-
suspend fun fetchNotesForBan(id: Long): List<PunishmentNoteImpl>
73-
suspend fun fetchNotesForMute(id: Long): List<PunishmentNoteImpl>
74-
suspend fun fetchNotesForKick(id: Long): List<PunishmentNoteImpl>
75-
suspend fun fetchNotesForWarn(id: Long): List<PunishmentNoteImpl>
72+
suspend fun fetchNotesForBan(id: Long): List<PunishmentNote>
73+
suspend fun fetchNotesForMute(id: Long): List<PunishmentNote>
74+
suspend fun fetchNotesForKick(id: Long): List<PunishmentNote>
75+
suspend fun fetchNotesForWarn(id: Long): List<PunishmentNote>
7676

77-
suspend fun fetchIpAddressesForBan(id: Long): List<PunishmentAttachedIpAddressImpl>
77+
suspend fun fetchIpAddressesForBan(id: Long): List<PunishmentAttachedIpAddress>
7878

7979
suspend fun fetchMutes(punishedUuid: UUID, onlyActive: Boolean): List<PunishmentMuteImpl>
8080
suspend fun fetchBans(punishedUuid: UUID, onlyActive: Boolean): List<PunishmentBanImpl>

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/netty/server/ServerClientImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dev.slne.surf.cloud.standalone.netty.server.network.ServerRunningPacketLi
77
import java.net.InetSocketAddress
88

99
class ServerClientImpl(
10-
val server: NettyServerImpl,
10+
val nettyServer: NettyServerImpl,
1111
serverCategory: String,
1212
serverName: String,
1313
val lobbyServer: Boolean,
@@ -26,7 +26,7 @@ class ServerClientImpl(
2626
}
2727

2828
override fun broadcast(packets: List<NettyPacket>) {
29-
server.connection.broadcast(packets)
29+
nettyServer.connection.broadcast(packets)
3030
}
3131

3232
companion object {

0 commit comments

Comments
 (0)