Class XpUtils

java.lang.Object
ru.cwcode.cwutils.xp.XpUtils

public class XpUtils extends Object
A utility for managing Player experience properly.
Author:
Jikoo
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    changeExp(org.bukkit.entity.Player player, int exp)
    Change a Player's exp.
    static void
    dropExp(org.bukkit.Location location, int xp)
     
    static int
    getExp(org.bukkit.entity.Player player)
    Calculates a player's total exp based on level and progress to next.
    static int
    getExpFromLevel(int level)
    Calculates total experience based on level.
    static double
    getLevelFromExp(long exp)
    Calculates 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

    • XpUtils

      public XpUtils()
  • Method Details

    • dropExp

      public static void dropExp(org.bukkit.Location location, int xp)
    • getExp

      public static int getExp(org.bukkit.entity.Player player)
      Calculates a player's total exp based on level and progress to next.
      Parameters:
      player - the Player
      Returns:
      the amount of exp the Player has
      See Also:
    • getExpFromLevel

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

        "One can determine how much experience has been collected to reach a level using the equations:

        Total Experience = [Level]2 + 6[Level] (at levels 0-15) 2.5[Level]2 - 40.5[Level] + 360 (at levels 16-30) 4.5[Level]2 - 162.5[Level] + 2220 (at level 31+)"

    • getLevelFromExp

      public static double getLevelFromExp(long exp)
      Calculates level based on total experience.
      Parameters:
      exp - the total experience
      Returns:
      the level calculated
    • changeExp

      public static void changeExp(org.bukkit.entity.Player player, int exp)
      Change a Player's exp.

      This method should be used in place of Player.giveExp(int), which does not properly account for different levels requiring different amounts of experience.

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