Splits the blacksmith command into two commands, and much more
This commit is contained in:
@ -0,0 +1,62 @@
|
||||
package net.knarcraft.blacksmith.util;
|
||||
|
||||
/**
|
||||
* A helper class for getting an object value as the correct type
|
||||
*/
|
||||
public final class ConfigHelper {
|
||||
|
||||
private ConfigHelper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given value as a double
|
||||
*
|
||||
* <p>This will throw an exception if used for a non-double setting</p>
|
||||
*
|
||||
* @param value <p>The object value to get</p>
|
||||
* @return <p>The value of the given object as a double</p>
|
||||
*/
|
||||
public static double asDouble(Object value) {
|
||||
if (value instanceof String) {
|
||||
return Double.parseDouble((String) value);
|
||||
} else if (value instanceof Integer) {
|
||||
return (Integer) value;
|
||||
} else {
|
||||
return (Double) value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given value as a boolean
|
||||
*
|
||||
* <p>This will throw an exception if used for a non-boolean value</p>
|
||||
*
|
||||
* @param value <p>The object value to get</p>
|
||||
* @return <p>The value of the given object as a boolean</p>
|
||||
*/
|
||||
public static boolean asBoolean(Object value) {
|
||||
if (value instanceof String) {
|
||||
return Boolean.parseBoolean((String) value);
|
||||
} else {
|
||||
return (Boolean) value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the given value as an integer
|
||||
*
|
||||
* <p>This will throw an exception if used for a non-integer setting</p>
|
||||
*
|
||||
* @param value <p>The object value to get</p>
|
||||
* @return <p>The value of the given object as an integer</p>
|
||||
*/
|
||||
public static int asInt(Object value) {
|
||||
if (value instanceof String) {
|
||||
return Integer.parseInt((String) value);
|
||||
} else {
|
||||
return (Integer) value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user