New API of TPluginManager#delayDisable
This commit is contained in:
parent
1878a67c6e
commit
8479abf02d
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.09</version>
|
<version>4.10</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -20,19 +20,26 @@ import java.util.regex.Pattern;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class TPluginManager implements PluginManager {
|
public class TPluginManager implements PluginManager {
|
||||||
|
|
||||||
|
private static TPluginManager singleton;
|
||||||
private final PluginManager instance;
|
private final PluginManager instance;
|
||||||
private final Main main = (Main) Main.getInst();
|
private final Main main = (Main) Main.getInst();
|
||||||
private static File updateDirectory = null;
|
private static File updateDirectory = null;
|
||||||
private Server server;
|
private Server server;
|
||||||
private Map<Pattern, PluginLoader> fileAssociations = new HashMap<>();
|
private Map<Pattern, PluginLoader> fileAssociations = new HashMap<>();
|
||||||
private List<Plugin> plugins = new ArrayList<>();
|
private List<Plugin> plugins = new ArrayList<>();
|
||||||
private Map<String, Plugin> lookupNames = new HashMap<>();
|
private Map<String, Plugin> lookupNames = new HashMap<>();
|
||||||
private SimpleCommandMap commandMap;
|
private SimpleCommandMap commandMap;
|
||||||
private Map<String, Permission> permissions = new HashMap<>();
|
private Map<String, Permission> permissions = new HashMap<>();
|
||||||
private Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<>();
|
private Map<Boolean, Set<Permission>> defaultPerms = new LinkedHashMap<>();
|
||||||
private Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<>();
|
private Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<>();
|
||||||
private Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<>();
|
private Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<>();
|
||||||
private boolean useTimings = false;
|
private boolean useTimings = false;
|
||||||
|
private List<Plugin> delayedDisable = new ArrayList<>();
|
||||||
|
|
||||||
|
public static void delayDisable(Plugin plugin) {
|
||||||
|
if (!singleton.delayedDisable.contains(plugin))
|
||||||
|
singleton.delayedDisable.add(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
public TPluginManager() {
|
public TPluginManager() {
|
||||||
instance = Bukkit.getPluginManager();
|
instance = Bukkit.getPluginManager();
|
||||||
@ -48,22 +55,23 @@ public class TPluginManager implements PluginManager {
|
|||||||
cloneField("permSubs");
|
cloneField("permSubs");
|
||||||
cloneField("defSubs");
|
cloneField("defSubs");
|
||||||
cloneField("useTimings");
|
cloneField("useTimings");
|
||||||
|
singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cloneField(String bukkitName) {
|
private void cloneField(String bukkitName) {
|
||||||
try {
|
try {
|
||||||
Field bukkitField = instance.getClass().getDeclaredField(bukkitName);
|
Field bukkitField = instance.getClass().getDeclaredField(bukkitName);
|
||||||
Field thisFiled = this.getClass().getDeclaredField(bukkitName);
|
Field thisFiled = this.getClass().getDeclaredField(bukkitName);
|
||||||
if (bukkitField == null || thisFiled == null) {
|
if (bukkitField == null || thisFiled == null) {
|
||||||
TLocale.Logger.warn("MISC.FIELD-COPY-FAILED", bukkitName);
|
TLocale.Logger.warn("MISC.FIELD-COPY-FAILED", bukkitName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bukkitField.setAccessible(true);
|
bukkitField.setAccessible(true);
|
||||||
thisFiled.setAccessible(true);
|
thisFiled.setAccessible(true);
|
||||||
thisFiled.set(this, bukkitField.get(instance));
|
thisFiled.set(this, bukkitField.get(instance));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TLocale.Logger.error("MISC.FIELD-COPY-ERROR", bukkitName, e.toString());
|
TLocale.Logger.error("MISC.FIELD-COPY-ERROR", bukkitName, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,10 +112,12 @@ public class TPluginManager implements PluginManager {
|
|||||||
@Override
|
@Override
|
||||||
public void disablePlugins() {
|
public void disablePlugins() {
|
||||||
for (Plugin plugin : getPlugins()) {
|
for (Plugin plugin : getPlugins()) {
|
||||||
if (plugin != main) {
|
if (plugin != main && !delayedDisable.contains(plugin)) {
|
||||||
disablePlugin(plugin);
|
disablePlugin(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Collections.reverse(delayedDisable);
|
||||||
|
delayedDisable.forEach(singleton::disablePlugin);
|
||||||
disablePlugin(main);
|
disablePlugin(main);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user