Looks like Rhino is not guaranteed after all. Add some checks.
Dieser Commit ist enthalten in:
Ursprung
8a5ebb88e0
Commit
cd78e311d5
@ -198,6 +198,9 @@ public class CommandFilter extends CommandBase {
|
|||||||
*/
|
*/
|
||||||
public static final String NAME = "filter";
|
public static final String NAME = "filter";
|
||||||
|
|
||||||
|
// Default error handler
|
||||||
|
private FilterFailedHandler defaultFailedHandler;
|
||||||
|
|
||||||
// Currently registered filters
|
// Currently registered filters
|
||||||
private List<Filter> filters = new ArrayList<Filter>();
|
private List<Filter> filters = new ArrayList<Filter>();
|
||||||
|
|
||||||
@ -223,6 +226,11 @@ public class CommandFilter extends CommandBase {
|
|||||||
try {
|
try {
|
||||||
// First attempt
|
// First attempt
|
||||||
initializeEngine();
|
initializeEngine();
|
||||||
|
|
||||||
|
// Oh for ..
|
||||||
|
if (!isInitialized()) {
|
||||||
|
throw new ScriptException("A JavaScript engine could not be found.");
|
||||||
|
}
|
||||||
} catch (ScriptException e1) {
|
} catch (ScriptException e1) {
|
||||||
// It's not a huge deal
|
// It's not a huge deal
|
||||||
printPackageWarning(e1);
|
printPackageWarning(e1);
|
||||||
@ -234,6 +242,10 @@ public class CommandFilter extends CommandBase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
initializeEngine();
|
initializeEngine();
|
||||||
|
|
||||||
|
if (!isInitialized()) {
|
||||||
|
reporter.reportWarning(this, "Could not load Rhino either. Please upgrade your JVM or OS.");
|
||||||
|
}
|
||||||
} catch (ScriptException e2) {
|
} catch (ScriptException e2) {
|
||||||
// And again ..
|
// And again ..
|
||||||
printPackageWarning(e2);
|
printPackageWarning(e2);
|
||||||
@ -255,9 +267,33 @@ public class CommandFilter extends CommandBase {
|
|||||||
engine = manager.getEngineByName(config.getScriptEngineName());
|
engine = manager.getEngineByName(config.getScriptEngineName());
|
||||||
|
|
||||||
// Import useful packages
|
// Import useful packages
|
||||||
|
if (engine != null) {
|
||||||
engine.eval("importPackage(org.bukkit);");
|
engine.eval("importPackage(org.bukkit);");
|
||||||
engine.eval("importPackage(com.comphenix.protocol.reflect);");
|
engine.eval("importPackage(com.comphenix.protocol.reflect);");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the filter engine has been successfully initialized.
|
||||||
|
* @return TRUE if it has, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isInitialized() {
|
||||||
|
return engine != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FilterFailedHandler getDefaultErrorHandler() {
|
||||||
|
// No need to create a new object every time
|
||||||
|
if (defaultFailedHandler == null) {
|
||||||
|
defaultFailedHandler = new FilterFailedHandler() {
|
||||||
|
@Override
|
||||||
|
public boolean handle(PacketEvent event, Filter filter, Exception ex) {
|
||||||
|
reporter.reportMinimal(plugin, "filterEvent(PacketEvent)", ex, event);
|
||||||
|
reporter.reportWarning(this, "Removing filter " + filter.getName() + " for causing an exception.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return defaultFailedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,14 +304,7 @@ public class CommandFilter extends CommandBase {
|
|||||||
* @return TRUE if we should, FALSE otherwise.
|
* @return TRUE if we should, FALSE otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean filterEvent(PacketEvent event) {
|
public boolean filterEvent(PacketEvent event) {
|
||||||
return filterEvent(event, new FilterFailedHandler() {
|
return filterEvent(event, getDefaultErrorHandler());
|
||||||
@Override
|
|
||||||
public boolean handle(PacketEvent event, Filter filter, Exception ex) {
|
|
||||||
reporter.reportMinimal(plugin, "filterEvent(PacketEvent)", ex, event);
|
|
||||||
reporter.reportWarning(this, "Removing filter " + filter.getName() + " for causing an exception.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -313,6 +342,10 @@ public class CommandFilter extends CommandBase {
|
|||||||
sender.sendMessage(ChatColor.RED + "Debug mode must be enabled in the configuration first!");
|
sender.sendMessage(ChatColor.RED + "Debug mode must be enabled in the configuration first!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!isInitialized()) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "JavaScript engine was not present. Filter system is disabled.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
final SubCommand command = parseCommand(args, 0);
|
final SubCommand command = parseCommand(args, 0);
|
||||||
final String name = args[1];
|
final String name = args[1];
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren