From 99c6fe20c24085cd154821af7c3c52501b7c67dd Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 16 May 2017 13:50:28 +0100 Subject: [PATCH] Catch exceptions thrown by context calculators --- .../luckperms/common/contexts/ContextManager.java | 7 ++++++- .../sponge/contexts/SpongeCalculatorLink.java | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java index 08df6c2bf..9c5dc4f86 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ContextManager.java @@ -48,7 +48,12 @@ public class ContextManager { private MutableContextSet calculateApplicableContext(T subject, MutableContextSet accumulator) { for (ContextCalculator calculator : calculators) { - calculator.giveApplicableContext(subject, accumulator); + try { + calculator.giveApplicableContext(subject, accumulator); + } catch (Exception e) { + new RuntimeException("Exception thrown by ContextCalculator: " + calculator.getClass().getName(), e).printStackTrace(); + } + } return accumulator; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java index 3c7bbfd0b..c19acdacd 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/contexts/SpongeCalculatorLink.java @@ -39,14 +39,19 @@ import java.util.Set; @AllArgsConstructor public class SpongeCalculatorLink implements ContextCalculator { - private final org.spongepowered.api.service.context.ContextCalculator calculator; + private final org.spongepowered.api.service.context.ContextCalculator delegate; @Override public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) { Set contexts = new HashSet<>(); - calculator.accumulateContexts(subject, contexts); - accumulator.addAll(CompatibilityUtil.convertContexts(contexts)); + try { + delegate.accumulateContexts(subject, contexts); + accumulator.addAll(CompatibilityUtil.convertContexts(contexts)); + } catch (Exception e) { + new RuntimeException("Exception thrown by delegate Sponge calculator: " + delegate.getClass().getName(), e).printStackTrace(); + } + return accumulator; } }