|
@@ -29,6 +29,7 @@ import uk.org.ownage.dmdirc.Config;
|
29
|
29
|
import uk.org.ownage.dmdirc.Server;
|
30
|
30
|
import uk.org.ownage.dmdirc.ServerManager;
|
31
|
31
|
import uk.org.ownage.dmdirc.commandparser.commands.channel.*;
|
|
32
|
+import uk.org.ownage.dmdirc.commandparser.commands.global.*;
|
32
|
33
|
import uk.org.ownage.dmdirc.commandparser.commands.query.*;
|
33
|
34
|
import uk.org.ownage.dmdirc.commandparser.commands.server.*;
|
34
|
35
|
import uk.org.ownage.dmdirc.logger.ErrorLevel;
|
|
@@ -41,6 +42,10 @@ import uk.org.ownage.dmdirc.logger.Logger;
|
41
|
42
|
*/
|
42
|
43
|
public final class CommandManager {
|
43
|
44
|
|
|
45
|
+ /**
|
|
46
|
+ * The global commands that have been instansiated.
|
|
47
|
+ */
|
|
48
|
+ private static List<Command> globalCommands;
|
44
|
49
|
/**
|
45
|
50
|
* The server commands that have been instansiated.
|
46
|
51
|
*/
|
|
@@ -53,6 +58,10 @@ public final class CommandManager {
|
53
|
58
|
* The query commands that have been instansiated.
|
54
|
59
|
*/
|
55
|
60
|
private static List<Command> queryCommands;
|
|
61
|
+ /**
|
|
62
|
+ * The parsers that have requested global commands.
|
|
63
|
+ */
|
|
64
|
+ private static List<CommandParser> globalParsers;
|
56
|
65
|
/**
|
57
|
66
|
* The parsers that have requested server commands.
|
58
|
67
|
*/
|
|
@@ -99,6 +108,9 @@ public final class CommandManager {
|
99
|
108
|
} else if (command instanceof QueryCommand) {
|
100
|
109
|
target = queryParsers;
|
101
|
110
|
queryCommands.add(command);
|
|
111
|
+ } else if (command instanceof GlobalCommand) {
|
|
112
|
+ target = globalParsers;
|
|
113
|
+ globalCommands.add(command);
|
102
|
114
|
} else {
|
103
|
115
|
Logger.error(ErrorLevel.ERROR, "Attempted to register an invalid command: "
|
104
|
116
|
+ command.getClass().getName());
|
|
@@ -116,7 +128,7 @@ public final class CommandManager {
|
116
|
128
|
final String commandName = Config.getCommandChar() + command.getName();
|
117
|
129
|
|
118
|
130
|
for (Server server : ServerManager.getServerManager().getServers()) {
|
119
|
|
- if (command instanceof ServerCommand) {
|
|
131
|
+ if (command instanceof ServerCommand || command instanceof GlobalCommand) {
|
120
|
132
|
server.getTabCompleter().addEntry(commandName);
|
121
|
133
|
} else if (command instanceof ChannelCommand) {
|
122
|
134
|
for (String channelName : server.getChannels()) {
|
|
@@ -151,6 +163,9 @@ public final class CommandManager {
|
151
|
163
|
} else if (command instanceof QueryCommand) {
|
152
|
164
|
target = queryParsers;
|
153
|
165
|
queryCommands.remove(command);
|
|
166
|
+ } else if (command instanceof GlobalCommand) {
|
|
167
|
+ target = globalParsers;
|
|
168
|
+ globalCommands.remove(command);
|
154
|
169
|
} else {
|
155
|
170
|
Logger.error(ErrorLevel.ERROR, "Attempted to unregister an invalid command: "
|
156
|
171
|
+ command.getClass().getName());
|
|
@@ -168,7 +183,7 @@ public final class CommandManager {
|
168
|
183
|
final String commandName = Config.getCommandChar() + command.getName();
|
169
|
184
|
|
170
|
185
|
for (Server server : ServerManager.getServerManager().getServers()) {
|
171
|
|
- if (command instanceof ServerCommand) {
|
|
186
|
+ if (command instanceof ServerCommand || command instanceof GlobalCommand) {
|
172
|
187
|
server.getTabCompleter().removeEntry(commandName);
|
173
|
188
|
} else if (command instanceof ChannelCommand) {
|
174
|
189
|
for (String channelName : server.getChannels()) {
|
|
@@ -214,10 +229,12 @@ public final class CommandManager {
|
214
|
229
|
channelCommands = new ArrayList<Command>();
|
215
|
230
|
serverCommands = new ArrayList<Command>();
|
216
|
231
|
queryCommands = new ArrayList<Command>();
|
|
232
|
+ globalCommands = new ArrayList<Command>();
|
217
|
233
|
|
218
|
234
|
channelParsers = new ArrayList<CommandParser>();
|
219
|
235
|
serverParsers = new ArrayList<CommandParser>();
|
220
|
236
|
queryParsers = new ArrayList<CommandParser>();
|
|
237
|
+ globalParsers = new ArrayList<CommandParser>();
|
221
|
238
|
|
222
|
239
|
channelPopupCommands = new ArrayList<Command>();
|
223
|
240
|
|
|
@@ -266,8 +283,6 @@ public final class CommandManager {
|
266
|
283
|
new Nick();
|
267
|
284
|
new Notice();
|
268
|
285
|
new Query();
|
269
|
|
- new Exit();
|
270
|
|
- new ExitDefault();
|
271
|
286
|
new Raw();
|
272
|
287
|
new Reconnect();
|
273
|
288
|
new ReloadActions();
|
|
@@ -279,6 +294,10 @@ public final class CommandManager {
|
279
|
294
|
// Query commands
|
280
|
295
|
new QueryMe();
|
281
|
296
|
new QueryMeEmpty();
|
|
297
|
+
|
|
298
|
+ // Global commands
|
|
299
|
+ new Exit();
|
|
300
|
+ new ExitDefault();
|
282
|
301
|
}
|
283
|
302
|
|
284
|
303
|
/**
|
|
@@ -313,6 +332,22 @@ public final class CommandManager {
|
313
|
332
|
serverParsers.add(parser);
|
314
|
333
|
}
|
315
|
334
|
|
|
335
|
+ /**
|
|
336
|
+ * Loads all global commands into the specified parser.
|
|
337
|
+ * @param parser The parser to load commands into
|
|
338
|
+ */
|
|
339
|
+ public static void loadGlobalCommands(final CommandParser parser) {
|
|
340
|
+ if (globalCommands == null) {
|
|
341
|
+ initLists();
|
|
342
|
+ }
|
|
343
|
+
|
|
344
|
+ for (Command com : globalCommands) {
|
|
345
|
+ parser.registerCommand(com);
|
|
346
|
+ }
|
|
347
|
+
|
|
348
|
+ globalParsers.add(parser);
|
|
349
|
+ }
|
|
350
|
+
|
316
|
351
|
/**
|
317
|
352
|
* Loads all query commands into the specified parser.
|
318
|
353
|
* @param parser The parser to load commands into
|
|
@@ -349,6 +384,26 @@ public final class CommandManager {
|
349
|
384
|
return null;
|
350
|
385
|
}
|
351
|
386
|
|
|
387
|
+ /**
|
|
388
|
+ * Retrieves the global command identified by the specified signature.
|
|
389
|
+ * @param signature The signature to look for
|
|
390
|
+ * @return A global command with a matching signature, or null if none
|
|
391
|
+ * were found.
|
|
392
|
+ */
|
|
393
|
+ public static GlobalCommand getGlobalCommand(final String signature) {
|
|
394
|
+ if (globalCommands == null) {
|
|
395
|
+ initLists();
|
|
396
|
+ }
|
|
397
|
+
|
|
398
|
+ for (Command com : globalCommands) {
|
|
399
|
+ if (com.getSignature().equalsIgnoreCase(signature)) {
|
|
400
|
+ return (GlobalCommand) com;
|
|
401
|
+ }
|
|
402
|
+ }
|
|
403
|
+
|
|
404
|
+ return null;
|
|
405
|
+ }
|
|
406
|
+
|
352
|
407
|
/**
|
353
|
408
|
* Retrieves the channel command identified by the specified signature.
|
354
|
409
|
* @param signature The signature to look for
|