Quellcode durchsuchen

Added new chat command class

git-svn-id: http://svn.dmdirc.com/trunk@1778 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5
Chris Smith vor 17 Jahren
Ursprung
Commit
0d2a7b730b

+ 3
- 7
src/com/dmdirc/Channel.java Datei anzeigen

@@ -69,7 +69,7 @@ import javax.swing.SwingUtilities;
69 69
  *
70 70
  * @author chris
71 71
  */
72
-public final class Channel extends WritableFrameContainer implements
72
+public final class Channel extends MessageTarget implements
73 73
         IChannelMessage, IChannelGotNames, IChannelTopic, IChannelJoin,
74 74
         IChannelPart, IChannelKick, IChannelQuit, IChannelAction,
75 75
         IChannelNickChanged, IChannelModeChanged, IChannelUserModeChanged,
@@ -209,11 +209,7 @@ public final class Channel extends WritableFrameContainer implements
209 209
         return server.getParser().getMaxLength("PRIVMSG", getChannelInfo().getName());
210 210
     }
211 211
     
212
-    /**
213
-     * Sends the specified string as an action (CTCP) to the channel that this object
214
-     * represents.
215
-     * @param action The action to send
216
-     */
212
+    /** {@inheritDoc} */
217 213
     public void sendAction(final String action) {
218 214
         final ClientInfo me = server.getParser().getMyself();
219 215
         final String modes = channelInfo.getUser(me).getImportantModePrefix();
@@ -294,7 +290,7 @@ public final class Channel extends WritableFrameContainer implements
294 290
         String temp = Styliser.stipControlCodes(channelInfo.getName());
295 291
         
296 292
         if (channelInfo.getTopic().length() > 0) {
297
-                temp = temp + " - " + Styliser.stipControlCodes(channelInfo.getTopic());
293
+            temp = temp + " - " + Styliser.stipControlCodes(channelInfo.getTopic());
298 294
         }
299 295
         
300 296
         // Needs to be final for AIC

+ 3
- 0
src/com/dmdirc/Main.java Datei anzeigen

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27
+import com.dmdirc.commandparser.CommandManager;
27 28
 import com.dmdirc.config.IdentityManager;
28 29
 import com.dmdirc.logger.DMDircExceptionHandler;
29 30
 import com.dmdirc.plugins.PluginManager;
@@ -75,6 +76,8 @@ public final class Main {
75 76
         
76 77
         final CommandLineParser clp = new CommandLineParser(args);
77 78
         
79
+        CommandManager.initCommands();
80
+        
78 81
         IdentityManager.load();
79 82
         
80 83
         Config.init();

+ 41
- 0
src/com/dmdirc/MessageTarget.java Datei anzeigen

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc;
24
+
25
+/**
26
+ * Defines common methods for objects that you can send messages to (such as
27
+ * channels and queries).
28
+ * 
29
+ * @author Chris
30
+ */
31
+public abstract class MessageTarget extends WritableFrameContainer {
32
+    
33
+    /**
34
+     * Sends the specified string as an action (CTCP) to the target that this
35
+     * object represents.
36
+     * 
37
+     * @param action The action to send
38
+     */    
39
+    public abstract void sendAction(final String action);
40
+
41
+}

+ 1
- 1
src/com/dmdirc/Query.java Datei anzeigen

@@ -47,7 +47,7 @@ import java.io.Serializable;
47 47
  * corresponding ServerFrame, and handles user input to a ServerFrame.
48 48
  * @author chris
49 49
  */
50
-public final class Query extends WritableFrameContainer implements
50
+public final class Query extends MessageTarget implements
51 51
         IPrivateAction, IPrivateMessage, INickChanged, IQuit, Serializable {
52 52
     
53 53
     /**

+ 2
- 0
src/com/dmdirc/commandparser/ChannelCommandParser.java Datei anzeigen

@@ -73,6 +73,8 @@ public final class ChannelCommandParser extends CommandParser {
73 73
             final boolean isSilent, final Command command, final String... args) {
74 74
         if (command instanceof ChannelCommand) {
75 75
             ((ChannelCommand) command).execute(origin, server, channel, isSilent, args);
76
+        } else if (command instanceof ChatCommand) {
77
+            ((ChatCommand) command).execute(origin, server, channel, isSilent, args);
76 78
         } else if (command instanceof ServerCommand) {
77 79
             ((ServerCommand) command).execute(origin, server, isSilent, args);
78 80
         } else {

+ 35
- 0
src/com/dmdirc/commandparser/ChatCommand.java Datei anzeigen

@@ -0,0 +1,35 @@
1
+/*
2
+ * ChatCommand.java
3
+ *
4
+ * Created on 28-Jul-2007, 20:42:42
5
+ *
6
+ * To change this template, choose Tools | Template Manager
7
+ * and open the template in the editor.
8
+ */
9
+
10
+package com.dmdirc.commandparser;
11
+
12
+import com.dmdirc.MessageTarget;
13
+import com.dmdirc.Server;
14
+import com.dmdirc.ui.interfaces.InputWindow;
15
+
16
+/**
17
+ * Represents a command that can be performed in the context of a "chat" window
18
+ * (i.e., a channel or a query).
19
+ *
20
+ * @author Chris
21
+ */
22
+public abstract class ChatCommand extends Command {
23
+    
24
+    /**
25
+     * Executes this command.
26
+     * 
27
+     * @param origin The window in which the command was typed
28
+     * @param server The server instance that this command is being executed on
29
+     * @param target The target of this command
30
+     * @param isSilent Whether this command is silenced or not
31
+     * @param args Arguments passed to this command
32
+     */
33
+    public abstract void execute(InputWindow origin, Server server, MessageTarget target,
34
+            boolean isSilent, String... args);
35
+}

+ 170
- 184
src/com/dmdirc/commandparser/CommandManager.java Datei anzeigen

@@ -31,6 +31,7 @@ import com.dmdirc.commandparser.commands.query.*;
31 31
 import com.dmdirc.commandparser.commands.server.*;
32 32
 import com.dmdirc.logger.ErrorLevel;
33 33
 import com.dmdirc.logger.Logger;
34
+import com.dmdirc.ui.input.TabCompleter;
34 35
 
35 36
 import java.util.ArrayList;
36 37
 import java.util.Iterator;
@@ -46,41 +47,46 @@ public final class CommandManager {
46 47
     /**
47 48
      * The global commands that have been instansiated.
48 49
      */
49
-    private static List<Command> globalCommands;
50
+    private static List<Command> globalCommands = new ArrayList<Command>();
50 51
     /**
51 52
      * The server commands that have been instansiated.
52 53
      */
53
-    private static List<Command> serverCommands;
54
+    private static List<Command> serverCommands = new ArrayList<Command>();
54 55
     /**
55 56
      * The channel commands that have been instansiated.
56 57
      */
57
-    private static List<Command> channelCommands;
58
+    private static List<Command> channelCommands = new ArrayList<Command>();
58 59
     /**
59 60
      * The query commands that have been instansiated.
60 61
      */
61
-    private static List<Command> queryCommands;
62
+    private static List<Command> queryCommands = new ArrayList<Command>();
63
+    /**
64
+     * The "chat" commands that have been instansiated.
65
+     */
66
+    private static List<Command> chatCommands = new ArrayList<Command>();
67
+    
62 68
     /**
63 69
      * The parsers that have requested global commands.
64 70
      */
65
-    private static List<CommandParser> globalParsers;
71
+    private static List<CommandParser> globalParsers = new ArrayList<CommandParser>();
66 72
     /**
67 73
      * The parsers that have requested server commands.
68 74
      */
69
-    private static List<CommandParser> serverParsers;
75
+    private static List<CommandParser> serverParsers = new ArrayList<CommandParser>();
70 76
     /**
71 77
      * The parsers that have requested channel commands.
72 78
      */
73
-    private static List<CommandParser> channelParsers;
79
+    private static List<CommandParser> channelParsers = new ArrayList<CommandParser>();
74 80
     /**
75 81
      * The parsers that have requested query commands.
76 82
      */
77
-    private static List<CommandParser> queryParsers;
83
+    private static List<CommandParser> queryParsers = new ArrayList<CommandParser>();
78 84
     
79 85
     /**
80 86
      * Channel commands that have been registered to appear in the nicklist
81 87
      * popup.
82 88
      */
83
-    private static List<Command> channelPopupCommands;
89
+    private static List<Command> channelPopupCommands = new ArrayList<Command>();
84 90
     
85 91
     /**
86 92
      * Prevents creation of a new command manager.
@@ -94,120 +100,125 @@ public final class CommandManager {
94 100
      * @param command The command to be registered
95 101
      */
96 102
     public static void registerCommand(final Command command) {
97
-        if (channelCommands == null) {
98
-            initLists();
99
-        }
100
-        
101
-        List<CommandParser> target = null;
103
+        registerCommand(command, true);
104
+    }
105
+    
106
+    /**
107
+     * Unregisters a command with the command manager.
108
+     * @param command The command to be unregistered
109
+     */
110
+    public static void unregisterCommand(final Command command) {
111
+        registerCommand(command, false);
112
+    }
113
+    
114
+    /**
115
+     * Registers or unregisters a command.
116
+     *
117
+     * @param command The command to be (un)registered
118
+     * @param register True if the command should be registered, false if it
119
+     * should be unregistered.
120
+     */
121
+    private static void registerCommand(final Command command, final boolean register) {
122
+        boolean canContinue = true;
102 123
         
103 124
         if (command instanceof ChannelCommand) {
104
-            target = channelParsers;
125
+            registerCommand(command, channelParsers, register);
105 126
             channelCommands.add(command);
106 127
         } else if (command instanceof ServerCommand) {
107
-            target = serverParsers;
128
+            registerCommand(command, serverParsers, register);
108 129
             serverCommands.add(command);
109 130
         } else if (command instanceof QueryCommand) {
110
-            target = queryParsers;
131
+            registerCommand(command, queryParsers, register);
111 132
             queryCommands.add(command);
112 133
         } else if (command instanceof GlobalCommand) {
113
-            target = globalParsers;
134
+            registerCommand(command, globalParsers, register);
114 135
             globalCommands.add(command);
136
+        } else if (command instanceof ChatCommand) {
137
+            registerCommand(command, queryParsers, register);
138
+            registerCommand(command, channelParsers, register);
139
+            chatCommands.add(command);
115 140
         } else {
116
-            Logger.userError(ErrorLevel.HIGH, "Attempted to register an invalid command: "
141
+            canContinue = false;
142
+            
143
+            Logger.userError(ErrorLevel.HIGH, "Attempted to (un)register an invalid command: "
117 144
                     + command.getClass().getName());
118 145
         }
119 146
         
120
-        // FIXME: There's no way to kill old/dead entries in the *Parsers lists.
121
-        //        Ideally, they'd unregister themselves (or so) when unloaded.
122
-        if (target != null) {
123
-            for (CommandParser parser : target) {
124
-                if (parser != null) {
125
-                    parser.registerCommand(command);
126
-                }
127
-            }
128
-            
129
-            final String commandName = Config.getCommandChar() + command.getName();
130
-            
131
-            for (Server server : ServerManager.getServerManager().getServers()) {
132
-                if (command instanceof ServerCommand || command instanceof GlobalCommand) {
133
-                    server.getTabCompleter().addEntry(commandName);
134
-                } else if (command instanceof ChannelCommand) {
135
-                    for (String channelName : server.getChannels()) {
136
-                        server.getChannel(channelName).getTabCompleter().addEntry(commandName);
137
-                    }
138
-                } else if (command instanceof QueryCommand) {
139
-                    for (String queryName : server.getQueries()) {
140
-                        server.getQuery(queryName).getTabCompleter().addEntry(commandName);
141
-                    }
142
-                }
143
-            }
147
+        if (canContinue) {
148
+            registerCommandName(command, register);
144 149
         }
145 150
     }
146 151
     
147 152
     /**
148
-     * Unregisters a command with the command manager.
149
-     * @param command The command to be unregistered
153
+     * Registers the specified command with all of the specified parsers.
154
+     *
155
+     * @param command The command to be reigstered
156
+     * @param parsers The parsers to register the command with
150 157
      */
151
-    public static void unregisterCommand(final Command command) {
152
-        if (channelCommands == null) {
153
-            return;
154
-        }
155
-        
156
-        List<CommandParser> target = null;
157
-        
158
-        if (command instanceof ChannelCommand) {
159
-            target = channelParsers;
160
-            channelCommands.remove(command);
161
-        } else if (command instanceof ServerCommand) {
162
-            target = serverParsers;
163
-            serverCommands.remove(command);
164
-        } else if (command instanceof QueryCommand) {
165
-            target = queryParsers;
166
-            queryCommands.remove(command);
167
-        } else if (command instanceof GlobalCommand) {
168
-            target = globalParsers;
169
-            globalCommands.remove(command);
170
-        } else {
171
-            Logger.userError(ErrorLevel.HIGH, "Attempted to unregister an invalid command: "
172
-                    + command.getClass().getName());
173
-        }
174
-        
158
+    private static void registerCommand(final Command command,
159
+            final List<CommandParser> parsers, final boolean register) {
175 160
         // FIXME: There's no way to kill old/dead entries in the *Parsers lists.
176 161
         //        Ideally, they'd unregister themselves (or so) when unloaded.
177
-        if (target != null) {
178
-            for (CommandParser parser : target) {
179
-                if (parser != null) {
180
-                    parser.unregisterCommand(command);
181
-                }
162
+        for (CommandParser parser : parsers) {
163
+            if (register) {
164
+                parser.registerCommand(command);
165
+            } else {
166
+                parser.unregisterCommand(command);
182 167
             }
183
-            
184
-            final String commandName = Config.getCommandChar() + command.getName();
185
-            
186
-            for (Server server : ServerManager.getServerManager().getServers()) {
187
-                if (command instanceof ServerCommand || command instanceof GlobalCommand) {
188
-                    server.getTabCompleter().removeEntry(commandName);
189
-                } else if (command instanceof ChannelCommand) {
190
-                    for (String channelName : server.getChannels()) {
191
-                        server.getChannel(channelName).getTabCompleter().removeEntry(commandName);
192
-                    }
193
-                } else if (command instanceof QueryCommand) {
194
-                    for (String queryName : server.getQueries()) {
195
-                        server.getQuery(queryName).getTabCompleter().removeEntry(commandName);
196
-                    }
168
+        }
169
+    }
170
+    
171
+    /**
172
+     * Registers or unregisters the specified command's name with the relevant
173
+     * tab completers.
174
+     *
175
+     * @param command The command to be registered
176
+     * @param register True if the command should be registered, false if it
177
+     * should be unregistered.
178
+     */
179
+    private static void registerCommandName(final Command command,
180
+            final boolean register) {
181
+        // Do tab completion
182
+        final String commandName = Config.getCommandChar() + command.getName();
183
+        
184
+        for (Server server : ServerManager.getServerManager().getServers()) {
185
+            if (command instanceof ServerCommand || command instanceof GlobalCommand) {
186
+                registerCommandName(server.getTabCompleter(), commandName, register);
187
+            } else if (command instanceof ChannelCommand || command instanceof ChatCommand) {
188
+                for (String channelName : server.getChannels()) {
189
+                    registerCommandName(server.getChannel(channelName).getTabCompleter(), commandName, register);
190
+                }
191
+            } else if (command instanceof QueryCommand || command instanceof ChatCommand) {
192
+                for (String queryName : server.getQueries()) {
193
+                    registerCommandName(server.getQuery(queryName).getTabCompleter(), commandName, register);
197 194
                 }
198 195
             }
199 196
         }
200 197
     }
201 198
     
199
+    /**
200
+     * Registers or unregisters the specified command with the specified tab-
201
+     * completer.
202
+     *
203
+     * @param completer The tab completer to be used
204
+     * @param name The command name to be registered
205
+     * @param register True if the command should be registered, false if it
206
+     * should be unregistered.
207
+     */
208
+    private static void registerCommandName(final TabCompleter completer,
209
+            final String name, final boolean register) {
210
+        if (register) {
211
+            completer.addEntry(name);
212
+        }  else {
213
+            completer.removeEntry(name);
214
+        }
215
+    }
216
+    
202 217
     /**
203 218
      * Registers a command for use in the nicklist popup.
204 219
      * @param command The command to be registered
205 220
      */
206 221
     public static void registerPopupCommand(final Command command) {
207
-        if (channelPopupCommands == null) {
208
-            initLists();
209
-        }
210
-        
211 222
         channelPopupCommands.add(command);
212 223
     }
213 224
     
@@ -216,36 +227,13 @@ public final class CommandManager {
216 227
      * @return A list of commands suitable for use in the nicklist popup
217 228
      */
218 229
     public static List<Command> getNicklistCommands() {
219
-        if (channelPopupCommands == null) {
220
-            initLists();
221
-        }
222
-        
223 230
         return channelPopupCommands;
224 231
     }
225 232
     
226
-    /**
227
-     * Initialises the command manager's various command lists.
228
-     */
229
-    private static void initLists() {
230
-        channelCommands = new ArrayList<Command>();
231
-        serverCommands = new ArrayList<Command>();
232
-        queryCommands = new ArrayList<Command>();
233
-        globalCommands = new ArrayList<Command>();
234
-        
235
-        channelParsers = new ArrayList<CommandParser>();
236
-        serverParsers = new ArrayList<CommandParser>();
237
-        queryParsers = new ArrayList<CommandParser>();
238
-        globalParsers = new ArrayList<CommandParser>();
239
-        
240
-        channelPopupCommands = new ArrayList<Command>();
241
-        
242
-        initCommands();
243
-    }
244
-    
245 233
     /**
246 234
      * Instansiates the default commands.
247 235
      */
248
-    private static void initCommands() {
236
+    public static void initCommands() {
249 237
         // Channel commands
250 238
         new Ban();
251 239
         new Benchmark();
@@ -297,7 +285,7 @@ public final class CommandManager {
297 285
         new ExitDefault();
298 286
         new Ifplugin();
299 287
         new NewServer();
300
-        new Notify();        
288
+        new Notify();
301 289
         new LoadFormatter();
302 290
         new LoadPlugin();
303 291
         new ReloadActions();
@@ -312,11 +300,11 @@ public final class CommandManager {
312 300
      * @param parser The parser to load commands into
313 301
      */
314 302
     public static void loadChannelCommands(final CommandParser parser) {
315
-        if (channelCommands == null) {
316
-            initLists();
303
+        for (Command com : channelCommands) {
304
+            parser.registerCommand(com);
317 305
         }
318 306
         
319
-        for (Command com : channelCommands) {
307
+        for (Command com : chatCommands) {
320 308
             parser.registerCommand(com);
321 309
         }
322 310
         
@@ -328,10 +316,6 @@ public final class CommandManager {
328 316
      * @param parser The parser to load commands into
329 317
      */
330 318
     public static void loadServerCommands(final CommandParser parser) {
331
-        if (serverCommands == null) {
332
-            initLists();
333
-        }
334
-        
335 319
         final Iterator<Command> it = serverCommands.iterator();
336 320
         
337 321
         while (it.hasNext()) {
@@ -346,10 +330,6 @@ public final class CommandManager {
346 330
      * @param parser The parser to load commands into
347 331
      */
348 332
     public static void loadGlobalCommands(final CommandParser parser) {
349
-        if (globalCommands == null) {
350
-            initLists();
351
-        }
352
-        
353 333
         for (Command com : globalCommands) {
354 334
             parser.registerCommand(com);
355 335
         }
@@ -362,11 +342,11 @@ public final class CommandManager {
362 342
      * @param parser The parser to load commands into
363 343
      */
364 344
     protected static void loadQueryCommands(final QueryCommandParser parser) {
365
-        if (queryCommands == null)    {
366
-            initLists();
345
+        for (Command com : queryCommands) {
346
+            parser.registerCommand(com);
367 347
         }
368 348
         
369
-        for (Command com : queryCommands) {
349
+        for (Command com : chatCommands) {
370 350
             parser.registerCommand(com);
371 351
         }
372 352
         
@@ -376,7 +356,7 @@ public final class CommandManager {
376 356
     /**
377 357
      * Retrieves the command identified by the specified name, regardless of
378 358
      * type.
379
-     * 
359
+     *
380 360
      * @param name The name to look for
381 361
      * @return A command with a matching signature, or null if none were found
382 362
      */
@@ -387,6 +367,8 @@ public final class CommandManager {
387 367
             return (Command) getServerCommandByName(name);
388 368
         } else if (getChannelCommandByName(name) != null) {
389 369
             return (Command) getChannelCommandByName(name);
370
+        } else if (getChatCommandByName(name) != null) {
371
+            return (Command) getChatCommandByName(name);
390 372
         } else {
391 373
             return (Command) getChannelCommandByName(name);
392 374
         }
@@ -399,10 +381,6 @@ public final class CommandManager {
399 381
      * were found.
400 382
      */
401 383
     public static ServerCommand getServerCommand(final String signature) {
402
-        if (serverCommands == null) {
403
-            initLists();
404
-        }
405
-        
406 384
         for (Command com : serverCommands) {
407 385
             if (com.getSignature().equalsIgnoreCase(signature)) {
408 386
                 return (ServerCommand) com;
@@ -418,12 +396,8 @@ public final class CommandManager {
418 396
      * @return A server command with a matching name, or null if none were found
419 397
      */
420 398
     public static ServerCommand getServerCommandByName(final String name) {
421
-        if (serverCommands == null) {
422
-            initLists();
423
-        }
424
-        
425 399
         return (ServerCommand) getCommandByName(name, serverCommands);
426
-    }    
400
+    }
427 401
     
428 402
     /**
429 403
      * Retrieves the global command identified by the specified signature.
@@ -432,10 +406,6 @@ public final class CommandManager {
432 406
      * were found.
433 407
      */
434 408
     public static GlobalCommand getGlobalCommand(final String signature) {
435
-        if (globalCommands == null) {
436
-            initLists();
437
-        }
438
-        
439 409
         for (Command com : globalCommands) {
440 410
             if (com.getSignature().equalsIgnoreCase(signature)) {
441 411
                 return (GlobalCommand) com;
@@ -451,10 +421,6 @@ public final class CommandManager {
451 421
      * @return A global command with a matching name, or null if none were found
452 422
      */
453 423
     public static GlobalCommand getGlobalCommandByName(final String name) {
454
-        if (globalCommands == null) {
455
-            initLists();
456
-        }
457
-        
458 424
         return (GlobalCommand) getCommandByName(name, globalCommands);
459 425
     }
460 426
     
@@ -465,10 +431,6 @@ public final class CommandManager {
465 431
      * were found.
466 432
      */
467 433
     public static ChannelCommand getChannelCommand(final String signature) {
468
-        if (channelCommands == null) {
469
-            initLists();
470
-        }
471
-        
472 434
         for (Command com : channelCommands) {
473 435
             if (com.getSignature().equalsIgnoreCase(signature)) {
474 436
                 return (ChannelCommand) com;
@@ -484,12 +446,33 @@ public final class CommandManager {
484 446
      * @return A channel command with a matching name, or null if none were found
485 447
      */
486 448
     public static ChannelCommand getChannelCommandByName(final String name) {
487
-        if (channelCommands == null) {
488
-            initLists();
449
+        return (ChannelCommand) getCommandByName(name, channelCommands);
450
+    }
451
+    
452
+    /**
453
+     * Retrieves the chat command identified by the specified signature.
454
+     * @param signature The signature to look for
455
+     * @return A chat command with a matching signature, or null if none
456
+     * were found.
457
+     */
458
+    public static ChatCommand getChatCommand(final String signature) {
459
+        for (Command com : chatCommands) {
460
+            if (com.getSignature().equalsIgnoreCase(signature)) {
461
+                return (ChatCommand) com;
462
+            }
489 463
         }
490 464
         
491
-        return (ChannelCommand) getCommandByName(name, channelCommands);
492
-    }    
465
+        return null;
466
+    }
467
+    
468
+    /**
469
+     * Retrieves the chat command identified by the specified name.
470
+     * @param name The name to look for
471
+     * @return A chat command with a matching name, or null if none were found
472
+     */
473
+    public static ChatCommand getChatCommandByName(final String name) {
474
+        return (ChatCommand) getCommandByName(name, chatCommands);
475
+    }
493 476
     
494 477
     /**
495 478
      * Retrieves the command identified by the specified name.
@@ -498,7 +481,7 @@ public final class CommandManager {
498 481
      * @return A command with a matching name, or null if none were found
499 482
      */
500 483
     private static Command getCommandByName(final String name,
501
-            final List<Command> list) {        
484
+            final List<Command> list) {
502 485
         for (Command com : list) {
503 486
             if (com.getName().equalsIgnoreCase(name)) {
504 487
                 return com;
@@ -506,7 +489,7 @@ public final class CommandManager {
506 489
         }
507 490
         
508 491
         return null;
509
-    }    
492
+    }
510 493
     
511 494
     /**
512 495
      * Returns a list containing the global commands that have been initialised
@@ -515,7 +498,7 @@ public final class CommandManager {
515 498
      */
516 499
     public static List<Command> getGlobalCommands() {
517 500
         return globalCommands;
518
-    }    
501
+    }
519 502
     
520 503
     /**
521 504
      * Returns a list containing the server commands that have been initialised
@@ -535,6 +518,15 @@ public final class CommandManager {
535 518
         return channelCommands;
536 519
     }
537 520
     
521
+    /**
522
+     * Returns a list containing the chat commands that have been initialised
523
+     * by this command manager.
524
+     * @return An ArrayList of chat commands, or null if none have been loaded
525
+     */
526
+    public static List<Command> getChatCommands() {
527
+        return chatCommands;
528
+    }
529
+    
538 530
     /**
539 531
      * Returns a list containing the query commands that have been initialised
540 532
      * by this command manager.
@@ -550,11 +542,13 @@ public final class CommandManager {
550 542
      * @return True iff the command is a channel command, false otherwise
551 543
      */
552 544
     public static boolean isChannelCommand(final String command) {
553
-        if (channelCommands == null) {
554
-            CommandManager.initLists();
545
+        for (Command chanCommand : channelCommands) {
546
+            if (chanCommand.getName().equalsIgnoreCase(command)) {
547
+                return true;
548
+            }
555 549
         }
556 550
         
557
-        for (Command chanCommand : channelCommands) {
551
+        for (Command chanCommand : chatCommands) {
558 552
             if (chanCommand.getName().equalsIgnoreCase(command)) {
559 553
                 return true;
560 554
             }
@@ -570,10 +564,6 @@ public final class CommandManager {
570 564
      * names
571 565
      */
572 566
     public static List<String> getServerCommandNames() {
573
-        if (serverCommands == null) {
574
-            CommandManager.initLists();
575
-        }
576
-        
577 567
         return getCommandNames(serverCommands);
578 568
     }
579 569
     
@@ -584,41 +574,37 @@ public final class CommandManager {
584 574
      * names
585 575
      */
586 576
     public static List<String> getGlobalCommandNames() {
587
-        if (globalCommands == null) {
588
-            CommandManager.initLists();
589
-        }
590
-        
591 577
         return getCommandNames(globalCommands);
592 578
     }
593 579
     
594 580
     /**
595 581
      * Returns the names (including command char) of all registered channel
596 582
      * commands.
597
-     * @return An ArrayList&lt;String&gt; containing all registered server command
598
-     * names
583
+     * @return A list containing all registered channel command names
599 584
      */
600 585
     public static List<String> getChannelCommandNames() {
601
-        if (channelCommands == null) {
602
-            CommandManager.initLists();
603
-        }
604
-        
605 586
         return getCommandNames(channelCommands);
606 587
     }
607 588
     
608 589
     /**
609
-     * Returns the names (including command char) of all registered channel
590
+     * Returns the names (including command char) of all registered query
610 591
      * commands.
611
-     * @return An ArrayList&lt;String&gt; containing all registered server command
612
-     * names
592
+     * @return A list containing all registered query command names
613 593
      */
614 594
     public static List<String> getQueryCommandNames() {
615
-        if (queryCommands == null) {
616
-            CommandManager.initLists();
617
-        }
618
-        
619 595
         return getCommandNames(queryCommands);
620 596
     }
621 597
     
598
+    /**
599
+     * Returns the names (including command char) of all registered chat
600
+     * commands.
601
+     * @return An ArrayList&lt;String&gt; containing all registered chat command
602
+     * names
603
+     */
604
+    public static List<String> getChatCommandNames() {
605
+        return getCommandNames(chatCommands);
606
+    }    
607
+    
622 608
     /**
623 609
      * Iterates through the specified source and returns a list of the names
624 610
      * of all commands found in it.

+ 2
- 0
src/com/dmdirc/commandparser/QueryCommandParser.java Datei anzeigen

@@ -73,6 +73,8 @@ public final class QueryCommandParser extends CommandParser {
73 73
             final boolean isSilent, final Command command, final String... args) {
74 74
         if (command instanceof QueryCommand) {
75 75
             ((QueryCommand) command).execute(origin, server, query, isSilent, args);
76
+        } else if (command instanceof ChatCommand) {
77
+            ((ChatCommand) command).execute(origin, server, query, isSilent, args);
76 78
         } else if (command instanceof ServerCommand) {
77 79
             ((ServerCommand) command).execute(origin, server, isSilent, args);
78 80
         } else {

Laden…
Abbrechen
Speichern