Class ExpUtils

java.lang.Object
co.crystaldev.alpinecore.util.ExpUtils

public final class ExpUtils extends Object
Utility for managing player experience.
Since:
0.1.0
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    changeExp(@NotNull org.bukkit.entity.Player player, int exp)
    Change experience for a Player.
    static int
    getExp(@NotNull org.bukkit.entity.Player player)
    Calculate total Player experience based on level and progress to next.
    static int
    getExpFromLevel(int level)
    Calculate total experience based on level.
    static int
    Calculate level based on total experience.
    static double
    getLevelFromExp(long exp)
    Calculate level (including progress to next level) based on total experience.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExpUtils

      public ExpUtils()
  • Method Details

    • getExp

      public static int getExp(@NotNull @NotNull org.bukkit.entity.Player player)
      Calculate total Player experience based on level and progress to next.
      Parameters:
      player - the Player
      Returns:
      the amount of experience the Player has
      See Also:
    • getExpFromLevel

      public static int getExpFromLevel(int level)
      Calculate total experience based on level.
      Parameters:
      level - the level
      Returns:
      the total experience calculated
      See Also:
    • getLevelFromExp

      public static double getLevelFromExp(long exp)
      Calculate level (including progress to next level) based on total experience.
      Parameters:
      exp - the total experience
      Returns:
      the level calculated
    • getIntLevelFromExp

      public static int getIntLevelFromExp(long exp)
      Calculate level based on total experience.
      Parameters:
      exp - the total experience
      Returns:
      the level calculated
    • changeExp

      public static void changeExp(@NotNull @NotNull org.bukkit.entity.Player player, int exp)
      Change experience for a Player. This method is preferred over Player.giveExp(int).

      In older versions the method does not take differences in exp per level into account. This leads to over leveling when granting players large amounts of experience.

      In modern versions, while differing amounts of experience per level are accounted for, the approach used is loop-heavy and requires an excessive number of calculations, which makes it quite slow.

      Parameters:
      player - the Player affected
      exp - the amount of experience to add or remove