StatsHelper
com.jsmacrosce.jsmacros.client.api.helper.StatsHelper
Provides access to the player's client-side statistics counters.
Typed methods query a named registry statistic, while custom-stat methods query the named custom statistic directly. Keyed methods accept names from getStatList(). Count getters throw IllegalArgumentException for unknown ids, since a count cannot represent absence, while formatted and text lookups return null. hasCustomStat(String) reports whether a custom id is registered without throwing.
getStatText(String) returns the statistic type's display name, not an individual statistic name. updateStatistics() requests updated statistics from the server.
js
if (World.isWorldLoaded()) {
const stats = Player.getStatistics();
Chat.log(`${stats.getBlockMined("minecraft:stone")} stone mined`);
Chat.log(`${stats.getItemUsed("minecraft:diamond_pickaxe")} pickaxe uses`);
stats.updateStatistics();
}Constructors
new StatsHelper
new StatsHelper(StatsCounter base)#Wraps the supplied statistics counter.
Parameters:
base: raw statistics counter to wrap
Methods
getBlockMined
getCustomFormattedStat
getCustomStat
getEntityKilled
getFormattedStatMap
getFormattedStatValue
Returns the counter for the statistic identified by
statKey, formatted by that statistic's formatter.Parameters:
statKey: one of the keys from getStatList()
Returns: the formatted value of the matching statistic, or
null if no realized statistic has that keygetItemBroken
getItemCrafted
getItemDropped
getItemPickedUp
getItemUsed
getKilledByEntity
getRawStatMap
getRawStatValue
Returns the unformatted counter for the statistic identified by
statKey.Parameters:
statKey: one of the keys from getStatList()
Returns: the raw value of the matching statistic
getStatList
getStatText
Returns the display name of the statistic type identified by
statKey, rather than a name specific to that statistic.Parameters:
statKey: one of the keys from getStatList()
Returns: the text component naming that statistic's category, or
null if no realized statistic has that keyhasCustomStat
Returns whether a custom statistic with this identifier is registered. Use this to tell an unknown identifier apart from a registered statistic whose counter is zero.
Parameters:
id: the custom statistic identifier
Returns:
true if the id names a registered custom statistictoString
updateStatistics
Requests that the server send the current statistics over the active connection.
Returns: self for chaining.