v4.14
+ 修复:插件主动调用依赖注入方法后重复注入的问题
This commit is contained in:
parent
655e3c2619
commit
dd2e1f7d1c
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.skymc</groupId>
|
||||
<artifactId>TabooLib</artifactId>
|
||||
<version>4.13</version>
|
||||
<version>4.14</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -11,22 +11,23 @@ import java.util.logging.LogRecord;
|
||||
* @since 2018-04-22
|
||||
*/
|
||||
public class TLoggerFilter implements Filter {
|
||||
|
||||
public static void init() {
|
||||
Bukkit.getLogger().setFilter(new TLoggerFilter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord e) {
|
||||
if (e.getMessage().contains("Cannot load configuration from stream")) {
|
||||
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement element : elements) {
|
||||
if (element.getClassName().contains("ConfigUtils")) {
|
||||
System.out.println(Arrays.asList(e.getParameters()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else return !e.getMessage().contains("Enabled plugin with unregistered PluginClassLoader");
|
||||
|
||||
public static void init() {
|
||||
Bukkit.getLogger().setFilter(new TLoggerFilter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord e) {
|
||||
if (e.getMessage().contains("Cannot load configuration from stream")) {
|
||||
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement element : elements) {
|
||||
if (element.getClassName().contains("ConfigUtils")) {
|
||||
System.out.println(Arrays.asList(e.getParameters()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return !e.getMessage().contains("Enabled plugin with unregistered PluginClassLoader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,10 +13,17 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Izzel_Aliz
|
||||
*/
|
||||
public class TDependencyInjector {
|
||||
|
||||
private static List<String> injected = new ArrayList<>();
|
||||
|
||||
public static Dependency[] getDependencies(Object o) {
|
||||
Dependency[] dependencies = new Dependency[0];
|
||||
Dependencies d = o.getClass().getAnnotation(Dependencies.class);
|
||||
@ -30,26 +37,28 @@ public class TDependencyInjector {
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public static void inject(Plugin plugin, Object o) {
|
||||
TLocaleLoader.load(plugin, true);
|
||||
injectDependencies(plugin, o);
|
||||
injectLogger(plugin, o);
|
||||
injectConfig(plugin, o);
|
||||
injectPluginInstance(plugin, o);
|
||||
}
|
||||
|
||||
static void injectOnEnable(Plugin plugin) {
|
||||
if (!plugin.equals(Main.getInst())) {
|
||||
inject(plugin, plugin);
|
||||
}
|
||||
inject(plugin, plugin);
|
||||
}
|
||||
|
||||
static void onDisable(Plugin plugin) {
|
||||
static void ejectOnDisable(Plugin plugin) {
|
||||
eject(plugin, plugin);
|
||||
}
|
||||
|
||||
public static void inject(Plugin plugin, Object o) {
|
||||
if (!plugin.equals(Main.getInst()) && !injected.contains(plugin.getName())) {
|
||||
injected.add(plugin.getName());
|
||||
TLocaleLoader.load(plugin, true);
|
||||
injectDependencies(plugin, o);
|
||||
injectLogger(plugin, o);
|
||||
injectConfig(plugin, o);
|
||||
injectPluginInstance(plugin, o);
|
||||
}
|
||||
}
|
||||
|
||||
public static void eject(Plugin plugin, Object o) {
|
||||
try {
|
||||
injected.remove(plugin.getName());
|
||||
ejectConfig(plugin, o);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class TPluginManager implements PluginManager {
|
||||
|
||||
@Override
|
||||
public void disablePlugin(Plugin plugin) {
|
||||
TDependencyInjector.onDisable(plugin);
|
||||
TDependencyInjector.ejectOnDisable(plugin);
|
||||
instance.disablePlugin(plugin);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user