Added the ability to recover from engine incompatibilities.
Dieser Commit ist enthalten in:
Ursprung
2411d29822
Commit
8a5ebb88e0
@ -220,16 +220,44 @@ public class CommandFilter extends CommandBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initalizeScript() {
|
private void initalizeScript() {
|
||||||
|
try {
|
||||||
|
// First attempt
|
||||||
|
initializeEngine();
|
||||||
|
} catch (ScriptException e1) {
|
||||||
|
// It's not a huge deal
|
||||||
|
printPackageWarning(e1);
|
||||||
|
|
||||||
|
if (!config.getScriptEngineName().equals("rhino")) {
|
||||||
|
reporter.reportWarning(this, "Falling back to the Rhino engine.");
|
||||||
|
config.setScriptEngineName("rhino");
|
||||||
|
config.saveAll();
|
||||||
|
|
||||||
|
try {
|
||||||
|
initializeEngine();
|
||||||
|
} catch (ScriptException e2) {
|
||||||
|
// And again ..
|
||||||
|
printPackageWarning(e2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printPackageWarning(ScriptException e) {
|
||||||
|
reporter.reportWarning(this, "Unable to initialize packages for JavaScript engine.", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the current configured engine.
|
||||||
|
* @throws ScriptException If we are unable to import packages.
|
||||||
|
*/
|
||||||
|
private void initializeEngine() throws ScriptException {
|
||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
ScriptEngineManager manager = new ScriptEngineManager();
|
||||||
engine = manager.getEngineByName("JavaScript");
|
engine = manager.getEngineByName(config.getScriptEngineName());
|
||||||
|
|
||||||
// Import useful packages
|
// Import useful packages
|
||||||
try {
|
|
||||||
engine.eval("importPackage(org.bukkit);");
|
engine.eval("importPackage(org.bukkit);");
|
||||||
engine.eval("importPackage(com.comphenix.protocol.reflect);");
|
engine.eval("importPackage(com.comphenix.protocol.reflect);");
|
||||||
} catch (ScriptException e) {
|
|
||||||
throw new IllegalStateException("Unable to initialize packages for JavaScript engine.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,9 +41,10 @@ class ProtocolConfig {
|
|||||||
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
|
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
|
||||||
|
|
||||||
private static final String DEBUG_MODE_ENABLED = "debug";
|
private static final String DEBUG_MODE_ENABLED = "debug";
|
||||||
|
|
||||||
private static final String INJECTION_METHOD = "injection method";
|
private static final String INJECTION_METHOD = "injection method";
|
||||||
|
|
||||||
|
private static final String SCRIPT_ENGINE_NAME = "script engine";
|
||||||
|
|
||||||
private static final String UPDATER_NOTIFY = "notify";
|
private static final String UPDATER_NOTIFY = "notify";
|
||||||
private static final String UPDATER_DOWNLAD = "download";
|
private static final String UPDATER_DOWNLAD = "download";
|
||||||
private static final String UPDATER_DELAY = "delay";
|
private static final String UPDATER_DELAY = "delay";
|
||||||
@ -257,6 +258,24 @@ class ProtocolConfig {
|
|||||||
updater.set(UPDATER_LAST_TIME, lastTimeSeconds);
|
updater.set(UPDATER_LAST_TIME, lastTimeSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the unique name of the script engine to use for filtering.
|
||||||
|
* @return Script engine to use.
|
||||||
|
*/
|
||||||
|
public String getScriptEngineName() {
|
||||||
|
return global.getString(SCRIPT_ENGINE_NAME, "JavaScript");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the unique name of the script engine to use for filtering.
|
||||||
|
* <p>
|
||||||
|
* This setting will take effect next time ProtocolLib is started.
|
||||||
|
* @param name - name of the script engine to use.
|
||||||
|
*/
|
||||||
|
public void setScriptEngineName(String name) {
|
||||||
|
global.set(SCRIPT_ENGINE_NAME, name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the default injection method.
|
* Retrieve the default injection method.
|
||||||
* @return Default method.
|
* @return Default method.
|
||||||
|
@ -22,3 +22,6 @@ global:
|
|||||||
|
|
||||||
# Whether or not to enable the filter command
|
# Whether or not to enable the filter command
|
||||||
debug: false
|
debug: false
|
||||||
|
|
||||||
|
# The engine used by the filter command
|
||||||
|
script engine: JavaScript
|
In neuem Issue referenzieren
Einen Benutzer sperren