This commit is contained in:
坏黑 2018-06-22 17:56:35 +08:00
commit 1a73bc0bd7
4 changed files with 110 additions and 20 deletions

1
.gitignore vendored
View File

@ -22,3 +22,4 @@ hs_err_pid*
.gradle/4.3.1/
.idea
target
TabooLib.iml

11
pom.xml
View File

@ -6,13 +6,10 @@
<groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId>
<version>4.09</version>
<version>4.10</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compile.source>1.5</maven.compile.source>
<maven.compile.target>1.5</maven.compile.target>
<maven.compile.deprecation>off</maven.compile.deprecation>
</properties>
<build>
<defaultGoal>clean install package</defaultGoal>
@ -33,8 +30,10 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>8</source>
<target>8</target>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>false</showDeprecation>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>
<plugin>

View File

@ -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<Boolean> 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);
}
}
}
}

View File

@ -20,6 +20,7 @@ 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;
@ -33,6 +34,12 @@ public class TPluginManager implements PluginManager {
private Map<String, Map<Permissible, Boolean>> permSubs = new HashMap<>();
private Map<Boolean, Map<Permissible, Boolean>> defSubs = new HashMap<>();
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() {
instance = Bukkit.getPluginManager();
@ -48,6 +55,7 @@ public class TPluginManager implements PluginManager {
cloneField("permSubs");
cloneField("defSubs");
cloneField("useTimings");
singleton = this;
}
private void cloneField(String bukkitName) {
@ -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);
}