Skip to content

Commit

Permalink
feat(placeholders): add player_client and player_mods placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Mar 12, 2023
1 parent f75620d commit 2e7b03b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/me/adrianed/clientcatcher/ClientCatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ClientCatcher @Inject constructor(
eventManager.register(this, ModListener(this))
logger.info("Correctly loaded ClientCatcher")
if (pluginManager.isLoaded("miniplaceholders")) {
registerExpansion()
registerExpansion(proxyServer)
}
metrics.make(this, 17830)
}
Expand Down
21 changes: 19 additions & 2 deletions src/main/kotlin/me/adrianed/clientcatcher/Placeholder.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package me.adrianed.clientcatcher

import com.velocitypowered.api.proxy.Player
import com.velocitypowered.api.proxy.ProxyServer
import io.github.miniplaceholders.kotlin.asClosingTag
import io.github.miniplaceholders.kotlin.expansion
import net.kyori.adventure.text.Component.text
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue
import kotlin.jvm.optionals.getOrNull

fun registerExpansion() {
fun registerExpansion(proxyServer: ProxyServer) {
expansion("clientcatcher") {
filter(Player::class.java)
audiencePlaceholder("client") { aud, _, _ -> text((aud as Player).clientBrand ?: "").asClosingTag() }
audiencePlaceholder("mods") { aud, _, _ ->
val mods = (aud as Player).modInfo.getOrNull()?.mods
text(mods?.joinToString(", ") { "${it.id}:${it.version}" } ?: "").asClosingTag()
}
.globalPlaceholder("player_client") { queue, ctx ->
queue.player(proxyServer)?.let { player ->
val mods = player.modInfo.getOrNull()?.mods
text(mods?.joinToString(", ") { "${it.id}:${it.version}" } ?: "").asClosingTag()
} ?: throw ctx.newException("Offline Player provided")
}
.globalPlaceholder("player_mods") { queue, ctx ->
queue.player(proxyServer)?.let {
text(it.clientBrand ?: "").asClosingTag()
} ?: throw ctx.newException("Offline Player provided")
}
}.register()
}
}

fun ArgumentQueue.player(proxyServer: ProxyServer): Player? =
proxyServer.getPlayer(popOr("You need to provide a Player Name").value()).getOrNull()

0 comments on commit 2e7b03b

Please sign in to comment.