use of com.laytonsmith.core.exceptions.PrefilterNonMatchException in project CommandHelper by EngineHub.
the class EventUtils method GetMatchingEvents.
/**
* Returns a set of events that should be triggered by this event.
*
* @param type
* @param eventName
* @param e
* @return
*/
public static SortedSet<BoundEvent> GetMatchingEvents(Driver type, String eventName, BindableEvent e, Event driver) {
SortedSet<BoundEvent> toRun = new TreeSet<>();
// This is the set of bounded events of this driver type.
// We must now look through the bound events to see if they are
// the eventName, and if so, we will also run the prefilter.
SortedSet<BoundEvent> bounded = GetEvents(type);
if (bounded != null) {
// Wrap this in a new set, so we can safely iterate it with async threads
bounded = new TreeSet<>(bounded);
for (BoundEvent b : bounded) {
try {
boolean matches = false;
try {
matches = driver.matches(b.getPrefilter(), e);
} catch (ConfigRuntimeException ex) {
// This can happen in limited cases, but still needs to be
// handled properly. This would happen if, for instance, a
// prefilter was configured improperly with bad runtime data.
// We use the environment from the bound event.
ConfigRuntimeException.HandleUncaughtException(ex, b.getEnvironment());
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError err) {
// This happens when a CH extension depends on a not-included or binary outdated class.
// Log the error and continue since there's nothing we can do about it.
String chBrand = Implementation.GetServerType().getBranding();
String chVersion = Static.getVersion().toString();
String culprit = chBrand;
outerLoop: for (ExtensionTracker tracker : ExtensionManager.getTrackers().values()) {
for (Event event : tracker.getEvents()) {
if (event.getName().equals(driver.getName())) {
for (Extension extension : tracker.getExtensions()) {
culprit = extension.getName();
break outerLoop;
}
}
}
}
String modVersion;
try {
modVersion = StaticLayer.GetConvertor().GetServer().getAPIVersion();
} catch (Exception ex) {
modVersion = Implementation.GetServerType().name();
}
String extensionData = "";
for (ExtensionTracker tracker : ExtensionManager.getTrackers().values()) {
for (Extension extension : tracker.getExtensions()) {
try {
extensionData += TermColors.CYAN + extension.getName() + TermColors.RED + " (" + TermColors.RESET + extension.getVersion() + TermColors.RED + ")\n";
} catch (AbstractMethodError ex) {
// This happens with an old style extensions. Just skip it.
extensionData += TermColors.CYAN + "Unknown Extension" + TermColors.RED + "\n";
}
}
}
if (extensionData.isEmpty()) {
extensionData = "NONE\n";
}
String driverEventName = driver.getName();
String jarName = new File(driver.getSourceJar().getFile()).getName();
String emsg = TermColors.RED + "Uh oh! You've found an error in the eventhandler for event " + TermColors.CYAN + driverEventName + TermColors.RED + ", implemented in " + TermColors.CYAN + culprit + " (" + jarName + ")" + TermColors.RED + ".\n" + "Please report this to the developers, and be sure to include the version numbers:\n" + TermColors.CYAN + "Server" + TermColors.RED + " version: " + TermColors.RESET + modVersion + TermColors.RED + ";\n" + TermColors.CYAN + chBrand + TermColors.RED + " version: " + TermColors.RESET + chVersion + TermColors.RED + ";\n" + "Loaded extensions and versions:\n" + extensionData + "Here's the stacktrace:\n" + TermColors.RESET + Static.GetStacktraceString(err);
Static.getLogger().log(Level.SEVERE, emsg);
// If we can't match it, it's not a match.
continue;
}
if (b.getEventName().equals(eventName) && matches) {
toRun.add(b);
}
} catch (PrefilterNonMatchException ex) {
// Not running this one
}
}
}
return toRun;
}
use of com.laytonsmith.core.exceptions.PrefilterNonMatchException in project CommandHelper by EngineHub.
the class Prefilters method MathMatch.
private static void MathMatch(Construct one, Construct two) throws PrefilterNonMatchException {
try {
double dOne = Static.getNumber(one, Target.UNKNOWN);
double dTwo = Static.getNumber(two, Target.UNKNOWN);
if (dOne != dTwo) {
throw new PrefilterNonMatchException();
}
} catch (ConfigRuntimeException e) {
throw new PrefilterNonMatchException();
}
}
use of com.laytonsmith.core.exceptions.PrefilterNonMatchException in project CommandHelper by EngineHub.
the class Prefilters method ExpressionMatch.
private static void ExpressionMatch(Construct expression, String key, Construct dvalue) throws PrefilterNonMatchException {
String exp = expression.val().substring(1, expression.val().length() - 1);
boolean inequalityMode = false;
if (exp.contains("<") || exp.contains(">") || exp.contains("==")) {
inequalityMode = true;
}
String eClass = "com.sk89q.worldedit.internal.expression.Expression";
String errClass = "com.sk89q.worldedit.internal.expression.ExpressionException";
Class eClazz, errClazz;
try {
eClazz = Class.forName(eClass);
errClazz = Class.forName(errClass);
} catch (ClassNotFoundException cnf) {
throw new CREPluginInternalException("You are missing a required dependency: " + eClass, expression.getTarget(), cnf);
}
try {
Object e = ReflectionUtils.invokeMethod(eClazz, null, "compile", new Class[] { String.class, String[].class }, new Object[] { exp, new String[] { key } });
double val = (double) ReflectionUtils.invokeMethod(eClazz, e, "evaluate", new Class[] { double[].class }, new Object[] { new double[] { Static.getDouble(dvalue, Target.UNKNOWN) } });
if (inequalityMode) {
if (val == 0) {
throw new PrefilterNonMatchException();
}
} else {
if (val != Static.getDouble(dvalue, Target.UNKNOWN)) {
throw new PrefilterNonMatchException();
}
}
} catch (ReflectionUtils.ReflectionException rex) {
if (rex.getCause().getClass().isAssignableFrom(errClazz)) {
throw new CREPluginInternalException("Your expression was invalidly formatted", expression.getTarget(), rex.getCause());
} else {
throw new CREPluginInternalException(rex.getMessage(), expression.getTarget(), rex.getCause());
}
}
}
use of com.laytonsmith.core.exceptions.PrefilterNonMatchException in project CommandHelper by EngineHub.
the class Prefilters method LocationMatch.
private static void LocationMatch(Construct location1, Construct location2) throws PrefilterNonMatchException {
MCLocation l1 = ObjectGenerator.GetGenerator().location(location1, null, location1.getTarget());
MCLocation l2 = ObjectGenerator.GetGenerator().location(location2, null, Target.UNKNOWN);
if ((!l1.getWorld().equals(l2.getWorld())) || (l1.getBlockX() != l2.getBlockX()) || (l1.getBlockY() != l2.getBlockY()) || (l1.getBlockZ() != l2.getBlockZ())) {
throw new PrefilterNonMatchException();
}
}
use of com.laytonsmith.core.exceptions.PrefilterNonMatchException in project CommandHelper by EngineHub.
the class Prefilters method ItemMatch.
private static void ItemMatch(Construct item1, Construct item2) throws PrefilterNonMatchException {
String i1 = item1.val().split(":")[0];
String i2 = item2.val().split(":")[0];
if (!i1.trim().equals(i2)) {
throw new PrefilterNonMatchException();
}
}
Aggregations