Skip to content

StatsHelper ​

com.jsmacrosce.jsmacros.client.api.helper.StatsHelper

Since1.8.4

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(); unknown keys throw IllegalArgumentException. 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 ​

getBlockMined(String id): intSince1.8.4#
The number of times the player has mined the block with this identifier.

Parameters:

  • id: the identifier of the block
Returns: the mined count

getCustomFormattedStat ​

getCustomFormattedStat(String id): StringSince1.8.4#
Returns the formatted counter for the custom statistic identified by id.

Parameters:

  • id: the custom statistic identifier
Returns: the formatted counter value

getCustomStat ​

getCustomStat(String id): intSince1.8.4#
Returns the counter for the custom statistic identified by id.

Parameters:

  • id: the custom statistic identifier
Returns: the raw counter value

getEntityKilled ​

getEntityKilled(String id): intSince1.8.4#
The number of times the player has killed the entity with this identifier.

Parameters:

  • id: the identifier of the entity
Returns: the kill count

getFormattedStatMap ​

getFormattedStatMap(): Map<String, String>Since1.8.4#
Returns the formatted counters currently held by this helper, keyed by individual statistic name.
Returns: a map of statistic name to its formatted value

getFormattedStatValue ​

getFormattedStatValue(String statKey): StringSince1.8.4#
Returns the counter for the statistic identified by statKey, formatted by that statistic's formatter.

Parameters:

Returns: the formatted value of the matching statistic

getItemBroken ​

getItemBroken(String id): intSince1.8.4#
Returns the broken-item count for the item identified by id.

Parameters:

  • id: the identifier of the item
Returns: the broken count

getItemCrafted ​

getItemCrafted(String id): intSince1.8.4#
Returns the crafted-item count for the item identified by id.

Parameters:

  • id: the identifier of the item
Returns: the crafted count

getItemDropped ​

getItemDropped(String id): intSince1.8.4#
Returns the item-drop count for the item identified by id.

Parameters:

  • id: the identifier of the item
Returns: the dropped count

getItemPickedUp ​

getItemPickedUp(String id): intSince1.8.4#
Returns the item pickup count for the item identified by id.

Parameters:

  • id: the identifier of the item
Returns: the picked-up count

getItemUsed ​

getItemUsed(String id): intSince1.8.4#
Returns the item-use count for the item identified by id.

Parameters:

  • id: the identifier of the item
Returns: the used count

getKilledByEntity ​

getKilledByEntity(String id): intSince1.8.4#
The number of times the player has been killed by the entity with this identifier.

Parameters:

  • id: the identifier of the entity
Returns: the death count

getRawStatMap ​

getRawStatMap(): Map<String, Integer>Since1.8.4#
Returns the unformatted counters currently held by this helper, keyed by individual statistic name.
Returns: a map of individual statistic name to its raw value

getRawStatValue ​

getRawStatValue(String statKey): intSince1.8.4#
Returns the unformatted counter for the statistic identified by statKey.

Parameters:

Returns: the raw value of the matching statistic

getStatList ​

getStatList(): List<String>Since1.8.4#
Returns the names of the statistics currently held by this helper; each name identifies one statistic, including when multiple statistics share a type.
Returns: a list of individual statistic keys, one per recorded statistic

getStatText ​

getStatText(String statKey): ComponentSince1.8.4#
Returns the display name of the statistic type identified by statKey, rather than a name specific to that statistic.

Parameters:

Returns: the text component naming that statistic's category

toString ​

toString(): String#
Returns a diagnostic string containing the formatted statistics map, in the form StatsHelper:{...}.
Returns: diagnostic string containing the formatted statistics map

updateStatistics ​

updateStatistics(): StatsHelperSince1.8.4#
Requests that the server send the current statistics over the active connection.
Returns: self for chaining.