Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ package org.sayandev.sayanvanish.velocity.feature.features
import com.velocitypowered.api.event.Subscribe
import com.velocitypowered.api.event.proxy.ProxyPingEvent
import com.velocitypowered.api.proxy.server.ServerPing
import org.sayandev.sayanvanish.api.feature.Configurable
import org.sayandev.sayanvanish.api.feature.RegisteredFeature
import org.sayandev.sayanvanish.velocity.api.SayanVanishVelocityAPI
import org.sayandev.sayanvanish.velocity.feature.ListenedFeature
import org.spongepowered.configurate.objectmapping.ConfigSerializable
import org.spongepowered.configurate.objectmapping.meta.Comment
import kotlin.jvm.optionals.getOrNull

@RegisteredFeature
@ConfigSerializable
class FeatureUpdatePing : ListenedFeature("update_ping") {
class FeatureUpdatePing(
@Comment("List of server names whose players are counted toward the online player count. If empty, players from all servers will be counted.")
@Configurable val servers: List<String> = emptyList()
) : ListenedFeature("update_ping") {

@Subscribe
fun onProxyPing(event: ProxyPingEvent) {
if (!isActive()) return
val pingPlayers = event.ping.players.getOrNull() ?: return
val vanishedOnlineUsers = SayanVanishVelocityAPI.getInstance().database.getUsers().filter { user -> user.isVanished && user.isOnline }
val vanishedOnlineUsersNames = vanishedOnlineUsers.map { vanishUser -> vanishUser.username }
val vanishedOnlineUsers = SayanVanishVelocityAPI.getInstance().database.getUsers().filter { user -> user.isVanished && user.isOnline && (servers.isEmpty() || user.serverId in servers) }
val vanishedOnlineUsersNames = vanishedOnlineUsers.map { vanishUser -> vanishUser.username }.toSet()
val nonVanishedPlayersCount = SayanVanishVelocityAPI.getInstance().database.getBasicUsers(true).filter { basicUser ->
!vanishedOnlineUsersNames.contains(basicUser.username)
(servers.isEmpty() || basicUser.serverId in servers) &&
!vanishedOnlineUsersNames.contains(basicUser.username)
}.size
val nonVanishedPlayersSample = pingPlayers.sample.filter { pingPlayer ->
!vanishedOnlineUsersNames.contains(pingPlayer.name)
}

event.ping = event.ping
.asBuilder()
.onlinePlayers(nonVanishedPlayersCount)
Expand Down