Skip to content

Commit df3990a

Browse files
committed
feat: add total player value with mod to /display stats command
1 parent b07c3f6 commit df3990a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ Plugin:
5353
- [x] Add `/display list` filters (`mine`, `world <name>`, `owner <name>`, `sync`)
5454
- [x] Add translation for `/display list` command
5555
- [ ] Improve `/display video` error feedback (separate invalid URL/not owner/wrong target block)
56-
- [ ] Add total value output to `/display stats`
56+
- [x] Add total value output to `/display stats`
5757
- [ ] Add admin target mode for `/display on|off <player>`
5858
- [ ] Improve `/display reload` output with what was reloaded
59-
- [ ] Add `/display cleanup` command
6059

6160
# Version 1.4.3
6261

spigot/src/main/kotlin/com/dreamdisplays/commands/subcommands/StatsCommand.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ class StatsCommand : SubCommand {
1414

1515
override fun execute(sender: CommandSender, args: Array<String?>) {
1616
val versions = getVersions()
17-
val counts = versions.values.filterNotNull().groupingBy { it }.eachCount()
17+
val counts = versions.values
18+
.filterNotNull()
19+
.groupingBy { it }
20+
.eachCount()
21+
.toSortedMap()
1822

1923
sendMessage(sender, "displayStatsHeader")
2024

2125
for ((version, count) in counts) {
22-
val msg = config.getMessageForPlayer(sender as? Player, "displayStatsEntry")
23-
sendColoredMessage(sender, String.format(msg as String, version, count))
26+
sendColoredMessage(sender, format(sender, "displayStatsEntry", version, count))
2427
}
28+
29+
val total = counts.values.sum()
30+
sendColoredMessage(sender, format(sender, "displayStatsTotal", total))
31+
}
32+
33+
private fun format(sender: CommandSender, key: String, vararg values: Any): String {
34+
val template = config.getMessageForPlayer(sender as? Player, key) as? String ?: key
35+
return runCatching { String.format(template, *values) }.getOrElse { template }
2536
}
2637
}

0 commit comments

Comments
 (0)