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>
|
<groupId>me.skymc</groupId>
|
||||||
<artifactId>TabooLib</artifactId>
|
<artifactId>TabooLib</artifactId>
|
||||||
<version>4.13</version>
|
<version>4.14</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -26,7 +26,8 @@ public class TLoggerFilter implements Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return !e.getMessage().contains("Enabled plugin with unregistered PluginClassLoader");
|
||||||
}
|
}
|
||||||
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.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Izzel_Aliz
|
||||||
|
*/
|
||||||
public class TDependencyInjector {
|
public class TDependencyInjector {
|
||||||
|
|
||||||
|
private static List<String> injected = new ArrayList<>();
|
||||||
|
|
||||||
public static Dependency[] getDependencies(Object o) {
|
public static Dependency[] getDependencies(Object o) {
|
||||||
Dependency[] dependencies = new Dependency[0];
|
Dependency[] dependencies = new Dependency[0];
|
||||||
Dependencies d = o.getClass().getAnnotation(Dependencies.class);
|
Dependencies d = o.getClass().getAnnotation(Dependencies.class);
|
||||||
@ -30,26 +37,28 @@ public class TDependencyInjector {
|
|||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void injectOnEnable(Plugin plugin) {
|
||||||
|
inject(plugin, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ejectOnDisable(Plugin plugin) {
|
||||||
|
eject(plugin, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public static void inject(Plugin plugin, Object o) {
|
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);
|
TLocaleLoader.load(plugin, true);
|
||||||
injectDependencies(plugin, o);
|
injectDependencies(plugin, o);
|
||||||
injectLogger(plugin, o);
|
injectLogger(plugin, o);
|
||||||
injectConfig(plugin, o);
|
injectConfig(plugin, o);
|
||||||
injectPluginInstance(plugin, o);
|
injectPluginInstance(plugin, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void injectOnEnable(Plugin plugin) {
|
|
||||||
if (!plugin.equals(Main.getInst())) {
|
|
||||||
inject(plugin, plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void onDisable(Plugin plugin) {
|
|
||||||
eject(plugin, plugin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void eject(Plugin plugin, Object o) {
|
public static void eject(Plugin plugin, Object o) {
|
||||||
try {
|
try {
|
||||||
|
injected.remove(plugin.getName());
|
||||||
ejectConfig(plugin, o);
|
ejectConfig(plugin, o);
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ public class TPluginManager implements PluginManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disablePlugin(Plugin plugin) {
|
public void disablePlugin(Plugin plugin) {
|
||||||
TDependencyInjector.onDisable(plugin);
|
TDependencyInjector.ejectOnDisable(plugin);
|
||||||
instance.disablePlugin(plugin);
|
instance.disablePlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user