@@ -109,11 +109,34 @@ public void resolve() throws ImperatException {
109
109
if (currentParameter .isFlag ()) {
110
110
handleParameterFlag (currentParameter , currentRaw , flag );
111
111
continue ;
112
- } else if (Patterns .isInputFlag (currentRaw ) && command .getFlagFromRaw (currentRaw ).isPresent ()) {
113
- //FOUND FREE FLAG
114
- var flagData = command .getFlagFromRaw (currentRaw ).get ();
115
- ParameterFlag <S > parameterFlag = ParameterTypes .flag (flagData );
116
- context .resolveFlag (parameterFlag .resolveFreeFlag (context , stream , flagData ));
112
+ } else if (Patterns .isInputFlag (currentRaw )) {
113
+
114
+ if (command .getFlagFromRaw (currentRaw ).isPresent ()) {
115
+
116
+ //FOUND FREE FLAG
117
+ var flagData = command .getFlagFromRaw (currentRaw ).get ();
118
+ ImperatDebugger .debug ("Found free flag '%s' from raw input '%s'" , flagData .name (), currentRaw );
119
+
120
+ ParameterFlag <S > parameterFlag = ParameterTypes .flag (flagData );
121
+ context .resolveFlag (parameterFlag .resolveFreeFlag (context , stream , flagData ));
122
+
123
+ }else {
124
+
125
+ /*
126
+ * if the current param IS NOT A FLAG, & the current input matches a flag's criteria
127
+ * if the input also isn't from the free flags register that is linked to the command's instance, THEN
128
+ * this can be a case of two consecutive optional flags next to each other , example usage:
129
+ * '/ban <target> [-silent] [-ip] [duration] [reason]'
130
+ * If user enters '/ban mqzen -s -ip' this should work flawlessly, while '/ban mqzen -ip -s' DOESN'T resolve the silent flag,
131
+ * because of the algorithm that retains the parameters order while resolving their values.
132
+ * I think this can be fixed in the command tree instead of doing it here by making the tree shuffle the possibilities of
133
+ * flag-command-nodes.
134
+ */
135
+
136
+ //TODO fix this in the command tree
137
+ }
138
+
139
+ //we skip the raw input cursor only
117
140
stream .skipRaw ();
118
141
continue ;
119
142
}
@@ -163,7 +186,7 @@ public void resolve() throws ImperatException {
163
186
}
164
187
}
165
188
166
- private void handleParameterFlag (CommandParameter <S > currentParameter , String currentRaw , FlagData <S > flag ) throws ImperatException {
189
+ private void handleParameterFlag (CommandParameter <S > currentParameter , String currentRaw , @ Nullable FlagData <S > flag ) throws ImperatException {
167
190
ImperatDebugger .debug ("Found parameter flag '%s' from raw input '%s'" , currentParameter .format (), currentRaw );
168
191
ImperatDebugger .debug ("It's FlagData='%s'" , (flag == null ? "NULL" : flag .name ()));
169
192
@@ -202,12 +225,14 @@ private CommandParameter<S> findMatchingFlagParameter(
202
225
ParameterFlag <S > parameterFlag
203
226
) {
204
227
CommandParameter <S > flagParam = currentParameter ;
228
+
205
229
while (flagParam != null && !parameterFlag .matchesInput (currentRaw , flagParam )) {
206
230
if (!flagParam .isFlag ()) {
207
231
break ;
208
232
}
209
233
flagParam = stream .popParameter ().orElse (null );
210
234
}
235
+
211
236
return flagParam ;
212
237
}
213
238
0 commit comments