# StatsHelper

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

**Since:** 1.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()](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatList-). Count getters throw
 [IllegalArgumentException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/IllegalArgumentException.html) for unknown ids, since a count cannot represent absence, while
 formatted and text lookups return `null`. [hasCustomStat(String)](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_hasCustomStat-String-) reports whether a
 custom id is registered without throwing.  
 [getStatText(String)](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatText-String-) returns the statistic type's display name, not an individual
 statistic name. [updateStatistics()](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_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 {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_constructor-StatsCounter-}

```js
new StatsHelper(StatsCounter base)
```

Wraps the supplied statistics counter.

**Parameters:**
- `base`: raw statistics counter to wrap

## Methods

### getBlockMined {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getBlockMined-String-}

```js
getBlockMined(String id): int
```

The number of times the player has mined the block with this identifier.

**Parameters:**
- `id`: the identifier of the block

**Returns:** the mined count

**Since:** 1.8.4

### getCustomFormattedStat {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getCustomFormattedStat-String-}

```js
getCustomFormattedStat(String id): String
```

Returns the formatted counter for the custom statistic identified by `id`.

**Parameters:**
- `id`: the custom statistic identifier

**Returns:** the formatted counter value, or `null` if no custom statistic with that id is
         registered

**Since:** 1.8.4

### getCustomStat {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getCustomStat-String-}

```js
getCustomStat(String id): int
```

Returns the counter for the custom statistic identified by `id`.

**Parameters:**
- `id`: the custom statistic identifier

**Returns:** the raw counter value

**Since:** 1.8.4

### getEntityKilled {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getEntityKilled-String-}

```js
getEntityKilled(String id): int
```

The number of times the player has killed the entity with this identifier.

**Parameters:**
- `id`: the identifier of the entity

**Returns:** the kill count

**Since:** 1.8.4

### getFormattedStatMap {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getFormattedStatMap-}

```js
getFormattedStatMap(): Map<String, String>
```

Returns the formatted counters currently held by this helper, keyed by individual
 statistic name.

**Returns:** a map of statistic name to its formatted value

**Since:** 1.8.4

### getFormattedStatValue {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getFormattedStatValue-String-}

```js
getFormattedStatValue(String statKey): String
```

Returns the counter for the statistic identified by `statKey`, formatted by that
 statistic's formatter.

**Parameters:**
- `statKey`: one of the keys from [getStatList()](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatList-)

**Returns:** the formatted value of the matching statistic, or `null` if no realized
         statistic has that key

**Since:** 1.8.4

### getItemBroken {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getItemBroken-String-}

```js
getItemBroken(String id): int
```

Returns the broken-item count for the item identified by `id`.

**Parameters:**
- `id`: the identifier of the item

**Returns:** the broken count

**Since:** 1.8.4

### getItemCrafted {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getItemCrafted-String-}

```js
getItemCrafted(String id): int
```

Returns the crafted-item count for the item identified by `id`.

**Parameters:**
- `id`: the identifier of the item

**Returns:** the crafted count

**Since:** 1.8.4

### getItemDropped {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getItemDropped-String-}

```js
getItemDropped(String id): int
```

Returns the item-drop count for the item identified by `id`.

**Parameters:**
- `id`: the identifier of the item

**Returns:** the dropped count

**Since:** 1.8.4

### getItemPickedUp {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getItemPickedUp-String-}

```js
getItemPickedUp(String id): int
```

Returns the item pickup count for the item identified by `id`.

**Parameters:**
- `id`: the identifier of the item

**Returns:** the picked-up count

**Since:** 1.8.4

### getItemUsed {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getItemUsed-String-}

```js
getItemUsed(String id): int
```

Returns the item-use count for the item identified by `id`.

**Parameters:**
- `id`: the identifier of the item

**Returns:** the used count

**Since:** 1.8.4

### getKilledByEntity {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getKilledByEntity-String-}

```js
getKilledByEntity(String id): int
```

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

**Since:** 1.8.4

### getRawStatMap {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getRawStatMap-}

```js
getRawStatMap(): Map<String, Integer>
```

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

**Since:** 1.8.4

### getRawStatValue {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getRawStatValue-String-}

```js
getRawStatValue(String statKey): int
```

Returns the unformatted counter for the statistic identified by `statKey`.

**Parameters:**
- `statKey`: one of the keys from [getStatList()](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatList-)

**Returns:** the raw value of the matching statistic

**Since:** 1.8.4

### getStatList {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatList-}

```js
getStatList(): List<String>
```

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

**Since:** 1.8.4

### getStatText {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatText-String-}

```js
getStatText(String statKey): Component
```

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()](#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_getStatList-)

**Returns:** the text component naming that statistic's category, or `null` if no realized
         statistic has that key

**Since:** 1.8.4

### hasCustomStat {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_hasCustomStat-String-}

```js
hasCustomStat(String id): boolean
```

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 statistic

**Since:** 2.2.0

### toString {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the formatted statistics map, in the form
 `StatsHelper:{...}`.

**Returns:** diagnostic string containing the formatted statistics map

### updateStatistics {#com.jsmacrosce.jsmacros.client.api.helper.StatsHelper_updateStatistics-}

```js
updateStatistics(): StatsHelper
```

Requests that the server send the current statistics over the active connection.

**Returns:** self for chaining.

**Since:** 1.8.4
