public class CommonFunctions extends Object implements SelfReference
Constructor and Description |
---|
CommonFunctions() |
Modifier and Type | Method and Description |
---|---|
Object[] |
array(int size)
create an empty array
|
Object[] |
arrayOf(Object... values) |
String |
formatCurrency(double money)
Translate money into specified country's currency format.
|
String |
formatCurrency(double money,
String locale1,
String locale2)
Translate money into specified country's currency format.
|
List<Object> |
list() |
List<Object> |
listOf(Object... values) |
Map<Object,Object> |
map() |
boolean |
matches(String str,
String regex)
matches the str by using regular expression regex
|
String |
mergeArguments(String[] args)
Merge array of String.
|
String |
mergeArguments(String[] args,
int indexFrom)
Merge array of String.
|
String |
mergeArguments(String[] args,
int indexFrom,
int indexTo)
Merge array of String.
|
Object |
newInstance(String className,
Object... args) |
double |
parseDouble(String str)
parse the string that contains decimal into real decimal value.
|
Object |
parseEnum(String enumClassName,
String valueName)
Get enum value manually.
|
int |
parseInt(String str)
parse the string that contains integer into real integer value.
|
double |
random(double end) |
double |
random(double start,
double end) |
float |
random(float end) |
float |
random(float start,
float end) |
int |
random(int end)
get a random integer value between 0 to end
|
int |
random(int start,
int end)
get a random integer value between start to end
*
|
long |
random(long end) |
long |
random(long start,
long end) |
String |
round(double val,
int decimal)
get a string representing the input value rounded to the set decimal place
|
Set<Object> |
set() |
Set<Object> |
set(Collection<?> iterable) |
SimpleLocation |
slocation(String world,
int x,
int y,
int z) |
double |
sqrt(int num) |
Object |
staticGetFieldValue(String className,
String fieldName)
Try to get static value for specified field from specified class.
|
Object |
staticMethod(String className,
String methodName,
Object... args)
Invoke the static method of provided class.
|
void |
staticSetFieldValue(String className,
String fieldName,
Object value)
Try to set static value for specified field from specified class.
|
byte |
toByte(Number number) |
double |
toDouble(Number number) |
float |
toFloat(Number number) |
int |
toInt(Number number) |
long |
toLong(Number number) |
short |
toShort(Number number) |
String |
typeOf(Object value,
boolean withFullPath)
Return the name of the class that provided object was created by.
|
public int random(int end)
Example) #MESSAGE "You rolled the dice: "+(random(6) + 1)
end
- exclusivepublic float random(float end)
public double random(double end)
public long random(long end)
public int random(int start, int end)
Example) #MESSAGE "You rolled the dice: "+random(1, 7)
start
- inclusiveend
- exclusivepublic float random(float start, float end)
public double random(double start, double end)
public long random(long start, long end)
public String round(double val, int decimal)
Example) #MESSAGE "1.09 rounded to the nearest tenth is " + round(1.09,1)
val
- the double to be roundeddecimal
- the decimal place to round topublic Object staticGetFieldValue(String className, String fieldName) throws ClassNotFoundException, NoSuchFieldException
className
- the full class namefieldName
- the name of static fieldClassNotFoundException
- error if the specified 'className' does not existNoSuchFieldException
- error if the specified 'fieldName' field does not exist in the class.public void staticSetFieldValue(String className, String fieldName, Object value) throws ClassNotFoundException, NoSuchFieldException, IllegalArgumentException
className
- full name of the classfieldName
- name of the static fieldvalue
- the value to save into the fieldClassNotFoundException
- error if the specified 'className' does not existNoSuchFieldException
- error if the specified 'fieldName' field does not exist in the class.IllegalArgumentException
- if the 'value' is incompatible with the field type.public Object staticMethod(String className, String methodName, Object... args) throws ClassNotFoundException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException
className
- the full name of the class.methodName
- the name of static method.args
- array of arguments. This can be empty if the method doesn't have any arguments.
(Ex. staticMethod("my.class", "PewPew")ClassNotFoundException
- error if the 'className' does not exist.NoSuchMethodException
- error if the 'methodName' does not exist in the class.IllegalArgumentException
- error if invalid 'args' are passed to the method.IllegalAccessException
public Object parseEnum(String enumClassName, String valueName) throws ClassNotFoundException
Example) /trg run #MESSAGE "value is "+parseEnum("org.bukkit.GameMode", "CREATIVE")
Example) /trg run player.setGameMode(parseEnum("org.bukkit.GameMode", "CREATIVE"))
Example) /trg run player.setGameMode("CREATIVE") //This also works
enumClassName
- the full class name of enum.valueName
- the enum value to parse.ClassNotFoundException
- if the provided class name doesn't exist or not enum class.public SimpleLocation slocation(String world, int x, int y, int z)
public Object newInstance(String className, Object... args) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalArgumentException, InvocationTargetException
public boolean matches(String str, String regex)
Example) /trg run IF matches("PewPew", "[a-zA-Z0-9 ]+"); #MESSAGE "Seems to be English"; ENDIF;
str
- regex
- public int parseInt(String str)
Example) /trg run #MESSAGE parseInt("300") + 50
str
- the string that contains integerpublic double parseDouble(String str)
Example) /trg run #MESSAGE parseDouble("15.30") + 2.12
str
- the string that contains decimalpublic Object[] array(int size)
Example) /trg run temp = array(5); temp[3] = "hi"; #MESSAGE temp[3];
size
- size of arraypublic Set<Object> set(Collection<?> iterable)
public String mergeArguments(String[] args)
args
- array to mergepublic String mergeArguments(String[] args, int indexFrom)
args
- array to mergeindexFrom
- inclusivepublic String mergeArguments(String[] args, int indexFrom, int indexTo)
args
- array to mergeindexFrom
- inclusiveindexTo
- inclusivepublic byte toByte(Number number)
public short toShort(Number number)
public int toInt(Number number)
public long toLong(Number number)
public float toFloat(Number number)
public double toDouble(Number number)
public double sqrt(int num)
public String formatCurrency(double money, String locale1, String locale2)
money
- locale1
- language code (Ex. en)locale2
- country code (Ex. US)public String formatCurrency(double money)
money
- public String typeOf(Object value, boolean withFullPath)
value
- the object to get its class namewithFullPath
- if true this returns class name containing full path