|
1 | 1 | package com.laytonsmith.core.events; |
2 | 2 |
|
| 3 | +import com.laytonsmith.PureUtilities.TermColors; |
| 4 | +import com.laytonsmith.abstraction.Implementation; |
| 5 | +import com.laytonsmith.abstraction.StaticLayer; |
| 6 | +import com.laytonsmith.core.Static; |
3 | 7 | import com.laytonsmith.core.constructs.CArray; |
4 | 8 | import com.laytonsmith.core.constructs.CString; |
5 | 9 | import com.laytonsmith.core.constructs.Construct; |
6 | 10 | import com.laytonsmith.core.constructs.Target; |
7 | 11 | import com.laytonsmith.core.events.BoundEvent.Priority; |
8 | 12 | import com.laytonsmith.core.exceptions.CRE.CREBindException; |
9 | 13 | import com.laytonsmith.core.exceptions.CRE.CREEventException; |
| 14 | +import com.laytonsmith.core.extensions.Extension; |
| 15 | +import com.laytonsmith.core.extensions.ExtensionManager; |
| 16 | +import com.laytonsmith.core.extensions.ExtensionTracker; |
10 | 17 | import com.laytonsmith.core.exceptions.ConfigRuntimeException; |
11 | 18 | import com.laytonsmith.core.exceptions.EventException; |
12 | 19 | import com.laytonsmith.core.exceptions.FunctionReturnException; |
13 | 20 | import com.laytonsmith.core.exceptions.PrefilterNonMatchException; |
| 21 | + |
| 22 | +import java.io.File; |
14 | 23 | import java.util.EnumMap; |
15 | 24 | import java.util.Iterator; |
16 | 25 | import java.util.Map; |
17 | 26 | import java.util.Set; |
18 | 27 | import java.util.SortedSet; |
19 | 28 | import java.util.TreeSet; |
| 29 | +import java.util.logging.Level; |
20 | 30 |
|
21 | 31 | /** |
22 | 32 | * |
@@ -200,6 +210,63 @@ public static SortedSet<BoundEvent> GetMatchingEvents(Driver type, String eventN |
200 | 210 | //prefilter was configured improperly with bad runtime data. |
201 | 211 | //We use the environment from the bound event. |
202 | 212 | ConfigRuntimeException.HandleUncaughtException(ex, b.getEnvironment()); |
| 213 | + } catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError err) { |
| 214 | + // This happens when a CH extension depends on a not-included or binary outdated class. |
| 215 | + // Log the error and continue since there's nothing we can do about it. |
| 216 | + |
| 217 | + String chBrand = Implementation.GetServerType().getBranding(); |
| 218 | + String chVersion = Static.getVersion().toString(); |
| 219 | + |
| 220 | + String culprit = chBrand; |
| 221 | + outerLoop: |
| 222 | + for(ExtensionTracker tracker : ExtensionManager.getTrackers().values()) { |
| 223 | + for(Event event : tracker.getEvents()) { |
| 224 | + if(event.getName().equals(driver.getName())) { |
| 225 | + for(Extension extension : tracker.getExtensions()) { |
| 226 | + culprit = extension.getName(); |
| 227 | + break outerLoop; |
| 228 | + } |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + |
| 233 | + String modVersion; |
| 234 | + try{ |
| 235 | + modVersion = StaticLayer.GetConvertor().GetServer().getAPIVersion(); |
| 236 | + } catch(Exception ex){ |
| 237 | + modVersion = Implementation.GetServerType().name(); |
| 238 | + } |
| 239 | + |
| 240 | + String extensionData = ""; |
| 241 | + for(ExtensionTracker tracker : ExtensionManager.getTrackers().values()){ |
| 242 | + for(Extension extension : tracker.getExtensions()){ |
| 243 | + try { |
| 244 | + extensionData += TermColors.CYAN + extension.getName() + TermColors.RED |
| 245 | + + " (" + TermColors.RESET + extension.getVersion() + TermColors.RED + ")\n"; |
| 246 | + } catch(AbstractMethodError ex){ |
| 247 | + // This happens with an old style extensions. Just skip it. |
| 248 | + extensionData += TermColors.CYAN + "Unknown Extension" + TermColors.RED + "\n"; |
| 249 | + } |
| 250 | + } |
| 251 | + } |
| 252 | + if(extensionData.isEmpty()){ |
| 253 | + extensionData = "NONE\n"; |
| 254 | + } |
| 255 | + |
| 256 | + String driverEventName = driver.getName(); |
| 257 | + String jarName = new File(driver.getSourceJar().getFile()).getName(); |
| 258 | + String emsg = TermColors.RED + "Uh oh! You've found an error in the eventhandler for event " |
| 259 | + + TermColors.CYAN + driverEventName + TermColors.RED + ", implemented in " |
| 260 | + + TermColors.CYAN + culprit + " (" + jarName + ")" + TermColors.RED + ".\n" |
| 261 | + + "Please report this to the developers, and be sure to include the version numbers:\n" |
| 262 | + + TermColors.CYAN + "Server" + TermColors.RED + " version: " |
| 263 | + + TermColors.RESET + modVersion + TermColors.RED + ";\n" |
| 264 | + + TermColors.CYAN + chBrand + TermColors.RED + " version: " |
| 265 | + + TermColors.RESET + chVersion + TermColors.RED + ";\n" |
| 266 | + + "Loaded extensions and versions:\n" + extensionData |
| 267 | + + "Here's the stacktrace:\n" + TermColors.RESET + Static.GetStacktraceString(err); |
| 268 | + Static.getLogger().log(Level.SEVERE, emsg); |
| 269 | + continue; // If we can't match it, it's not a match. |
203 | 270 | } |
204 | 271 | if (b.getEventName().equals(eventName) && matches) { |
205 | 272 | toRun.add(b); |
|
0 commit comments