|
@@ -23,6 +23,7 @@
|
23
|
23
|
package com.dmdirc.commandparser.commands.flags;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.commandparser.CommandArguments;
|
|
26
|
+import com.dmdirc.events.CommandErrorEvent;
|
26
|
27
|
import com.dmdirc.interfaces.WindowModel;
|
27
|
28
|
|
28
|
29
|
import java.util.ArrayList;
|
|
@@ -131,13 +132,13 @@ public class CommandFlagHandler {
|
131
|
132
|
}
|
132
|
133
|
} else if (disabledBy.containsKey(name)) {
|
133
|
134
|
// Disabled by another flag
|
134
|
|
- sendLine(origin, arguments.isSilent(), "commandError",
|
|
135
|
+ sendError(origin, arguments.isSilent(),
|
135
|
136
|
"Cannot use flag --" + name
|
136
|
137
|
+ " in conjunction with --" + disabledBy.get(name).getName());
|
137
|
138
|
return null;
|
138
|
139
|
} else {
|
139
|
140
|
// Disabled because not yet enabled
|
140
|
|
- sendLine(origin, arguments.isSilent(), "commandError",
|
|
141
|
+ sendError(origin, arguments.isSilent(),
|
141
|
142
|
"Cannot use flag --" + name
|
142
|
143
|
+ " without " + getEnablers(flag));
|
143
|
144
|
return null;
|
|
@@ -181,8 +182,8 @@ public class CommandFlagHandler {
|
181
|
182
|
final int lastArg = argCount + offset - 1;
|
182
|
183
|
|
183
|
184
|
if (arguments.getArguments().length <= lastArg) {
|
184
|
|
- sendLine(origin, arguments.isSilent(),
|
185
|
|
- "commandError", "Flag --" + flag.getName() + " expects "
|
|
185
|
+ sendError(origin, arguments.isSilent(),
|
|
186
|
+ "Flag --" + flag.getName() + " expects "
|
186
|
187
|
+ argCount + " argument"
|
187
|
188
|
+ (argCount == 1 ? "" : "s"));
|
188
|
189
|
return -1;
|
|
@@ -244,17 +245,16 @@ public class CommandFlagHandler {
|
244
|
245
|
}
|
245
|
246
|
|
246
|
247
|
/**
|
247
|
|
- * Convenience method to send a line to the specified frame container.
|
|
248
|
+ * Convenience method to send a command error event.
|
248
|
249
|
*
|
249
|
|
- * @param origin The container to send the line to
|
|
250
|
+ * @param origin The container to send the event to
|
250
|
251
|
* @param isSilent Whether the command is silenced or not
|
251
|
|
- * @param messageType The type of the line to be sent
|
252
|
|
- * @param args The arguments for the specified messageType
|
|
252
|
+ * @param message The error message
|
253
|
253
|
*/
|
254
|
|
- protected static void sendLine(final WindowModel origin, final boolean isSilent,
|
255
|
|
- final String messageType, final Object... args) {
|
|
254
|
+ private static void sendError(final WindowModel origin, final boolean isSilent,
|
|
255
|
+ final String message) {
|
256
|
256
|
if (origin != null && !isSilent) {
|
257
|
|
- origin.addLine(messageType, args);
|
|
257
|
+ origin.getEventBus().publishAsync(new CommandErrorEvent(origin, message));
|
258
|
258
|
}
|
259
|
259
|
}
|
260
|
260
|
|