diff --git a/Changelog.txt b/Changelog.txt index dbd69f220..aa6e510d2 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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 diff --git a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java index dbfddb519..56b9f8563 100644 --- a/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java +++ b/src/main/java/com/gmail/nossr50/api/ExperienceAPI.java @@ -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. + *
+ * 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. + *
+ * 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; + } } diff --git a/src/main/java/com/gmail/nossr50/api/exceptions/InvalidFormulaTypeException.java b/src/main/java/com/gmail/nossr50/api/exceptions/InvalidFormulaTypeException.java new file mode 100644 index 000000000..c46332b99 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/exceptions/InvalidFormulaTypeException.java @@ -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."); + } +}