SystemPlaceholders is a lightweight annotation-based system for registering and managing custom placeholders compatible with PlaceholderAPI.
You can include SystemPlaceholders in your project by adding the following dependency to your build.gradle file, you can get the versions from Maven Central:
plugins{
id("com.google.devtools.ksp") version "2.2.0-2.0.2"
}
dependencies {
implementation("com.system32dev.systemplaceholders:SystemPlaceholders:1.0.1")
ksp("com.system32dev.systemplaceholders:SystemPlaceholders:1.0.1")
}Enable the PlaceholderRegistry in your plugin’s onEnable method:
override fun onEnable() {
PlaceholderRegistry.registerAll()
}To define your own placeholders, use the @Expansion annotation. It accepts the following parameters:
-
author (String): the name of the expansion author
-
identifier (String): the unique identifier of your placeholders
-
version (String): the version of the expansion
-
persist (Boolean, optional): whether to persist the expansion (default: true)
@Expansion("System32", "mycoolplugin", "1.0.0")
object MyExpansion {
// Your placeholders go here
}Each placeholder is defined using the @Placeholder annotation. You can add it to any function inside your expansion object or class.
@Expansion("System32", "fenixtimer", "1.0.0")
object MyPlaceholder {
@Placeholder("getStats")
fun getStats(statKey: String): String {
// Fetch data from your cache or database
return "someValue"
}
// If you pass 'true' as the second parameter, the method receives the Player as the first argument
@Placeholder("getStats", true)
fun getStatsWithPlayer(player: Player?, statKey: String): String {
// Check if player is not null before using it
return "someValue"
}
}Once registered, you can use your placeholders in the format %mycoolplugin_getStats_<statKey>%
- Make a Object Parser for more complex placeholders