@@ -82,7 +82,8 @@ public Object childEvaluate(
8282 throws ParserException {
8383
8484 if (functionName .equalsIgnoreCase ("createMacro" )) {
85- if (parameters .size () > 3 ) {
85+ FunctionUtil .checkNumberParam (functionName , parameters , 1 , 6 );
86+ if (parameters .size () > 4 ) {
8687 if (parameters .get (4 ).toString ().equalsIgnoreCase ("campaign" )) {
8788 return createMacro (parameters , false );
8889 } else if (parameters .get (4 ).toString ().equalsIgnoreCase ("gm" )) {
@@ -100,10 +101,12 @@ public Object childEvaluate(
100101 } else if (functionName .equalsIgnoreCase ("hasMacro" )) {
101102 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
102103 String label = parameters .get (0 ).toString ();
103- if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
104- return hasMacro (label , false ) ? BigDecimal .ONE : BigDecimal .ZERO ;
105- } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
106- return hasMacro (label , true ) ? BigDecimal .ONE : BigDecimal .ZERO ;
104+ if (parameters .size () > 1 ) {
105+ if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
106+ return hasMacro (label , false ) ? BigDecimal .ONE : BigDecimal .ZERO ;
107+ } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
108+ return hasMacro (label , true ) ? BigDecimal .ONE : BigDecimal .ZERO ;
109+ }
107110 } else {
108111 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
109112 return token .getMacroNames (false ).contains (label ) ? BigDecimal .ONE : BigDecimal .ZERO ;
@@ -112,10 +115,12 @@ public Object childEvaluate(
112115 } else if (functionName .equalsIgnoreCase ("getMacros" )) {
113116 FunctionUtil .checkNumberParam (functionName , parameters , 0 , 3 );
114117 String delim = parameters .size () > 0 ? parameters .get (0 ).toString () : "," ;
115- if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
116- return getMacros (delim , MapTool .getCampaign ().getMacroButtonPropertiesArray ());
117- } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
118- return getMacros (delim , MapTool .getCampaign ().getGmMacroButtonPropertiesArray ());
118+ if (parameters .size () > 1 ) {
119+ if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
120+ return getMacros (delim , MapTool .getCampaign ().getMacroButtonPropertiesArray ());
121+ } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
122+ return getMacros (delim , MapTool .getCampaign ().getGmMacroButtonPropertiesArray ());
123+ }
119124 } else {
120125 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
121126 return getMacros (delim , token );
@@ -125,10 +130,12 @@ public Object childEvaluate(
125130 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
126131 int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
127132 String delim = parameters .size () > 1 ? parameters .get (1 ).toString () : ";" ;
128- if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
129- return getMacroButtonProps (index , delim , false );
130- } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
131- return getMacroButtonProps (index , delim , true );
133+ if (parameters .size () > 2 ) {
134+ if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
135+ return getMacroButtonProps (index , delim , false );
136+ } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
137+ return getMacroButtonProps (index , delim , true );
138+ }
132139 } else {
133140 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
134141 return getMacroButtonProps (token , index , delim );
@@ -139,10 +146,12 @@ public Object childEvaluate(
139146 Object value = parameters .get (0 );
140147 String props = parameters .get (1 ).toString ();
141148 String delim = parameters .size () > 2 ? parameters .get (2 ).toString () : ";" ;
142- if (parameters .get (3 ).toString ().equalsIgnoreCase ("campaign" )) {
143- return setMacroProps (value , props , delim , false );
144- } else if (parameters .get (3 ).toString ().equalsIgnoreCase ("gm" )) {
145- return setMacroProps (value , props , delim , true );
149+ if (parameters .size () > 3 ) {
150+ if (parameters .get (3 ).toString ().equalsIgnoreCase ("campaign" )) {
151+ return setMacroProps (value , props , delim , false );
152+ } else if (parameters .get (3 ).toString ().equalsIgnoreCase ("gm" )) {
153+ return setMacroProps (value , props , delim , true );
154+ }
146155 } else {
147156 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 3 , 4 );
148157 return setMacroProps (value , props , delim , token );
@@ -153,11 +162,14 @@ public Object childEvaluate(
153162 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
154163 String label = parameters .get (0 ).toString ();
155164 String delim = parameters .size () > 1 ? parameters .get (1 ).toString () : "," ;
156- if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
157- return getMacroIndexes (label , delim , MapTool .getCampaign ().getMacroButtonPropertiesArray ());
158- } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
159- return getMacroIndexes (
160- label , delim , MapTool .getCampaign ().getGmMacroButtonPropertiesArray ());
165+ if (parameters .size () > 2 ) {
166+ if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
167+ return getMacroIndexes (
168+ label , delim , MapTool .getCampaign ().getMacroButtonPropertiesArray ());
169+ } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
170+ return getMacroIndexes (
171+ label , delim , MapTool .getCampaign ().getGmMacroButtonPropertiesArray ());
172+ }
161173 } else {
162174 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
163175 return getMacroIndexes (label , delim , token );
@@ -174,10 +186,12 @@ public Object childEvaluate(
174186 FunctionUtil .blockUntrustedMacro (functionName );
175187 int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
176188 String command = FunctionUtil .paramAsString (functionName , parameters , 1 , true );
177- if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
178- return setMacroCommand (index , command , true );
179- } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
180- return setMacroCommand (index , command , false );
189+ if (parameters .size () > 2 ) {
190+ if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
191+ return setMacroCommand (index , command , true );
192+ } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
193+ return setMacroCommand (index , command , false );
194+ }
181195 } else {
182196 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
183197 return setMacroCommand (index , command , token );
@@ -186,10 +200,12 @@ public Object childEvaluate(
186200 } else if (functionName .equalsIgnoreCase ("getMacroCommand" )) {
187201 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
188202 int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
189- if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
190- return getMacroCommand (index , true );
191- } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
192- return getMacroCommand (index , false );
203+ if (parameters .size () > 1 ) {
204+ if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
205+ return getMacroCommand (index , true );
206+ } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
207+ return getMacroCommand (index , false );
208+ }
193209 } else {
194210 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
195211 return getMacroCommand (index , token );
@@ -202,10 +218,12 @@ public Object childEvaluate(
202218 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
203219 String group = parameters .get (0 ).toString ();
204220 String delim = parameters .size () > 1 ? parameters .get (1 ).toString () : "," ;
205- if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
206- return getMacroGroup (group , delim , true );
207- } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
208- return getMacroGroup (group , delim , false );
221+ if (parameters .size () > 2 ) {
222+ if (parameters .get (2 ).toString ().equalsIgnoreCase ("gm" )) {
223+ return getMacroGroup (group , delim , true );
224+ } else if (parameters .get (2 ).toString ().equalsIgnoreCase ("campaign" )) {
225+ return getMacroGroup (group , delim , false );
226+ }
209227 } else {
210228 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
211229 return getMacroGroup (group , delim , token );
@@ -214,18 +232,19 @@ public Object childEvaluate(
214232 } else if (functionName .equalsIgnoreCase ("removeMacro" )) {
215233 FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
216234 int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
217- if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
218- return removeMacro (index , true );
219- } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
220- return removeMacro (index , false );
235+ if (parameters .size () > 1 ) {
236+ if (parameters .get (1 ).toString ().equalsIgnoreCase ("gm" )) {
237+ return removeMacro (index , true );
238+ } else if (parameters .get (1 ).toString ().equalsIgnoreCase ("campaign" )) {
239+ return removeMacro (index , false );
240+ }
221241 } else {
222242 Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
223243 return removeMacro (index , token );
224244 }
225-
226- } else { // should never happen, hopefully ;)
227- throw new ParserException (I18N .getText (KEY_UNKNOWN_MACRO , functionName ));
228245 }
246+ /* code should never happen, hopefully ;) */
247+ throw new ParserException (I18N .getText (KEY_UNKNOWN_MACRO , functionName ));
229248 }
230249
231250 /**
@@ -1053,7 +1072,7 @@ private MacroButtonProperties macroButtonPropertiesFromJSON(
10531072 if (json == null ) json = JSONMacroFunctions .getInstance ().asJsonElement (propString );
10541073 JsonObject jobj = json .getAsJsonObject ();
10551074 if (jobj != null ) {
1056- if (!jobj .has ("label" ))
1075+ if (!jobj .has ("label" ) && mbp . getLabel (). isEmpty () )
10571076 throw new ParserException (I18N .getText (KEY_MISSING_LABEL , "createMacro" ));
10581077 if (jobj .has ("command" ) && !MapTool .getParser ().isMacroTrusted ()) {
10591078 int index = mbp .getIndex ();
0 commit comments