2525
2626package in .twizmwaz .cardinal .module .filter ;
2727
28+ import com .google .common .collect .Lists ;
2829import com .google .common .collect .Maps ;
2930import in .twizmwaz .cardinal .Cardinal ;
3031import in .twizmwaz .cardinal .event .match .MatchModuleLoadCompleteEvent ;
5354import in .twizmwaz .cardinal .module .filter .type .CreatureFilter ;
5455import in .twizmwaz .cardinal .module .filter .type .CrouchingFilter ;
5556import in .twizmwaz .cardinal .module .filter .type .EntityFilter ;
57+ import in .twizmwaz .cardinal .module .filter .type .FilterReference ;
5658import in .twizmwaz .cardinal .module .filter .type .FlyingFilter ;
5759import in .twizmwaz .cardinal .module .filter .type .HoldingFilter ;
5860import in .twizmwaz .cardinal .module .filter .type .LayerFilter ;
8486import org .jdom2 .located .Located ;
8587
8688import java .util .Collection ;
89+ import java .util .List ;
8790import java .util .Map ;
8891
8992@ ModuleEntry (depends = {RegionModule .class , TeamModule .class })
9093public class FilterModule extends AbstractModule implements Listener {
9194
9295 private Map <Match , Map <String , Filter >> filters = Maps .newHashMap ();
96+ private Map <Match , List <FilterReference >> references = Maps .newHashMap ();
9397
9498 //Static filters. Can be shared across matches, because they use no arguments
9599 public static final Filter ALLOW = new StaticFilter (FilterState .ALLOW );
@@ -114,6 +118,7 @@ public FilterModule() {
114118 @ Override
115119 public boolean loadMatch (@ NonNull Match match ) {
116120 filters .put (match , Maps .newHashMap ());
121+ references .put (match , Lists .newArrayList ());
117122 for (Element filtersElement : match .getMap ().getDocument ().getRootElement ().getChildren ("filters" )) {
118123 for (Element filterElement : filtersElement .getChildren ()) {
119124 filters .get (match ).put ("always" , ALLOW );
@@ -125,6 +130,10 @@ public boolean loadMatch(@NonNull Match match) {
125130 }
126131 }
127132 }
133+ for (FilterReference reference : references .get (match )) {
134+ reference .load (this , match );
135+ }
136+ references .remove (match );
128137 return true ;
129138 }
130139
@@ -158,6 +167,12 @@ public Filter getFilter(@NonNull Match match, @NonNull String id) {
158167 return filters .get (match ).get (id );
159168 }
160169
170+ public Filter getFilterReference (@ NonNull Match match , @ NonNull String id ) {
171+ FilterReference reference = new FilterReference (id );
172+ references .get (match ).add (reference );
173+ return reference ;
174+ }
175+
161176 /**
162177 * Parses an element for a filter.
163178 *
@@ -312,7 +327,7 @@ public Filter getFilter(Match match, Element element, String... alternateAttribu
312327 for (String alternateAttribute : alternateAttributes ) {
313328 String filterValue = element .getAttributeValue (alternateAttribute );
314329 if (filterValue != null ) {
315- Filter filter = getFilter (match , filterValue );
330+ Filter filter = getFilterReference (match , filterValue );
316331 if (filter != null ) {
317332 return checkFilter (match , id , filter );
318333 }
@@ -321,7 +336,7 @@ public Filter getFilter(Match match, Element element, String... alternateAttribu
321336
322337 String filterValue = element .getAttributeValue ("id" );
323338 if (filterValue != null ) {
324- Filter filter = getFilter (match , filterValue );
339+ Filter filter = getFilterReference (match , filterValue );
325340 if (filter != null ) {
326341 return checkFilter (match , id , filter );
327342 }
0 commit comments