Remove unnecessary reflection

This commit is contained in:
MattBDev
2020-03-17 22:27:41 -04:00
parent ecedc1ff12
commit 1df5853f33
14 changed files with 18 additions and 59 deletions

View File

@ -2,8 +2,6 @@ package com.boydti.fawe.util;
import static org.slf4j.LoggerFactory.getLogger;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.object.brush.BrushSettings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sk89q.jnbt.CompoundTag;
@ -80,7 +78,7 @@ public final class BrushCache {
}
nbt = new CompoundTag(map = new HashMap<>());
} else {
map = ReflectionUtils.getMap(nbt.getValue());
map = nbt.getValue();
}
brushCache.remove(getKey(item));
CompoundTag display = (CompoundTag) map.get("display");

View File

@ -432,14 +432,14 @@ public class MainUtil {
}
public static void setPosition(CompoundTag tag, int x, int y, int z) {
Map<String, Tag> value = ReflectionUtils.getMap(tag.getValue());
Map<String, Tag> value = tag.getValue();
value.put("x", new IntTag(x));
value.put("y", new IntTag(y));
value.put("z", new IntTag(z));
}
public static void setEntityInfo(CompoundTag tag, Entity entity) {
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
Map<String, Tag> map = tag.getValue();
map.put("Id", new StringTag(entity.getState().getType().getId()));
ListTag pos = (ListTag) map.get("Pos");
if (pos != null) {

View File

@ -73,25 +73,6 @@ public class ReflectionUtils {
blankField(enumClass, "enumConstants"); // IBM JDK
}
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.emptyMap())
.getClass();
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
try {
Class<? extends Map> clazz = map.getClass();
if (clazz != UNMODIFIABLE_MAP) {
Fawe.debug("getMap is unused. Please report this to MattBDev on Github or Discord");
return map;
}
Field m = clazz.getDeclaredField("m");
m.setAccessible(true);
return (Map<T, V>) m.get(map);
} catch (Throwable e) {
e.printStackTrace();
return map;
}
}
public static <T> List<T> getList(List<T> list) {
try {
Class<? extends List<T>> clazz = (Class<? extends List<T>>) Class