diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt index 0cd10a9..024227a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/EcoJobsPlugin.kt @@ -31,7 +31,7 @@ class EcoJobsPlugin : LibReforgePlugin() { PlayerPlaceholder( this, "job_level" - ) { it.activeJobLevel?.level.toString() ?: "" }.register() + ) { it.activeJobLevel?.level.toString() }.register() PlayerPlaceholder( this, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt index 944db97..a77b212 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecojobs/jobs/Job.kt @@ -171,6 +171,28 @@ class Job( ) { it.getJobLevel(this).toString() }.register() + + PlayerPlaceholder( + plugin, + "${id}_total_players" + ) { + getTotalPlayers(this).toNiceString() + }.register() + } + + private fun getTotalPlayers(job: Job): Int { + val offlinePlayers = Bukkit.getServer().offlinePlayers + val onlinePlayers = Bukkit.getServer().onlinePlayers + + val allPlayers = offlinePlayers + onlinePlayers + var countPlayerWithJob = 0 + + for (player in allPlayers.distinct()) { + if (player.activeJob?.id == job.id) + countPlayerWithJob += 1 + } + + return countPlayerWithJob } fun getLevel(level: Int): JobLevel = levels.get(level) {