Fix Reflection

This commit is contained in:
sky 2019-12-21 20:35:35 +08:00
parent 5908428403
commit ea9a782975
4 changed files with 29 additions and 29 deletions

View File

@ -31,6 +31,7 @@ public class LocalPlayer {
files.forEach((name, file) -> {
try {
file.save(toFile(name));
} catch (NullPointerException ignored) {
} catch (Throwable t) {
t.printStackTrace();
}
@ -43,6 +44,7 @@ public class LocalPlayer {
if (toPlayer(name) == null) {
try {
files.remove(name).save(toFile(name));
} catch (NullPointerException ignored) {
} catch (Throwable t) {
t.printStackTrace();
}

View File

@ -63,7 +63,6 @@ public class SimpleReflection {
}
public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) {
throw new RuntimeException("Not Found Cache.");
@ -72,14 +71,14 @@ public class SimpleReflection {
if (value == null) {
throw new RuntimeException("Not Found Field.");
}
try {
field.set(instance, value);
} catch (Exception e) {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) {
throw new RuntimeException("Not Found Cache.");
@ -88,15 +87,15 @@ public class SimpleReflection {
if (field == null) {
throw new RuntimeException("Not Found Field.");
}
try {
return field.get(instance);
} catch (Exception e) {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) {
try {
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
if (fields == null) {
throw new RuntimeException("Not Found Cache.");
@ -105,8 +104,9 @@ public class SimpleReflection {
if (field == null) {
throw new RuntimeException("Not Found Field.");
}
try {
return (T) field.get(instance);
} catch (Exception e) {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return def;

View File

@ -15,5 +15,4 @@ object AsyncTask {
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId
}
}

View File

@ -29,5 +29,4 @@ class Example extends JavaPlugin with Listener {
class a
assert(this == JavaPlugin.getProvidingPlugin(classOf[a]))
}
}