Merge branch 'master' of https://github.com/Bkm016/TabooLib
This commit is contained in:
commit
1a73bc0bd7
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,3 +22,4 @@ hs_err_pid*
|
|||||||
.gradle/4.3.1/
|
.gradle/4.3.1/
|
||||||
.idea
|
.idea
|
||||||
target
|
target
|
||||||
|
TabooLib.iml
|
11
pom.xml
11
pom.xml
@ -6,13 +6,10 @@
|
|||||||
|
|
||||||
<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>
|
||||||
<maven.compile.source>1.5</maven.compile.source>
|
|
||||||
<maven.compile.target>1.5</maven.compile.target>
|
|
||||||
<maven.compile.deprecation>off</maven.compile.deprecation>
|
|
||||||
</properties>
|
</properties>
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean install package</defaultGoal>
|
<defaultGoal>clean install package</defaultGoal>
|
||||||
@ -33,8 +30,10 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>3.7.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>8</source>
|
<source>1.8</source>
|
||||||
<target>8</target>
|
<target>1.8</target>
|
||||||
|
<showDeprecation>false</showDeprecation>
|
||||||
|
<useIncrementalCompilation>true</useIncrementalCompilation>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -5,9 +5,35 @@ import com.ilummc.tlib.bean.Property;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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")
|
@TConfig(name = "cfg.yml", charset = "GBK")
|
||||||
public class ExampleMain extends JavaPlugin {
|
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);
|
private Property<Boolean> update = Property.of(false);
|
||||||
|
|
||||||
@Override
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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