-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(placeholders): add player_client and player_mods placeholders
- Loading branch information
Showing
2 changed files
with
20 additions
and
3 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
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() | ||
|