Add method for checking if a spell property exists

This commit is contained in:
Electroblob77
2020-04-17 23:02:45 +01:00
parent 8291373427
commit b23136d568
2 changed files with 26 additions and 3 deletions
@@ -224,11 +224,23 @@ public final class SpellProperties {
}
/**
* Returns the base value for this spell that corresponds to the given identifier.
* Returns whether a base value was defined with the given identifier.
* @param identifier The string identifier to check for.
* @return True if a base value was defined with the given identifier, false otherwise.
*/
public boolean hasBaseValue(String identifier){
return baseValues.containsKey(identifier);
}
/**
* Returns the base value for this spell that corresponds to the given identifier. To check whether an identifier
* exists, use {@link SpellProperties#hasBaseValue(String)}.
* @param identifier The string identifier to fetch the base value for.
* @return The base value, as a {@code Number}.
* @throws IllegalArgumentException if no base value was defined with the given identifier.
*/
// Better to throw an exception than make this nullable because the vast majority of uses are for retrieving
// specific spells' properties that are known to exist, and IntelliJ would scream at us for not checking
public Number getBaseValue(String identifier){
if(!baseValues.containsKey(identifier)){
throw new IllegalArgumentException("Base value with identifier '" + identifier + "' is not defined.");