From 8479abf02d62d0063b0a5c839a16d725a2d529b4 Mon Sep 17 00:00:00 2001 From: Izzel_Aliz Date: Thu, 14 Jun 2018 11:31:10 +0800 Subject: [PATCH] New API of TPluginManager#delayDisable --- pom.xml | 2 +- .../ilummc/tlib/inject/TPluginManager.java | 36 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 0ecda19..0b6faf7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.09 + 4.10 UTF-8 diff --git a/src/main/java/com/ilummc/tlib/inject/TPluginManager.java b/src/main/java/com/ilummc/tlib/inject/TPluginManager.java index 67832c5..ae5d1ca 100644 --- a/src/main/java/com/ilummc/tlib/inject/TPluginManager.java +++ b/src/main/java/com/ilummc/tlib/inject/TPluginManager.java @@ -20,19 +20,26 @@ import java.util.regex.Pattern; @SuppressWarnings("unused") public class TPluginManager implements PluginManager { + private static TPluginManager singleton; private final PluginManager instance; private final Main main = (Main) Main.getInst(); private static File updateDirectory = null; private Server server; private Map fileAssociations = new HashMap<>(); private List plugins = new ArrayList<>(); - private Map lookupNames = new HashMap<>(); + private Map lookupNames = new HashMap<>(); private SimpleCommandMap commandMap; private Map permissions = new HashMap<>(); private Map> defaultPerms = new LinkedHashMap<>(); private Map> permSubs = new HashMap<>(); private Map> defSubs = new HashMap<>(); private boolean useTimings = false; + private List delayedDisable = new ArrayList<>(); + + public static void delayDisable(Plugin plugin) { + if (!singleton.delayedDisable.contains(plugin)) + singleton.delayedDisable.add(plugin); + } public TPluginManager() { instance = Bukkit.getPluginManager(); @@ -48,22 +55,23 @@ public class TPluginManager implements PluginManager { cloneField("permSubs"); cloneField("defSubs"); cloneField("useTimings"); + singleton = this; } - + private void cloneField(String bukkitName) { - try { - Field bukkitField = instance.getClass().getDeclaredField(bukkitName); - Field thisFiled = this.getClass().getDeclaredField(bukkitName); - if (bukkitField == null || thisFiled == null) { + try { + Field bukkitField = instance.getClass().getDeclaredField(bukkitName); + Field thisFiled = this.getClass().getDeclaredField(bukkitName); + if (bukkitField == null || thisFiled == null) { TLocale.Logger.warn("MISC.FIELD-COPY-FAILED", bukkitName); - return; - } - bukkitField.setAccessible(true); - thisFiled.setAccessible(true); - thisFiled.set(this, bukkitField.get(instance)); + return; + } + bukkitField.setAccessible(true); + thisFiled.setAccessible(true); + thisFiled.set(this, bukkitField.get(instance)); } catch (Exception e) { TLocale.Logger.error("MISC.FIELD-COPY-ERROR", bukkitName, e.toString()); - } + } } @Override @@ -104,10 +112,12 @@ public class TPluginManager implements PluginManager { @Override public void disablePlugins() { for (Plugin plugin : getPlugins()) { - if (plugin != main) { + if (plugin != main && !delayedDisable.contains(plugin)) { disablePlugin(plugin); } } + Collections.reverse(delayedDisable); + delayedDisable.forEach(singleton::disablePlugin); disablePlugin(main); }