diff --git a/.gitignore b/.gitignore index 6136bf5..c4a2af9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ hs_err_pid* .gradle/4.3.1/ .idea -target \ No newline at end of file +target +TabooLib.iml \ No newline at end of file diff --git a/pom.xml b/pom.xml index 59b125b..0b6faf7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,13 +6,10 @@ me.skymc TabooLib - 4.09 + 4.10 UTF-8 - 1.5 - 1.5 - off clean install package @@ -33,8 +30,10 @@ maven-compiler-plugin 3.7.0 - 8 - 8 + 1.8 + 1.8 + false + true diff --git a/src/main/java/com/ilummc/tlib/ExampleMain.java b/src/main/java/com/ilummc/tlib/ExampleMain.java index f3f1739..324599f 100644 --- a/src/main/java/com/ilummc/tlib/ExampleMain.java +++ b/src/main/java/com/ilummc/tlib/ExampleMain.java @@ -5,9 +5,35 @@ import com.ilummc.tlib.bean.Property; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.lang.management.GarbageCollectorMXBean; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryMXBean; +import java.util.concurrent.TimeUnit; + @TConfig(name = "cfg.yml", charset = "GBK") public class ExampleMain extends JavaPlugin { + public static void main(String[] args) { + MemoryMXBean bean = ManagementFactory.getMemoryMXBean(); + System.out.println(bean.getHeapMemoryUsage().toString()); + System.out.println(bean.getNonHeapMemoryUsage().toString()); + for (int i = 0; i < 10; i++) { + for (GarbageCollectorMXBean mxBean : ManagementFactory.getGarbageCollectorMXBeans()) { + System.out.println(mxBean.getName()); + System.out.println(mxBean.getCollectionCount()); + System.out.println(mxBean.getCollectionTime()); + for (String s : mxBean.getMemoryPoolNames()) { + System.out.println(s); + } + System.out.println(mxBean.getObjectName().toString()); + } + System.gc(); + } + for (String s : ManagementFactory.getRuntimeMXBean().getInputArguments()) { + System.out.println(s); + } + } + private Property update = Property.of(false); @Override @@ -31,4 +57,58 @@ public class ExampleMain extends JavaPlugin { } } + + private static class CD { + + final long start, period; + final TimeUnit unit; + final Runnable onStart, onFinish, onTimer; + + CD(long start, long period, TimeUnit unit, Runnable onStart, Runnable onFinish, Runnable onTimer) { + this.start = start; + this.period = period; + this.unit = unit; + this.onStart = onStart; + this.onFinish = onFinish; + this.onTimer = onTimer; + } + + public static void main(String[] args) { + CD.builder().setOnStart(() -> { + }).setOnFinish(() -> { + }).setOnTimer(1000, TimeUnit.MILLISECONDS, () -> { + }).build(); + } + + public static CdBuilder builder() { + return new CdBuilder(); + } + + private static class CdBuilder { + private long start, period; + private TimeUnit unit; + private Runnable onStart, onFinish, onTimer; + + public CdBuilder setOnStart(Runnable runnable) { + this.onStart = runnable; + return this; + } + + public CdBuilder setOnFinish(Runnable runnable) { + this.onFinish = runnable; + return this; + } + + public CdBuilder setOnTimer(long period, TimeUnit timeUnit, Runnable runnable) { + this.period = period; + this.unit = timeUnit; + this.onTimer = runnable; + return this; + } + + public CD build() { + return new CD(start, period, unit, onStart, onFinish, onTimer); + } + } + } } 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); }