Interface PlayerStats


public interface PlayerStats
An instance represents a mutable collection of stats of a player.

Generally there are 2 cached instances per player: One that holds the stats of a game, and the other of the total ones. Use isGameStats() and getGameStats() to differentiate them.

  • Method Details

    • getPlayerUUID

      UUID getPlayerUUID()
      The UUID of the involved player
      Returns:
      The UUID of the player who owns the stats.
    • isGameStats

      boolean isGameStats()
      Get whether this stats instance holds the stats of a running match, and not the total ones.
      Returns:
      Whether these stats are about the round that the player currently plays.
    • getGameStats

      @Nullable @Nullable PlayerStats getGameStats()
      Will return the stats of the round that the player currently plays.
      Returns:
      Can return null when isGameStats() returns true or the player isn't playing right now
    • resetGameStats

      void resetGameStats()
      Will reset the game stats.

      It does not matter if you're calling this with the game stats or the normal stats

    • get

      Number get(String key)
      Looks for the stats entry with that key.

      Will use 0 as default.

      Parameters:
      key - The id/key of the stats entry
      Returns:
      The value that this players. 0 if there are no stats with that key
    • set

      default Number set(String key, Number value)
      Sets the value of a stats entry.

      Keep in mind that the PlayerStatChangeEvent is likely being dispatched with this.

      Parameters:
      key - The id/key of the stats entry
      value - The value for that entry
      Returns:
      Returns the previous value
      Throws:
      IllegalArgumentException - When key doesn't fit the format
    • set

      Number set(String key, Number value, AttributeChangeCause cause)
      Sets the value of a stats entry,
      Parameters:
      key - The id/key of the stats entry
      value - The value for that entry
      cause - The technical cause for setting this
      Returns:
      Returns the previous value
      Throws:
      IllegalArgumentException - When key doesn't fit the format
    • add

      default Number add(String key, Number addAmount)
      Adds an amount to a stats entry.

      Keep in mind that the PlayerStatChangeEvent is likely being dispatched with this.

      Parameters:
      key - The id/key of the stats entry
      addAmount - The amount that shall be added
      Returns:
      Returns the previous value
      Throws:
      IllegalArgumentException - When key doesn't fit the format
    • add

      Number add(String key, Number addAmount, AttributeChangeCause cause)
      Adds an amount to a stats entry.
      Parameters:
      key - The id/key of the stats entry
      addAmount - The amount that shall be added
      cause - The technical cause for setting this
      Returns:
      Returns the previous value
      Throws:
      IllegalArgumentException - When key doesn't fit the format
    • entrySet

      Set<Map.Entry<String,Number>> entrySet()
      Returns all stored entries of this object
      Returns:
      Returns a set of all stored stats
    • save

      default void save()
      Asynchronously saves these stats.

      It's usually not needed to call this method when the player is currently on the server as the plugin will already handle it

    • save

      void save(@Nullable @Nullable Runnable callback)
      Asynchronously saves these stats.

      It's usually not needed to call this method when the player is currently on the server as the plugin will already handle it.

      Important: The callback doesn't get synced to the main thread.

      Parameters:
      callback - Gets called when the operation was finished