勉强能用的依赖加载系统做好了

This commit is contained in:
Izzel_Aliz 2018-04-04 20:00:39 +08:00
parent 946adbb3eb
commit add76a30cb
24 changed files with 665 additions and 57 deletions

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.ilummc.eagletdl:EagletCore:1.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/ilummc/eagletdl/EagletCore/1.0/EagletCore-1.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/ilummc/eagletdl/EagletCore/1.0/EagletCore-1.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/ilummc/eagletdl/EagletCore/1.0/EagletCore-1.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.ow2.asm:asm:5.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/5.2/asm-5.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/5.2/asm-5.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/5.2/asm-5.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.ow2.asm:asm:6.1.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/6.1.1/asm-6.1.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/6.1.1/asm-6.1.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/ow2/asm/asm/6.1.1/asm-6.1.1-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.projectlombok:lombok:1.16.20">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.20/lombok-1.16.20.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.20/lombok-1.16.20-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/projectlombok/lombok/1.16.20/lombok-1.16.20-sources.jar!/" />
</SOURCES>
</library>
</component>

31
pom.xml
View File

@ -41,7 +41,7 @@
<configuration>
<artifactSet>
<includes>
<include>org.ow2.asm</include>
<include>com.ilummc.eagletdl</include>
</includes>
</artifactSet>
<createDependencyReducedPom>false</createDependencyReducedPom>
@ -58,10 +58,20 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.ilummc.eagletdl</groupId>
<artifactId>EagletCore</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.2</version>
<version>6.1.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
<dependency>
<groupId>bukkit</groupId>
@ -70,6 +80,11 @@
<scope>system</scope>
<systemPath>${basedir}/libs/1_12_R1.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>bukkit</groupId>
<artifactId>bukkit1_8</artifactId>
@ -105,13 +120,6 @@
<scope>system</scope>
<systemPath>${basedir}/libs/com.sun.tools.jar</systemPath>
</dependency>
<dependency>
<groupId>lombok</groupId>
<artifactId>lombok</artifactId>
<version>1</version>
<scope>system</scope>
<systemPath>${basedir}/libs/lombok.jar</systemPath>
</dependency>
<dependency>
<groupId>placeholder</groupId>
<artifactId>placeholder</artifactId>
@ -140,11 +148,6 @@
<scope>system</scope>
<systemPath>${basedir}/libs/TabooCode5.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>wg</groupId>
<artifactId>wg</artifactId>

View File

