@@ -82,7 +82,8 @@ public Object childEvaluate(
82
82
throws ParserException {
83
83
84
84
if (functionName .equalsIgnoreCase ("createMacro" )) {
85
- if (parameters .size () > 3 ) {
85
+ FunctionUtil .checkNumberParam (functionName , parameters , 1 , 6 );
86
+ if (parameters .size () > 4 ) {
86
87
if (parameters .get (4 ).toString ().equalsIgnoreCase ("campaign" )) {
87
88
return createMacro (parameters , false );
88
89
} else if (parameters .get (4 ).toString ().equalsIgnoreCase ("gm" )) {
@@ -100,10 +101,12 @@ public Object childEvaluate(
100
101
} else if (functionName .equalsIgnoreCase ("hasMacro" )) {
101
102
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
102
103
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
+ }
107
110
} else {
108
111
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
109
112
return token .getMacroNames (false ).contains (label ) ? BigDecimal .ONE : BigDecimal .ZERO ;
@@ -112,10 +115,12 @@ public Object childEvaluate(
112
115
} else if (functionName .equalsIgnoreCase ("getMacros" )) {
113
116
FunctionUtil .checkNumberParam (functionName , parameters , 0 , 3 );
114
117
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
+ }
119
124
} else {
120
125
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
121
126
return getMacros (delim , token );
@@ -125,10 +130,12 @@ public Object childEvaluate(
125
130
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
126
131
int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
127
132
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
+ }
132
139
} else {
133
140
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
134
141
return getMacroButtonProps (token , index , delim );
@@ -139,10 +146,12 @@ public Object childEvaluate(
139
146
Object value = parameters .get (0 );
140
147
String props = parameters .get (1 ).toString ();
141
148
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
+ }
146
155
} else {
147
156
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 3 , 4 );
148
157
return setMacroProps (value , props , delim , token );
@@ -153,11 +162,14 @@ public Object childEvaluate(
153
162
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
154
163
String label = parameters .get (0 ).toString ();
155
164
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
+ }
161
173
} else {
162
174
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
163
175
return getMacroIndexes (label , delim , token );
@@ -174,10 +186,12 @@ public Object childEvaluate(
174
186
FunctionUtil .blockUntrustedMacro (functionName );
175
187
int index = FunctionUtil .paramAsInteger (functionName , parameters , 0 , false );
176
188
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
+ }
181
195
} else {
182
196
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
183
197
return setMacroCommand (index , command , token );
@@ -186,10 +200,12 @@ public Object childEvaluate(
186
200
} else if (functionName .equalsIgnoreCase ("getMacroCommand" )) {
187
201
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
188
202
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
+ }
193
209
} else {
194
210
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
195
211
return getMacroCommand (index , token );
@@ -202,10 +218,12 @@ public Object childEvaluate(
202
218
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 4 );
203
219
String group = parameters .get (0 ).toString ();
204
220
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
+ }
209
227
} else {
210
228
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 2 , 3 );
211
229
return getMacroGroup (group , delim , token );
@@ -214,18 +232,19 @@ public Object childEvaluate(
214
232
} else if (functionName .equalsIgnoreCase ("removeMacro" )) {
215
233
FunctionUtil .checkNumberParam (functionName , parameters , 1 , 3 );
216
234
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
+ }
221
241
} else {
222
242
Token token = FunctionUtil .getTokenFromParam (resolver , functionName , parameters , 1 , 2 );
223
243
return removeMacro (index , token );
224
244
}
225
-
226
- } else { // should never happen, hopefully ;)
227
- throw new ParserException (I18N .getText (KEY_UNKNOWN_MACRO , functionName ));
228
245
}
246
+ /* code should never happen, hopefully ;) */
247
+ throw new ParserException (I18N .getText (KEY_UNKNOWN_MACRO , functionName ));
229
248
}
230
249
231
250
/**
@@ -1053,7 +1072,7 @@ private MacroButtonProperties macroButtonPropertiesFromJSON(
1053
1072
if (json == null ) json = JSONMacroFunctions .getInstance ().asJsonElement (propString );
1054
1073
JsonObject jobj = json .getAsJsonObject ();
1055
1074
if (jobj != null ) {
1056
- if (!jobj .has ("label" ))
1075
+ if (!jobj .has ("label" ) && mbp . getLabel (). isEmpty () )
1057
1076
throw new ParserException (I18N .getText (KEY_MISSING_LABEL , "createMacro" ));
1058
1077
if (jobj .has ("command" ) && !MapTool .getParser ().isMacroTrusted ()) {
1059
1078
int index = mbp .getIndex ();
0 commit comments