1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-24 02:08:48 +00:00

feat: 其他更新

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-09-27 15:13:52 +08:00
parent 46359463b9
commit 233ab96cad
3 changed files with 225 additions and 12 deletions

View File

@ -92,6 +92,11 @@
<artifactId>Vault</artifactId> <artifactId>Vault</artifactId>
<version>1.5.6</version> <version>1.5.6</version>
</dependency> </dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot1102</artifactId> <artifactId>spigot1102</artifactId>

View File

@ -40,18 +40,6 @@ public class Log {
logger.addHandler(handler); logger.addHandler(handler);
} }
/**
* Sends console a message
*
* @param message
* Message to be displayed
*/
public static void console(final String... msg) {
for (final String str : msg) {
console(str);
}
}
/** /**
* Sends console a message * Sends console a message
* *
@ -74,6 +62,18 @@ public class Log {
console.sendMessage(prefix + String.format(message, object)); console.sendMessage(prefix + String.format(message, object));
} }
/**
* Sends console a message
*
* @param message
* Message to be displayed
*/
public static void console(final String[] msg) {
for (final String str : msg) {
console(str);
}
}
/** /**
* 调试消息 * 调试消息
* *

View File

@ -0,0 +1,208 @@
package pw.yumc.YumCore.utils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Minecraft反射类
*
* @since 2015年12月14日 下午1:35:11
* @author 许凯
*/
@SuppressWarnings("all")
public class ReflectUtil {
public static Field getDeclaredFieldByName(final Class source, final String name) {
try {
final Field field = source.getDeclaredField(name);
field.setAccessible(true);
return field;
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
public static List<Field> getDeclaredFieldByType(final Class source, final Class type) {
final List<Field> list = new ArrayList<>();
for (final Field field : source.getDeclaredFields()) {
if (field.getType() == type) {
field.setAccessible(true);
list.add(field);
}
}
return list;
}
public static Method getDeclaredMethod(final Class clzz, final String methodName, final Class... args) {
try {
return clzz.getDeclaredMethod(methodName, args);
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
public static Method getDeclaredMethodByNameAndParams(final Class source, final String name, final Class... args) {
for (final Method method : findMethodByParams(source.getDeclaredMethods(), args)) {
if (method.getName().equals(name)) {
return method;
}
}
return null;
}
public static List<Method> getDeclaredMethodByNameAndType(final Class source, final String name, final Class returnType) {
final List<Method> methods = new ArrayList<>();
for (final Method method : source.getDeclaredMethods()) {
if (method.getName().equals(name) && method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static List<Method> getDeclaredMethodByParams(final Class source, final Class... args) {
return findMethodByParams(source.getDeclaredMethods(), args);
}
public static List<Method> getDeclaredMethodByParamsAndType(final Class source, final Class returnType, final Class... args) {
final List<Method> methods = new ArrayList<>();
for (final Method method : findMethodByParams(source.getDeclaredMethods(), args)) {
if (method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static List<Method> getDeclaredMethodByType(final Class source, final Class returnType) {
final List<Method> methods = new ArrayList<>();
for (final Method method : source.getDeclaredMethods()) {
if (method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static Field getFieldByName(final Class source, final String name) {
try {
final Field field = source.getField(name);
field.setAccessible(true);
return field;
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
public static List<Field> getFieldByType(final Class source, final Class type) {
final List<Field> list = new ArrayList<>();
for (final Field field : source.getFields()) {
if (field.getType() == type) {
field.setAccessible(true);
list.add(field);
}
}
return list;
}
public static Object getHandle(final Object bukkitObj) {
try {
return bukkitObj.getClass().getMethod("getHandle").invoke(bukkitObj);
} catch (final Exception e) {
}
return null;
}
public static Method getMethodByNameAndParams(final Class source, final String name, final Class... args) {
for (final Method method : findMethodByParams(source.getMethods(), args)) {
if (method.getName().equals(name)) {
return method;
}
}
return null;
}
public static List<Method> getMethodByNameAndType(final Class source, final String name, final Class returnType) {
final List<Method> methods = new ArrayList<>();
for (final Method method : source.getMethods()) {
if (method.getName().equals(name) && method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static List<Method> getMethodByParams(final Class source, final Class... args) {
return findMethodByParams(source.getMethods(), args);
}
public static List<Method> getMethodByParamsAndType(final Class source, final Class returnType, final Class... args) {
final List<Method> methods = new ArrayList<>();
for (final Method method : findMethodByParams(source.getMethods(), args)) {
if (method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static List<Method> getMethodByType(final Class source, final Class returnType) {
final List<Method> methods = new ArrayList<>();
for (final Method method : source.getMethods()) {
if (method.getReturnType().equals(returnType)) {
methods.add(method);
}
}
return methods;
}
public static void invokeMethod(final Object object, final String methodName, final Class arg, final Object value) {
try {
final Method m = object.getClass().getDeclaredMethod(methodName, arg);
m.invoke(object, value);
} catch (final Exception e) {
e.printStackTrace();
}
}
public static void invokeMethod(final Object object, final String methodName, final Class[] args, final Object[] value) {
try {
final Method m = object.getClass().getDeclaredMethod(methodName, args);
m.invoke(object, value);
} catch (final Exception e) {
e.printStackTrace();
}
}
public static void invokeMethod(final Object object, final String methodName, final Object value) {
try {
final Method m = object.getClass().getDeclaredMethod(methodName, value.getClass());
m.invoke(object, value);
} catch (final Exception e) {
e.printStackTrace();
}
}
private static List<Method> findMethodByParams(final Method[] methods, final Class... args) {
final List<Method> list = new ArrayList<>();
start:
for (final Method method : methods) {
if (method.getParameterTypes().length == args.length) {
final Class[] array = method.getParameterTypes();
for (int i = 0; i < args.length; i++) {
if (!array[i].equals(args[i])) {
continue start;
}
}
method.setAccessible(true);
list.add(method);
}
}
return list;
}
}