Skip to content

Commit

Permalink
Fix duplicated countdown filter bossbars (#1407)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Oct 7, 2024
1 parent 78df927 commit d89b4fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/tc/oc/pgm/api/filter/ReactorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface ReactorFactory<R extends ReactorFactory.Reactor>
extends FilterDefinition, StateHolder<R> {

default void register(Match match, FilterMatchModule fmm) {
match.getFeatureContext().registerState(this, createReactor(match, fmm));
if (!match.getFeatureContext().hasState(this))
match.getFeatureContext().registerState(this, createReactor(match, fmm));
}

/**
Expand Down
17 changes: 12 additions & 5 deletions core/src/main/java/tc/oc/pgm/features/MatchFeatureContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@
import tc.oc.pgm.api.feature.Feature;
import tc.oc.pgm.util.collection.ContextStore;

public class MatchFeatureContext extends ContextStore<Feature> {
public class MatchFeatureContext extends ContextStore<Feature<?>> {

private final Map<StateHolder<?>, Object> states = new IdentityHashMap<>();

public String add(Feature feature) {
public String add(Feature<?> feature) {
super.add(feature.getId(), feature);
return feature.getId();
}

public <T extends Feature> T get(String id, Class<T> type) {
@SuppressWarnings("unchecked")
public <T extends Feature<?>> T get(String id, Class<T> type) {
return (T) this.get(id);
}

public <T> void registerState(StateHolder<T> stateHolder, T state) {
states.put(stateHolder, state);
if (states.putIfAbsent(stateHolder, state) != null) {
throw new IllegalStateException("State already registered: " + stateHolder);
}
}

@SuppressWarnings("unchecked")
public <T> T getState(StateHolder<T> stateHolder) {
//noinspection unchecked
return (T) assertNotNull(states.get(stateHolder), "state");
}

public boolean hasState(StateHolder<?> stateHolder) {
return states.containsKey(stateHolder);
}

public Map<StateHolder<?>, Object> getStates() {
return Collections.unmodifiableMap(states);
}
Expand Down

0 comments on commit d89b4fb

Please sign in to comment.