25
25
26
26
package in .twizmwaz .cardinal .module .filter ;
27
27
28
+ import com .google .common .collect .Lists ;
28
29
import com .google .common .collect .Maps ;
29
30
import in .twizmwaz .cardinal .Cardinal ;
30
31
import in .twizmwaz .cardinal .event .match .MatchModuleLoadCompleteEvent ;
53
54
import in .twizmwaz .cardinal .module .filter .type .CreatureFilter ;
54
55
import in .twizmwaz .cardinal .module .filter .type .CrouchingFilter ;
55
56
import in .twizmwaz .cardinal .module .filter .type .EntityFilter ;
57
+ import in .twizmwaz .cardinal .module .filter .type .FilterReference ;
56
58
import in .twizmwaz .cardinal .module .filter .type .FlyingFilter ;
57
59
import in .twizmwaz .cardinal .module .filter .type .HoldingFilter ;
58
60
import in .twizmwaz .cardinal .module .filter .type .LayerFilter ;
84
86
import org .jdom2 .located .Located ;
85
87
86
88
import java .util .Collection ;
89
+ import java .util .List ;
87
90
import java .util .Map ;
88
91
89
92
@ ModuleEntry (depends = {RegionModule .class , TeamModule .class })
90
93
public class FilterModule extends AbstractModule implements Listener {
91
94
92
95
private Map <Match , Map <String , Filter >> filters = Maps .newHashMap ();
96
+ private Map <Match , List <FilterReference >> references = Maps .newHashMap ();
93
97
94
98
//Static filters. Can be shared across matches, because they use no arguments
95
99
public static final Filter ALLOW = new StaticFilter (FilterState .ALLOW );
@@ -114,6 +118,7 @@ public FilterModule() {
114
118
@ Override
115
119
public boolean loadMatch (@ NonNull Match match ) {
116
120
filters .put (match , Maps .newHashMap ());
121
+ references .put (match , Lists .newArrayList ());
117
122
for (Element filtersElement : match .getMap ().getDocument ().getRootElement ().getChildren ("filters" )) {
118
123
for (Element filterElement : filtersElement .getChildren ()) {
119
124
filters .get (match ).put ("always" , ALLOW );
@@ -125,6 +130,10 @@ public boolean loadMatch(@NonNull Match match) {
125
130
}
126
131
}
127
132
}
133
+ for (FilterReference reference : references .get (match )) {
134
+ reference .load (this , match );
135
+ }
136
+ references .remove (match );
128
137
return true ;
129
138
}
130
139
@@ -158,6 +167,12 @@ public Filter getFilter(@NonNull Match match, @NonNull String id) {
158
167
return filters .get (match ).get (id );
159
168
}
160
169
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
+
161
176
/**
162
177
* Parses an element for a filter.
163
178
*
@@ -312,7 +327,7 @@ public Filter getFilter(Match match, Element element, String... alternateAttribu
312
327
for (String alternateAttribute : alternateAttributes ) {
313
328
String filterValue = element .getAttributeValue (alternateAttribute );
314
329
if (filterValue != null ) {
315
- Filter filter = getFilter (match , filterValue );
330
+ Filter filter = getFilterReference (match , filterValue );
316
331
if (filter != null ) {
317
332
return checkFilter (match , id , filter );
318
333
}
@@ -321,7 +336,7 @@ public Filter getFilter(Match match, Element element, String... alternateAttribu
321
336
322
337
String filterValue = element .getAttributeValue ("id" );
323
338
if (filterValue != null ) {
324
- Filter filter = getFilter (match , filterValue );
339
+ Filter filter = getFilterReference (match , filterValue );
325
340
if (filter != null ) {
326
341
return checkFilter (match , id , filter );
327
342
}
0 commit comments