mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Added API to ExperienceAPI to get the amount of XP needed for a level
This commit is contained in:
parent
c878775c72
commit
5cfd2dc799
@ -18,6 +18,7 @@ Version 1.5.01-dev
|
|||||||
+ Added support for `MATERIAL|data` format in treasures.yml
|
+ Added support for `MATERIAL|data` format in treasures.yml
|
||||||
+ Added API to experience events to get XP gain reason
|
+ Added API to experience events to get XP gain reason
|
||||||
+ Added API to check if an entity is bleeding
|
+ Added API to check if an entity is bleeding
|
||||||
|
+ Added API to ExperienceAPI to get the amount of XP needed for a level
|
||||||
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name
|
+ Added options to tools.yml and armor.yml config files to set a pretty repair material name
|
||||||
+ Added full support for repairables in tools.yml and armor.yml config files
|
+ Added full support for repairables in tools.yml and armor.yml config files
|
||||||
+ Added new API class SkillAPI used to get a list of valid skill names
|
+ Added new API class SkillAPI used to get a list of valid skill names
|
||||||
|
@ -5,6 +5,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.api.exceptions.InvalidFormulaTypeException;
|
||||||
|
import com.gmail.nossr50.datatypes.experience.FormulaType;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
|
||||||
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
|
||||||
@ -913,6 +915,33 @@ public final class ExperienceAPI {
|
|||||||
getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
|
getOfflineProfile(uuid).removeXp(getNonChildSkillType(skillType), xp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check how much XP is needed for a specific level with the selected level curve.
|
||||||
|
* </br>
|
||||||
|
* This function is designed for API usage.
|
||||||
|
*
|
||||||
|
* @param level The level to get the amount of XP for
|
||||||
|
*
|
||||||
|
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||||
|
*/
|
||||||
|
public static int getXpNeededToLevel(int level) {
|
||||||
|
return mcMMO.getFormulaManager().getCachedXpToLevel(level, ExperienceConfig.getInstance().getFormulaType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check how much XP is needed for a specific level with the provided level curve.
|
||||||
|
* </br>
|
||||||
|
* This function is designed for API usage.
|
||||||
|
*
|
||||||
|
* @param level The level to get the amount of XP for
|
||||||
|
* @param formulaType The formula type to get the amount of XP for
|
||||||
|
*
|
||||||
|
* @throws InvalidFormulaTypeException if the given formulaType is not valid
|
||||||
|
*/
|
||||||
|
public static int getXpNeededToLevel(int level, String formulaType) {
|
||||||
|
return mcMMO.getFormulaManager().getCachedXpToLevel(level, getFormulaType(formulaType));
|
||||||
|
}
|
||||||
|
|
||||||
// Utility methods follow.
|
// Utility methods follow.
|
||||||
private static void addOfflineXP(UUID playerUniqueId, SkillType skill, int XP) {
|
private static void addOfflineXP(UUID playerUniqueId, SkillType skill, int XP) {
|
||||||
PlayerProfile profile = getOfflineProfile(playerUniqueId);
|
PlayerProfile profile = getOfflineProfile(playerUniqueId);
|
||||||
@ -980,4 +1009,14 @@ public final class ExperienceAPI {
|
|||||||
|
|
||||||
return xpGainReason;
|
return xpGainReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
|
||||||
|
FormulaType formulaType = FormulaType.getFormulaType(formula);
|
||||||
|
|
||||||
|
if (formulaType == null) {
|
||||||
|
throw new InvalidFormulaTypeException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return formulaType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.gmail.nossr50.api.exceptions;
|
||||||
|
|
||||||
|
public class InvalidFormulaTypeException extends RuntimeException {
|
||||||
|
private static final long serialVersionUID = 3368670229490121886L;
|
||||||
|
|
||||||
|
public InvalidFormulaTypeException() {
|
||||||
|
super("That is not a valid FormulaType.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user