This commit is contained in:
asofold 2015-11-29 09:03:51 +01:00
parent 4a8f19ef7a
commit fdf15fc33e

View File

@ -53,11 +53,11 @@ public final class NCPHookManager {
}; };
static{ static{
// Fill the map to be sure that thread safety can be guaranteed. // Fill the map to be sure that thread safety can be guaranteed.
for (final CheckType type : CheckType.values()){ for (final CheckType type : CheckType.values()){
if (APIUtils.needsSynchronization(type)) hooksByChecks.put(type, Collections.synchronizedList(new ArrayList<NCPHook>())); if (APIUtils.needsSynchronization(type)) hooksByChecks.put(type, Collections.synchronizedList(new ArrayList<NCPHook>()));
else hooksByChecks.put(type, new ArrayList<NCPHook>()); else hooksByChecks.put(type, new ArrayList<NCPHook>());
} }
} }
/** /**
@ -275,22 +275,22 @@ public final class NCPHookManager {
* @param throwable * @param throwable
* the throwable * the throwable
*/ */
private static final void logHookFailure(final CheckType checkType, final Player player, final NCPHook hook, private static final void logHookFailure(final CheckType checkType, final Player player, final NCPHook hook, final Throwable t) {
final Throwable t) {
// TODO: might accumulate failure rate and only log every so and so seconds or disable hook if spamming (leads // TODO: might accumulate failure rate and only log every so and so seconds or disable hook if spamming (leads
// to NCP spam though)? // to NCP spam though)?
final StringBuilder builder = new StringBuilder(1024); final StringBuilder builder = new StringBuilder(1024);
builder.append("Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n"); builder.append("Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n");
builder.append("Processing: "); builder.append("Processing: ");
if (checkType.getParent() != null) if (checkType.getParent() != null) {
builder.append("Prent " + checkType.getParent() + " "); builder.append("Parent " + checkType.getParent() + " ");
}
builder.append("Check " + checkType); builder.append("Check " + checkType);
builder.append(" Player " + player.getName()); builder.append(" Player " + player.getName());
builder.append("\n"); builder.append("\n");
builder.append("Exception (" + t.getClass().getSimpleName() + "): " + t.getMessage() + "\n"); builder.append("Exception (" + t.getClass().getSimpleName() + "): " + t.getMessage() + "\n");
for (final StackTraceElement el : t.getStackTrace()) for (final StackTraceElement el : t.getStackTrace()) {
builder.append(el.toString()); builder.append(el.toString());
}
Bukkit.getLogger().severe(builder.toString()); Bukkit.getLogger().severe(builder.toString());
} }
@ -412,17 +412,17 @@ public final class NCPHookManager {
public static final boolean shouldCancelVLProcessing(final ViolationData violationData) { public static final boolean shouldCancelVLProcessing(final ViolationData violationData) {
// Checks for hooks registered for this event, parent groups or ALL will be inserted into the list. // Checks for hooks registered for this event, parent groups or ALL will be inserted into the list.
// Return true as soon as one hook returns true. Test hooks, if present. // Return true as soon as one hook returns true. Test hooks, if present.
final CheckType type = violationData.check.getType(); final CheckType type = violationData.check.getType();
final List<NCPHook> hooksCheck = hooksByChecks.get(type); final List<NCPHook> hooksCheck = hooksByChecks.get(type);
if (!hooksCheck.isEmpty()){ if (!hooksCheck.isEmpty()){
if (APIUtils.needsSynchronization(type)){ if (APIUtils.needsSynchronization(type)){
synchronized (hooksCheck) { synchronized (hooksCheck) {
return applyHooks(type, violationData.player, violationData, hooksCheck); return applyHooks(type, violationData.player, violationData, hooksCheck);
} }
} }
else{ else{
return applyHooks(type, violationData.player, violationData, hooksCheck); return applyHooks(type, violationData.player, violationData, hooksCheck);
} }
} }
return false; return false;
} }