Add method for checking if a spell property exists
This commit is contained in:
@@ -606,16 +606,27 @@ public abstract class Spell extends IForgeRegistryEntry.Impl<Spell> implements C
|
|||||||
return properties.cooldown;
|
return properties.cooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a property has been defined for the given identifier.
|
||||||
|
* @param identifier The JSON identifier to check for.
|
||||||
|
* @return True if a property has been defined for the given identifier, false if not.
|
||||||
|
*/
|
||||||
|
public final boolean hasProperty(String identifier){
|
||||||
|
return properties.hasBaseValue(identifier);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the base value specified in JSON for the given identifier. This may be used from within the spell
|
* Returns the base value specified in JSON for the given identifier. This may be used from within the spell
|
||||||
* class, or from elsewhere (entities, items, etc.) via the spell's instance.
|
* class, or from elsewhere (entities, items, etc.) via the spell's instance.
|
||||||
*
|
*
|
||||||
* @param identifier The JSON identifier for the required property. This <b>must</b> have been defined using
|
* @param identifier The JSON identifier for the required property. This <b>must</b> have been defined using
|
||||||
* {@link Spell#addProperties(String...)} or an exception will be thrown.
|
* {@link Spell#addProperties(String...)} or an exception will be thrown. To check if an
|
||||||
|
* identifier exists, use {@link Spell#hasProperty(String)}.
|
||||||
* @return The base value of the property, as a {@code Number} object. Internally this is handled as a float, but
|
* @return The base value of the property, as a {@code Number} object. Internally this is handled as a float, but
|
||||||
* it is passed through as a {@code Number} to avoid casting. <i>Be careful with rounding when extracting integer
|
* it is passed through as a {@code Number} to avoid casting. <i>Be careful with rounding when extracting integer
|
||||||
* values! The JSON parser cannot guarantee that the property file has an integer value.</i>
|
* values! The JSON parser cannot guarantee that the property file has an integer value.</i>
|
||||||
* @throws IllegalArgumentException if no property was defined with the given identifier. */
|
* @throws IllegalArgumentException if no property was defined with the given identifier.
|
||||||
|
*/
|
||||||
public final Number getProperty(String identifier){
|
public final Number getProperty(String identifier){
|
||||||
return properties.getBaseValue(identifier);
|
return properties.getBaseValue(identifier);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* @param identifier The string identifier to fetch the base value for.
|
||||||
* @return The base value, as a {@code Number}.
|
* @return The base value, as a {@code Number}.
|
||||||
* @throws IllegalArgumentException if no base value was defined with the given identifier.
|
* @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){
|
public Number getBaseValue(String identifier){
|
||||||
if(!baseValues.containsKey(identifier)){
|
if(!baseValues.containsKey(identifier)){
|
||||||
throw new IllegalArgumentException("Base value with identifier '" + identifier + "' is not defined.");
|
throw new IllegalArgumentException("Base value with identifier '" + identifier + "' is not defined.");
|
||||||
|
|||||||
Reference in New Issue
Block a user