AsmClassTransformer

This commit is contained in:
Izzel_Aliz
2018-04-29 15:44:01 +08:00
parent 250d168c2e
commit da8890b30a
12 changed files with 285 additions and 92 deletions

View File

@@ -3,6 +3,7 @@ package me.skymc.taboolib.fileutils;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.bean.Property;
import com.ilummc.tlib.util.Ref;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
@@ -86,13 +87,20 @@ public class ConfigUtils {
}
}
@SuppressWarnings("unchecked")
public static <T> T mapToObj(Map<String, Object> map, T obj) {
Class<?> clazz = obj.getClass();
map.forEach((string, value) -> Ref.getFieldBySerializedName(clazz, string).ifPresent(field -> {
if (!field.isAccessible())
field.setAccessible(true);
try {
field.set(obj, value);
if (Property.class.isAssignableFrom(field.getType())) {
Property<Object> property = (Property) field.get(obj);
if (property != null) property.set(value);
else field.set(obj, Property.of(value));
} else {
field.set(obj, value);
}
} catch (IllegalAccessException ignored) {
}
}));
@@ -108,7 +116,9 @@ public class ConfigUtils {
for (Field field : Ref.getDeclaredFields(object.getClass(), excludedModifiers, false)) {
try {
if (!field.isAccessible()) field.setAccessible(true);
map.put(Ref.getSerializedName(field), field.get(object));
Object obj = field.get(object);
if (obj instanceof Property) obj = ((Property) obj).get();
map.put(Ref.getSerializedName(field), obj);
} catch (IllegalAccessException ignored) {
}
}

View File

@@ -1,22 +1,14 @@
package me.skymc.taboolib.fileutils;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ch.njol.util.Closeable;
import me.skymc.taboolib.message.MsgUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.FileChannel;
import ch.njol.util.Closeable;
import me.skymc.taboolib.message.MsgUtils;
public class FileUtils {
public static String ip() {
@@ -247,6 +239,11 @@ public class FileUtils {
}
return null;
}
public static String getStringFromURL(String url, String def) {
String s = getStringFromURL(url, 1024);
return s == null ? def : s;
}
/**
* 下载文件