Package co.crystaldev.alpinecore.util
Class ExpUtils
java.lang.Object
co.crystaldev.alpinecore.util.ExpUtils
Utility for managing player experience.
- Since:
- 0.1.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
changeExp
(@NotNull org.bukkit.entity.Player player, int exp) Change experience for aPlayer
.static int
getExp
(@NotNull org.bukkit.entity.Player player) Calculate totalPlayer
experience based on level and progress to next.static int
getExpFromLevel
(int level) Calculate total experience based on level.static int
getIntLevelFromExp
(long exp) Calculate level based on total experience.static double
getLevelFromExp
(long exp) Calculate level (including progress to next level) based on total experience.
-
Constructor Details
-
ExpUtils
public ExpUtils()
-
-
Method Details
-
getExp
public static int getExp(@NotNull @NotNull org.bukkit.entity.Player player) Calculate totalPlayer
experience based on level and progress to next.- Parameters:
player
- thePlayer
- 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 aPlayer
. This method is preferred overPlayer.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
- thePlayer
affectedexp
- the amount of experience to add or remove
-