Added API to ExperienceAPI to get the amount of XP needed for a level

This commit is contained in:
TfT_02 2014-08-21 16:38:33 -06:00
parent c878775c72
commit 5cfd2dc799
3 changed files with 49 additions and 0 deletions

View File

@ -18,6 +18,7 @@ Version 1.5.01-dev
+ Added support for `MATERIAL|data` format in treasures.yml
+ Added API to experience events to get XP gain reason
+ 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 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

View File

@ -5,6 +5,8 @@ import java.util.UUID;
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.api.exceptions.InvalidPlayerException;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
@ -913,6 +915,33 @@ public final class ExperienceAPI {
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.
private static void addOfflineXP(UUID playerUniqueId, SkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerUniqueId);
@ -980,4 +1009,14 @@ public final class ExperienceAPI {
return xpGainReason;
}
private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
FormulaType formulaType = FormulaType.getFormulaType(formula);
if (formulaType == null) {
throw new InvalidFormulaTypeException();
}
return formulaType;
}
}

View File

@ -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.");
}
}