Archiviert
13
0

Added the ability to recover from engine incompatibilities.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-04-12 17:12:42 +02:00
Ursprung 2411d29822
Commit 8a5ebb88e0
3 geänderte Dateien mit 59 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -220,16 +220,44 @@ public class CommandFilter extends CommandBase {
}
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();
engine = manager.getEngineByName("JavaScript");
engine = manager.getEngineByName(config.getScriptEngineName());
// Import useful packages
try {
engine.eval("importPackage(org.bukkit);");
engine.eval("importPackage(com.comphenix.protocol.reflect);");
} catch (ScriptException e) {
throw new IllegalStateException("Unable to initialize packages for JavaScript engine.", e);
}
engine.eval("importPackage(org.bukkit);");
engine.eval("importPackage(com.comphenix.protocol.reflect);");
}
/**

Datei anzeigen

@ -41,9 +41,10 @@ class ProtocolConfig {
private static final String BACKGROUND_COMPILER_ENABLED = "background compiler";
private static final String DEBUG_MODE_ENABLED = "debug";
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_DOWNLAD = "download";
private static final String UPDATER_DELAY = "delay";
@ -257,6 +258,24 @@ class ProtocolConfig {
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.
* @return Default method.

Datei anzeigen

@ -21,4 +21,7 @@ global:
injection method:
# Whether or not to enable the filter command
debug: false
debug: false
# The engine used by the filter command
script engine: JavaScript