@ -2,7 +2,7 @@ package com.ilummc.tlib;
import com.ilummc.tlib.annotations.Config;
import com.ilummc.tlib.annotations.ConfigNode;
import com.ilummc.tlib.bean.BooleanProperty;
import com.ilummc.tlib.bean.Property;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@ -10,7 +10,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class ExampleMain extends JavaPlugin {
@ConfigNode("enableUpdate")
private BooleanProperty update = new BooleanProperty(true);
private Property<Boolean> update = Property.of(false);
@Override
public void onEnable() {

View File

@ -0,0 +1,28 @@
package com.ilummc.tlib;
import com.ilummc.tlib.inject.TLibPluginManager;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit;
import java.io.File;
import java.lang.reflect.Field;
public class TLib {
@SuppressWarnings({"unchecked"})
public static void init() {
// 注入 PluginLoader 用于加载依赖
try {
Field field = Bukkit.getServer().getClass().getDeclaredField("pluginManager");
field.setAccessible(true);
field.set(Bukkit.getServer(), new TLibPluginManager());
MsgUtils.send("注入成功");
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
MsgUtils.warn("注入失败");
}
new File(Main.getInst().getDataFolder(), "/libs").mkdirs();
}
}

View File

@ -1,8 +0,0 @@
package com.ilummc.tlib;
public class TabooLib {
public void init() {
}
}

View File

@ -1,5 +1,12 @@
package com.ilummc.tlib.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Config {
String name() default "config.yml";

View File

@ -1,5 +1,12 @@
package com.ilummc.tlib.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConfigNode {
String value();

View File

@ -1,7 +1,14 @@
package com.ilummc.tlib.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Dependencies {
String[] value();
Dependency[] value();
}

View File

@ -0,0 +1,16 @@
package com.ilummc.tlib.annotations;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Dependencies.class)
public @interface Dependency {
enum Type {PLUGIN, LIBRARY}
Type type();
String[] args();
}

View File

@ -0,0 +1,18 @@
package com.ilummc.tlib.annotations;
import com.ilummc.tlib.util.TLogger;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Logger {
String value() default "[{0}] {1}";
int level() default TLogger.INFO;
}

View File

@ -1,5 +1,12 @@
package com.ilummc.tlib.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PluginInstance {
String value();

View File

@ -1,5 +1,12 @@
package com.ilummc.tlib.annotations.db;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface SQLTable {
String value();

View File

@ -1,17 +0,0 @@
package com.ilummc.tlib.bean;
import java.util.function.BiConsumer;
public class BooleanProperty {
private boolean property;
public BooleanProperty(boolean property) {
this.property = property;
}
public void addListener(BiConsumer<Boolean, Boolean> consumer) {
}
}

View File

@ -1,4 +1,41 @@
package com.ilummc.tlib.bean;
public class Property {
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
public class Property<T> {
private Property(T value) {
this.value = value;
}
private List<BiConsumer<T, T>> consumers;
private T value;
public void set(T value) {
if (value != this.value) {
if (consumers != null)
for (BiConsumer<T, T> consumer : consumers) {
consumer.accept(this.value, value);
}
this.value = value;
}
}
public T get() {
return value;
}
public void addListener(BiConsumer<T, T> consumer) {
if (consumers == null)
consumers = new ArrayList<>();
consumers.add(consumer);
}
public static <T> Property<T> of(T value) {
return new Property<>(value);
}
}

View File

@ -0,0 +1,77 @@
package com.ilummc.tlib.dependency;
import com.ilummc.eagletdl.EagletTask;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
public class TDependency {
public static final String MAVEN_REPO = "http://repo.maven.apache.org/maven2";
/**
* 请求一个插件作为依赖这个插件将会在所有已经添加的 Jenkins 仓库Maven 仓库寻找
* <p>
* 阻塞线程进行下载/加载
*
* @param args 插件名称下载地址可选
* @return 是否成功加载了依赖
*/
public static boolean requestPlugin(String... args) {
return false;
}
/**
* 请求一个库作为依赖这个库将会在 Maven Centraloss.sonatype 以及自定义的 Maven 仓库寻找
* <p>
* 阻塞线程进行下载/加载
*
* @param args 依赖名格式为 groupId:artifactId:version
* @return 是否成功加载库如果加载成功插件将可以任意调用使用的类
*/
public static boolean requestLib(String... args) {
if (args[0].matches(".*:.*:.*")) {
String[] arr = args[0].split(":");
File file = new File(Main.getInst().getDataFolder(), "/libs/" + String.join("-", arr) + ".jar");
if (file.exists()) {
TDependencyLoader.addToPath(Main.getInst(), file);
return true;
} else if (downloadMaven(MAVEN_REPO, arr[0], arr[1], arr[2], file)) {
TDependencyLoader.addToPath(Main.getInst(), file);
return true;
} else return false;
}
return false;
}
private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target) {
ReentrantLock lock = new ReentrantLock();
AtomicBoolean failed = new AtomicBoolean(false);
new EagletTask()
.url(url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar")
.file(target)
.setThreads(8)
.setOnStart(event -> lock.lock())
.setOnProgress(event -> MsgUtils.send(" 下载速度 " + event.getSpeedFormatted()))
.setOnConnected(event -> MsgUtils.send(" 正在下载 " + String.join(":", new String[]{groupId, artifactId, version}) +
" 大小 " + event.getContentLength()))
.setOnError(event -> failed.set(true))
.setOnComplete(event -> {
lock.unlock();
MsgUtils.send(" 下载 " + String.join(":", new String[]{groupId, artifactId, version}) + " 完成");
})
.start();
try {
while (lock.tryLock()) lock.unlock();
} catch (Exception ignored) {
} finally {
lock.lock();
lock.unlock();
}
return !failed.get();
}
}

View File

@ -0,0 +1,32 @@
package com.ilummc.tlib.dependency;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class TDependencyLoader {
public static synchronized void addToPath(Plugin plugin, URL url) {
try {
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(plugin.getClass().getClassLoader(), url);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
public static synchronized void addToPath(Plugin plugin, File file) {
try {
addToPath(plugin, file.toURI().toURL());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,99 @@
package com.ilummc.tlib.inject;
import com.ilummc.tlib.annotations.Dependencies;
import com.ilummc.tlib.annotations.Dependency;
import com.ilummc.tlib.annotations.Logger;
import com.ilummc.tlib.annotations.PluginInstance;
import com.ilummc.tlib.dependency.TDependency;
import com.ilummc.tlib.util.TLogger;
import me.skymc.taboolib.message.MsgUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
public class DependencyInjector {
public static void inject(Plugin plugin, Object o) {
injectLogger(plugin, o);
injectPluginInstance(plugin, o);
injectDependencies(plugin, o);
}
static void injectOnEnable(Plugin plugin) {
inject(plugin, plugin);
}
static void onDisable(Plugin plugin) {
}
private static void injectLogger(Plugin plugin, Object o) {
try {
for (Field field : o.getClass().getDeclaredFields()) {
Logger logger;
if ((logger = field.getAnnotation(Logger.class)) != null) {
field.getType().asSubclass(TLogger.class);
TLogger tLogger = new TLogger(logger.value(), plugin, logger.level());
if (!field.isAccessible())
field.setAccessible(true);
field.set(o, tLogger);
}
}
} catch (Exception ignored) {
}
}
private static void injectPluginInstance(Plugin plugin, Object o) {
try {
for (Field field : o.getClass().getDeclaredFields()) {
PluginInstance instance;
if ((instance = field.getAnnotation(PluginInstance.class)) != null) {
if (!field.isAccessible())
field.setAccessible(true);
field.getType().asSubclass(JavaPlugin.class);
Plugin pl;
if ((pl = Bukkit.getPluginManager().getPlugin(instance.value())) == null) {
if (!TDependency.requestPlugin(instance.value())) {
MsgUtils.warn(plugin.getName() + " 所需的依赖插件 " + instance.value() + " 自动加载失败");
return;
} else {
pl = Bukkit.getPluginManager().getPlugin(instance.value());
}
}
if (pl != null)
field.set(o, pl);
}
}
} catch (Exception ignored) {
}
}
private static void injectDependencies(Plugin plugin, Object o) {
Dependency[] dependencies = new Dependency[0];
{
Dependencies d = o.getClass().getAnnotation(Dependencies.class);
if (d != null) dependencies = d.value();
Dependency d2 = o.getClass().getAnnotation(Dependency.class);
if (d2 != null) dependencies = new Dependency[]{d2};
}
if (dependencies.length != 0) {
MsgUtils.send("正在加载 " + plugin.getName() + " 插件所需的依赖");
for (Dependency dependency : dependencies) {
if (dependency.type() == Dependency.Type.PLUGIN)
if (TDependency.requestPlugin(dependency.args()))
MsgUtils.send(plugin.getName() + " 请求的插件 " + dependency.args()[0] + " 加载成功。");
else
MsgUtils.warn(plugin.getName() + " 请求的插件 " + dependency.args()[0] + " 加载失败。");
if (dependency.type() == Dependency.Type.LIBRARY)
if (TDependency.requestLib(dependency.args()))
MsgUtils.send(plugin.getName() + " 请求的库文件 " + String.join(":", dependency.args()) + " 加载成功。");
else
MsgUtils.send(plugin.getName() + " 请求的库文件 " + String.join(":", dependency.args()) + " 加载失败。");
}
MsgUtils.send("依赖加载完成");
}
}
}

View File

@ -0,0 +1,168 @@
package com.ilummc.tlib.inject;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.*;
import java.io.File;
import java.util.Set;
public class TLibPluginManager implements PluginManager {
private final PluginManager instance;
public TLibPluginManager() {
instance = Bukkit.getPluginManager();
}
@Override
public void registerInterface(Class<? extends PluginLoader> aClass) throws IllegalArgumentException {
instance.registerInterface(aClass);
}
@Override
public Plugin getPlugin(String s) {
return instance.getPlugin(s);
}
@Override
public Plugin[] getPlugins() {
return instance.getPlugins();
}
@Override
public boolean isPluginEnabled(String s) {
return instance.isPluginEnabled(s);
}
@Override
public boolean isPluginEnabled(Plugin plugin) {
return instance.isPluginEnabled(plugin);
}
@Override
public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException {
return instance.loadPlugin(file);
}
@Override
public Plugin[] loadPlugins(File file) {
return instance.loadPlugins(file);
}
@Override
public void disablePlugins() {
instance.disablePlugins();
}
@Override
public void clearPlugins() {
instance.clearPlugins();
}
@Override
public void callEvent(Event event) throws IllegalStateException {
instance.callEvent(event);
}
@Override
public void registerEvents(Listener listener, Plugin plugin) {
instance.registerEvents(listener, plugin);
}
@Override
public void registerEvent(Class<? extends Event> aClass, Listener listener, EventPriority eventPriority, EventExecutor eventExecutor, Plugin plugin) {
instance.registerEvent(aClass, listener, eventPriority, eventExecutor, plugin);
}
@Override
public void registerEvent(Class<? extends Event> aClass, Listener listener, EventPriority eventPriority, EventExecutor eventExecutor, Plugin plugin, boolean b) {
instance.registerEvent(aClass, listener, eventPriority, eventExecutor, plugin, b);
}
@Override
public void enablePlugin(Plugin plugin) {
DependencyInjector.injectOnEnable(plugin);
instance.enablePlugin(plugin);
}
@Override
public void disablePlugin(Plugin plugin) {
DependencyInjector.onDisable(plugin);
instance.disablePlugin(plugin);
}
@Override
public Permission getPermission(String s) {
return instance.getPermission(s);
}
@Override
public void addPermission(Permission permission) {
instance.addPermission(permission);
}
@Override
public void removePermission(Permission permission) {
instance.removePermission(permission);
}
@Override
public void removePermission(String s) {
instance.removePermission(s);
}
@Override
public Set<Permission> getDefaultPermissions(boolean b) {
return instance.getDefaultPermissions(b);
}
@Override
public void recalculatePermissionDefaults(Permission permission) {
instance.recalculatePermissionDefaults(permission);
}
@Override
public void subscribeToPermission(String s, Permissible permissible) {
instance.subscribeToPermission(s, permissible);
}
@Override
public void unsubscribeFromPermission(String s, Permissible permissible) {
instance.unsubscribeFromPermission(s, permissible);
}
@Override
public Set<Permissible> getPermissionSubscriptions(String s) {
return instance.getPermissionSubscriptions(s);
}
@Override
public void subscribeToDefaultPerms(boolean b, Permissible permissible) {
instance.subscribeToDefaultPerms(b, permissible);
}
@Override
public void unsubscribeFromDefaultPerms(boolean b, Permissible permissible) {
instance.unsubscribeFromDefaultPerms(b, permissible);
}
@Override
public Set<Permissible> getDefaultPermSubscriptions(boolean b) {
return instance.getDefaultPermSubscriptions(b);
}
@Override
public Set<Permission> getPermissions() {
return instance.getPermissions();
}
@Override
public boolean useTimings() {
return instance.useTimings();
}
}

View File

@ -0,0 +1,27 @@
package com.ilummc.tlib.util;
public class Strings {
/**
* 优化过的 String#replace比默认快了大概 5
*
* @param template 模板替换文件
* @param args 替换的参数
* @return 替换好的字符串
*/
public static String replaceWithOrder(String template, String... args) {
char[] arr = template.toCharArray();
StringBuilder stringBuilder = new StringBuilder(template.length());
for (int i = 0; i < arr.length; i++) {
if (arr[i] == '{' && Character.isDigit(arr[Math.min(i + 1, arr.length - 1)])
&& arr[Math.min(i + 1, arr.length - 1)] - '0' < args.length
&& arr[Math.min(i + 2, arr.length - 1)] == '}') {
stringBuilder.append(args[arr[i + 1] - '0']);
i += 2;
} else
stringBuilder.append(arr[i]);
}
return stringBuilder.toString();
}
}

View File

@ -0,0 +1,63 @@
package com.ilummc.tlib.util;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
public class TLogger {
public static final int VERBOSE = 0, FINEST = 1, FINE = 2, INFO = 3, WARN = 4, ERROR = 5, FATAL = 6;
@Getter
private final String pattern;
@Getter
private Plugin plugin;
@Getter
@Setter
private int level;
public TLogger(String pattern, Plugin plugin, int level) {
this.pattern = pattern;
this.plugin = plugin;
this.level = level;
}
public void verbose(String msg) {
if (level >= VERBOSE)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void finest(String msg) {
if (level >= FINEST)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void fine(String msg) {
if (level >= FINE)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void info(String msg) {
if (level >= INFO)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void warn(String msg) {
if (level >= WARN)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void error(String msg) {
if (level >= ERROR)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
public void fatal(String msg) {
if (level >= FATAL)
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), msg));
}
}

View File

@ -1,5 +1,7 @@
package me.skymc.taboolib;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.annotations.Dependency;
import lombok.Getter;
import lombok.Setter;
import me.skymc.taboolib.anvil.AnvilContainerAPI;
@ -104,6 +106,8 @@ public class Main extends JavaPlugin implements Listener {
public void onLoad() {
inst = this; disable = false;
TLib.init();
// 启动监控
new Metrics(this);