Skip to content

Commit

Permalink
Fix objective filter not reacting dynamically (PGMDev#1050)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
Signed-off-by: Samuel Roach <[email protected]>
  • Loading branch information
Pablete1234 authored and Samuel-Roach committed Sep 3, 2022
1 parent cd289d9 commit bd59686
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/tc/oc/pgm/filters/FilterMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ private <F extends Filterable<?>> 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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,6 +43,11 @@ public boolean isDynamic() {
return filter.isDynamic();
}

@Override
public Collection<Class<? extends Event>> getRelevantEvents() {
return filter.getRelevantEvents();
}

@Override
public Class<? extends MatchQuery> queryType() {
return MatchQuery.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit bd59686

Please sign in to comment.