From bd596869a5ede4f6266c2c1763b5df291f1f7ae3 Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Fri, 2 Sep 2022 23:53:38 +0200 Subject: [PATCH] Fix objective filter not reacting dynamically (#1050) Signed-off-by: Pablete1234 Signed-off-by: Samuel Roach --- .../main/java/tc/oc/pgm/filters/FilterMatchModule.java | 10 ++++++++++ .../tc/oc/pgm/filters/operator/TeamFilterAdapter.java | 7 +++++++ .../tc/oc/pgm/modes/ObjectiveModesMatchModule.java | 1 + 3 files changed, 18 insertions(+) diff --git a/core/src/main/java/tc/oc/pgm/filters/FilterMatchModule.java b/core/src/main/java/tc/oc/pgm/filters/FilterMatchModule.java index 32a3a88f52..f44cfddb75 100644 --- a/core/src/main/java/tc/oc/pgm/filters/FilterMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/filters/FilterMatchModule.java @@ -188,6 +188,16 @@ private > void register( throw new IllegalStateException("Cannot register filter listener after match has started"); } + // Ideally this should never happen. All features that try to register a dynamic filter should + // have ensured that the filter can respond dynamically to the scope, at XML parse time. + // However, that does not occur, nothing is validating dynamic filters' scopes at all. + // The proper fix is to have a validation, using FeatureValidation and all features + // that will use a filter dynamically to validate the scope. + if (!filter.respondsTo(scope)) { + throw new IllegalStateException( + "Filter " + filter + " does not respond to " + scope.getSimpleName() + " scope"); + } + final ListenerSet listenerSet = this.listeners.row(filter).computeIfAbsent(scope, s -> new ListenerSet()); diff --git a/core/src/main/java/tc/oc/pgm/filters/operator/TeamFilterAdapter.java b/core/src/main/java/tc/oc/pgm/filters/operator/TeamFilterAdapter.java index 183474c9f7..b15cc30cb2 100644 --- a/core/src/main/java/tc/oc/pgm/filters/operator/TeamFilterAdapter.java +++ b/core/src/main/java/tc/oc/pgm/filters/operator/TeamFilterAdapter.java @@ -1,6 +1,8 @@ package tc.oc.pgm.filters.operator; +import java.util.Collection; import java.util.Optional; +import org.bukkit.event.Event; import tc.oc.pgm.api.filter.query.MatchQuery; import tc.oc.pgm.features.XMLFeatureReference; import tc.oc.pgm.filters.matcher.TypedFilter; @@ -41,6 +43,11 @@ public boolean isDynamic() { return filter.isDynamic(); } + @Override + public Collection> getRelevantEvents() { + return filter.getRelevantEvents(); + } + @Override public Class queryType() { return MatchQuery.class; diff --git a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java index 76371325ca..f95d80b282 100644 --- a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java @@ -52,6 +52,7 @@ public void load() throws ModuleLoadException { if (mode.getFilter() != null) { // if filter returns ALLOW at any time in the match, start countdown for mode change fmm.onRise( + Match.class, mode.getFilter(), listener -> { if (!this.countdownContext.isRunning(countdown) && match.isRunning()) {