Add mechanism to set default status(on/off) of plugin
This commit is contained in:
parent
0b4b4b1759
commit
ace2e63887
|
|
@ -101,6 +101,12 @@ public class Config {
|
||||||
*/
|
*/
|
||||||
public static List DISABLED_PLUGINS = new LinkedList();
|
public static List DISABLED_PLUGINS = new LinkedList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of force enable plugin, The value spilt by <code>,</code>
|
||||||
|
* if you have multiple plugins need to enable.
|
||||||
|
*/
|
||||||
|
public static List FORCE_ENABLE_PLUGINS = new LinkedList();
|
||||||
|
|
||||||
public static class MongoDB {
|
public static class MongoDB {
|
||||||
/**
|
/**
|
||||||
* If true, trace all the parameters, default is false.
|
* If true, trace all the parameters, default is false.
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,15 @@ public class PluginDefine {
|
||||||
*/
|
*/
|
||||||
private String defineClass;
|
private String defineClass;
|
||||||
|
|
||||||
private PluginDefine(String name, String defineClass) {
|
/**
|
||||||
|
* The sate of plugin.
|
||||||
|
*/
|
||||||
|
private State state;
|
||||||
|
|
||||||
|
private PluginDefine(String name, String defineClass, State state) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.defineClass = defineClass;
|
this.defineClass = defineClass;
|
||||||
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginDefine build(String define) throws IllegalPluginDefineException {
|
public static PluginDefine build(String define) throws IllegalPluginDefineException {
|
||||||
|
|
@ -30,16 +36,31 @@ public class PluginDefine {
|
||||||
throw new IllegalPluginDefineException(define);
|
throw new IllegalPluginDefineException(define);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PluginDefine(pluginDefine[0], pluginDefine[1]);
|
String pluginName = pluginDefine[0];
|
||||||
|
String defineClass = pluginDefine[1];
|
||||||
|
if (pluginName.toUpperCase().startsWith("[OFF]")) {
|
||||||
|
return new PluginDefine(pluginName.substring(5), defineClass, State.OFF);
|
||||||
|
} else {
|
||||||
|
return new PluginDefine(pluginName, defineClass, State.ON);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enable() {
|
public boolean enable() {
|
||||||
return !Config.Plugin.DISABLED_PLUGINS.contains(name);
|
return !Config.Plugin.DISABLED_PLUGINS.contains(name) || forceEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean forceEnable() {
|
||||||
|
return state == State.OFF && Config.Plugin.FORCE_ENABLE_PLUGINS.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefineClass() {
|
public String getDefineClass() {
|
||||||
return defineClass;
|
return defineClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum State {
|
||||||
|
OFF, ON;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue