@@ -74,116 +74,110 @@ public class CoreModule extends AbstractListenerModule {
7474 @ Override
7575 public boolean loadMatch (Match match ) {
7676 Document document = match .getMap ().getDocument ();
77- for (Element coresElement : document .getRootElement ().getChildren ("cores" )) {
78- for (Element coreElement : coresElement .getChildren ("core" )) {
79- Located located = (Located ) coreElement ;
77+ for (Element coreElement : ParseUtil .getElementsIn (document .getRootElement (), "cores" , "core" )) {
78+ Located located = (Located ) coreElement ;
8079
81- String id = ParseUtil .getFirstAttribute ("id" , coreElement , coresElement );
80+ String id = coreElement .getAttributeValue ("id" );
81+ String name = coreElement .getAttributeValue ("name" , "Core" );
8282
83- String nameValue = ParseUtil .getFirstAttribute ("name" , coreElement , coresElement );
84- String name = nameValue == null ? "Core" : nameValue ;
83+ boolean required = Numbers .parseBoolean (coreElement .getAttributeValue ("required" ), true );
8584
86- String requiredValue = ParseUtil .getFirstAttribute ("required" , coreElement , coresElement );
87- boolean required = requiredValue == null || Numbers .parseBoolean (requiredValue );
85+ RegionModule regionModule = Cardinal .getModule (RegionModule .class );
86+ Region region ;
87+ try {
88+ region = regionModule .getRegion (match , coreElement );
89+ } catch (RegionException e ) {
90+ errors .add (new ModuleError (this , match .getMap (),
91+ new String []{RegionModule .getRegionError (e , "region" , "core" ),
92+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
93+ continue ;
94+ }
95+ if (region == null && coreElement .getAttribute ("region" ) != null ) {
96+ region = regionModule .getRegionById (match , coreElement .getAttributeValue ("region" ));
97+ }
98+ if (region == null ) {
99+ errors .add (new ModuleError (this , match .getMap (), new String []{"No region specified for core" ,
100+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
101+ continue ;
102+ }
103+ if (!region .isBounded ()) {
104+ errors .add (new ModuleError (this , match .getMap (),
105+ new String []{"Region specified for core must be a bounded region" ,
106+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
107+ continue ;
108+ }
88109
89- RegionModule regionModule = Cardinal .getModule (RegionModule .class );
90- Region region ;
110+ String leakValue = coreElement .getAttributeValue ("leak" );
111+ int leak = 5 ;
112+ if (leakValue != null ) {
91113 try {
92- region = regionModule . getRegion ( match , coreElement );
93- } catch (RegionException e ) {
114+ leak = Numbers . parseInteger ( leakValue );
115+ } catch (NumberFormatException e ) {
94116 errors .add (new ModuleError (this , match .getMap (),
95- new String []{RegionModule . getRegionError ( e , "region" , " core") ,
117+ new String []{"Invalid leak distance specified for core" ,
96118 "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
97119 continue ;
98120 }
99- if ( region == null && coresElement . getAttribute ( "region" ) != null ) {
100- region = regionModule . getRegionById ( match , coresElement . getAttributeValue ( "region" ));
101- }
102- if ( region == null ) {
103- errors . add ( new ModuleError ( this , match . getMap (), new String []{ "No region specified for core" ,
104- "Element at " + located . getLine () + ", " + located . getColumn ()}, false ));
105- continue ;
106- }
107- if (! region . isBounded () ) {
121+ }
122+
123+ MaterialPattern material = new MaterialPattern ( new AbstractMap . SimpleEntry <>( Material . OBSIDIAN ,
124+ MaterialPattern . ANY_DATA_VALUE ));
125+ String materialValue = coreElement . getAttributeValue ( "material" );
126+ if ( materialValue != null ) {
127+ try {
128+ material = MaterialPattern . getSingleMaterialPattern ( materialValue );
129+ } catch ( NumberFormatException e ) {
108130 errors .add (new ModuleError (this , match .getMap (),
109- new String []{"Region specified for core must be a bounded region " ,
131+ new String []{"Invalid data value of material specified for core " ,
110132 "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
111133 continue ;
112134 }
135+ }
136+ String teamValue = coreElement .getAttributeValue ("team" );
137+ if (teamValue == null ) {
138+ errors .add (new ModuleError (this , match .getMap (), new String []{"No team specified for wool" ,
139+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
140+ continue ;
141+ }
142+ Team team = Cardinal .getModule (TeamModule .class ).getTeamById (match , teamValue );
143+ if (team == null ) {
144+ errors .add (new ModuleError (this , match .getMap (), new String []{"Invalid team specified for core" ,
145+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
146+ continue ;
147+ }
113148
114- String leakValue = ParseUtil .getFirstAttribute ("leak" , coreElement , coresElement );
115- int leak = 5 ;
116- if (leakValue != null ) {
117- try {
118- leak = Numbers .parseInteger (leakValue );
119- } catch (NumberFormatException e ) {
120- errors .add (new ModuleError (this , match .getMap (),
121- new String []{"Invalid leak distance specified for core" ,
122- "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
123- continue ;
124- }
125- }
126-
127- MaterialPattern material = new MaterialPattern (new AbstractMap .SimpleEntry <>(Material .OBSIDIAN ,
128- MaterialPattern .ANY_DATA_VALUE ));
129- String materialValue = ParseUtil .getFirstAttribute ("material" , coreElement , coresElement );
130- if (materialValue != null ) {
131- try {
132- material = MaterialPattern .getSingleMaterialPattern (materialValue );
133- } catch (NumberFormatException e ) {
134- errors .add (new ModuleError (this , match .getMap (),
135- new String []{"Invalid data value of material specified for core" ,
136- "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
137- continue ;
138- }
139- }
140- String teamValue = ParseUtil .getFirstAttribute ("team" , coreElement , coresElement );
141- if (teamValue == null ) {
142- errors .add (new ModuleError (this , match .getMap (), new String []{"No team specified for core" ,
143- "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
144- continue ;
145- }
146- Team team = Cardinal .getModule (TeamModule .class ).getTeamById (match , teamValue );
147- if (team == null ) {
148- errors .add (new ModuleError (this , match .getMap (), new String []{"Invalid team specified for core" ,
149- "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
150- continue ;
151- }
152-
153- String modeChangesValue = ParseUtil .getFirstAttribute ("mode-changes" , coreElement , coresElement );
154- boolean modeChanges = modeChangesValue == null || Numbers .parseBoolean (modeChangesValue );
155-
156- String showValue = ParseUtil .getFirstAttribute ("show" , coreElement , coresElement );
157- boolean show = showValue == null || Numbers .parseBoolean (showValue );
158-
159- ProximityMetric proximityMetric = ProximityMetric .CLOSEST_PLAYER ;
160- String woolProximityMetricValue = ParseUtil .getFirstAttribute ("proximity-metric" , coreElement , coresElement );
161- if (woolProximityMetricValue != null ) {
162- try {
163- proximityMetric =
164- ProximityMetric .valueOf (Strings .getTechnicalName (woolProximityMetricValue ));
165- } catch (IllegalArgumentException e ) {
166- errors .add (new ModuleError (this , match .getMap (),
167- new String []{"Invalid proximity metric specified for core" ,
168- "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
169- continue ;
170- }
171- }
149+ String modeChangesValue = coreElement .getAttributeValue ("mode-changes" );
150+ boolean modeChanges = modeChangesValue == null || Numbers .parseBoolean (modeChangesValue );
172151
173- String proximityHorizontalValue = ParseUtil .getFirstAttribute ("proximity-horizontal" , coreElement ,
174- coresElement );
175- boolean proximityHorizontal = proximityHorizontalValue != null
176- && Numbers .parseBoolean (proximityHorizontalValue );
152+ String showValue = coreElement .getAttributeValue ("show" );
153+ boolean show = showValue == null || Numbers .parseBoolean (showValue );
177154
178- Core core = new Core (match , id , name , required , region , leak , material , team , modeChanges , show ,
179- proximityMetric , proximityHorizontal );
180- if (!IdModule .get ().add (match , id , core )) {
155+ ProximityMetric proximityMetric = ProximityMetric .CLOSEST_PLAYER ;
156+ String proximityMetricValue = coreElement .getAttributeValue ("proximity-metric" );
157+ if (proximityMetricValue != null ) {
158+ try {
159+ proximityMetric =
160+ ProximityMetric .valueOf (Strings .getTechnicalName (proximityMetricValue ));
161+ } catch (IllegalArgumentException e ) {
181162 errors .add (new ModuleError (this , match .getMap (),
182- new String []{"Core id is not valid or already in use " ,
163+ new String []{"Invalid proximity metric specified for core " ,
183164 "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
184- IdModule . get (). add ( match , null , core , true ) ;
165+ continue ;
185166 }
186167 }
168+
169+ String proximityHorizontalValue = coreElement .getAttributeValue ("proximity-horizontal" );
170+ boolean proximityHorizontal = proximityHorizontalValue != null
171+ && Numbers .parseBoolean (proximityHorizontalValue );
172+
173+ Core core = new Core (match , id , name , required , region , leak , material , team , modeChanges , show ,
174+ proximityMetric , proximityHorizontal );
175+ if (!IdModule .get ().add (match , id , core )) {
176+ errors .add (new ModuleError (this , match .getMap (),
177+ new String []{"Core id is not valid or already in use" ,
178+ "Element at " + located .getLine () + ", " + located .getColumn ()}, false ));
179+ IdModule .get ().add (match , null , core , true );
180+ }
187181 }
188182 return true ;
189183 }
0 commit comments