Fix Reflection
This commit is contained in:
parent
5908428403
commit
ea9a782975
@ -31,6 +31,7 @@ public class LocalPlayer {
|
|||||||
files.forEach((name, file) -> {
|
files.forEach((name, file) -> {
|
||||||
try {
|
try {
|
||||||
file.save(toFile(name));
|
file.save(toFile(name));
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -43,6 +44,7 @@ public class LocalPlayer {
|
|||||||
if (toPlayer(name) == null) {
|
if (toPlayer(name) == null) {
|
||||||
try {
|
try {
|
||||||
files.remove(name).save(toFile(name));
|
files.remove(name).save(toFile(name));
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,6 @@ public class SimpleReflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) {
|
public static void setFieldValue(Class<?> nmsClass, Object instance, String fieldName, Object value) {
|
||||||
try {
|
|
||||||
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
throw new RuntimeException("Not Found Cache.");
|
throw new RuntimeException("Not Found Cache.");
|
||||||
@ -72,14 +71,14 @@ public class SimpleReflection {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new RuntimeException("Not Found Field.");
|
throw new RuntimeException("Not Found Field.");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
field.set(instance, value);
|
field.set(instance, value);
|
||||||
} catch (Exception e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) {
|
public static Object getFieldValue(Class<?> nmsClass, Object instance, String fieldName) {
|
||||||
try {
|
|
||||||
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
throw new RuntimeException("Not Found Cache.");
|
throw new RuntimeException("Not Found Cache.");
|
||||||
@ -88,15 +87,15 @@ public class SimpleReflection {
|
|||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new RuntimeException("Not Found Field.");
|
throw new RuntimeException("Not Found Field.");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return field.get(instance);
|
return field.get(instance);
|
||||||
} catch (Exception e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) {
|
public static <T> T getFieldValue(Class<?> nmsClass, Object instance, String fieldName, T def) {
|
||||||
try {
|
|
||||||
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
Map<String, Field> fields = fieldCached.get(nmsClass.getName());
|
||||||
if (fields == null) {
|
if (fields == null) {
|
||||||
throw new RuntimeException("Not Found Cache.");
|
throw new RuntimeException("Not Found Cache.");
|
||||||
@ -105,8 +104,9 @@ public class SimpleReflection {
|
|||||||
if (field == null) {
|
if (field == null) {
|
||||||
throw new RuntimeException("Not Found Field.");
|
throw new RuntimeException("Not Found Field.");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return (T) field.get(instance);
|
return (T) field.get(instance);
|
||||||
} catch (Exception e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return def;
|
return def;
|
||||||
|
@ -15,5 +15,4 @@ object AsyncTask {
|
|||||||
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
def apply(init: Long, period: Long)(task: => Any)(implicit plugin: Plugin): Int = {
|
||||||
ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId
|
ScalaTaskExecutor(task).runTaskTimerAsynchronously(plugin, init, period).getTaskId
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,5 +29,4 @@ class Example extends JavaPlugin with Listener {
|
|||||||
class a
|
class a
|
||||||
assert(this == JavaPlugin.getProvidingPlugin(classOf[a]))
|
assert(this == JavaPlugin.getProvidingPlugin(classOf[a]))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user