-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(velocity): remove vanished players from server ping
- Loading branch information
Showing
6 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...yanvanish-proxy-velocity/src/main/kotlin/org/sayandev/sayanvanish/velocity/SayanVanish.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...rc/main/kotlin/org/sayandev/sayanvanish/velocity/feature/features/FeatureOnlinePlayers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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.RegisteredFeature | ||
import org.sayandev.sayanvanish.velocity.api.SayanVanishVelocityAPI | ||
import org.sayandev.sayanvanish.velocity.feature.ListenedFeature | ||
import org.sayandev.stickynote.lib.spongepowered.configurate.objectmapping.ConfigSerializable | ||
import kotlin.collections.count | ||
import kotlin.collections.filter | ||
import kotlin.collections.map | ||
import kotlin.collections.toTypedArray | ||
import kotlin.jvm.optionals.getOrNull | ||
|
||
@RegisteredFeature | ||
@ConfigSerializable | ||
class FeatureOnlinePlayers : ListenedFeature("online_players") { | ||
|
||
@Subscribe | ||
fun onProxyPing(event: ProxyPingEvent) { | ||
if (!isActive()) return | ||
val pingPlayers = event.ping.players.getOrNull() ?: return | ||
val onlineVanishedPlayers = SayanVanishVelocityAPI.getInstance().getVanishedUsers(false).filter { it.isOnline } | ||
val nonVanishedPlayersCount = pingPlayers.online - onlineVanishedPlayers.count() | ||
val nonVanishedPlayersSample = pingPlayers.sample.filter { !onlineVanishedPlayers.map { it.username }.contains(it.name) } | ||
event.ping = event.ping | ||
.asBuilder() | ||
.onlinePlayers(nonVanishedPlayersCount) | ||
.samplePlayers(*nonVanishedPlayersSample.map { ServerPing.SamplePlayer(it.name, it.id) }.toTypedArray()) | ||
.build() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ature/hook/FeatureHookEnhancedVelocity.kt → ...tures/hook/FeatureHookEnhancedVelocity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...city/feature/hook/FeatureHookVelocitab.kt → ...ure/features/hook/FeatureHookVelocitab.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters