Bladeren bron

Fix fallout from command changes

Change-Id: Ia5fb799a514aa47cbd3c407c42b3a149b147ae44
Reviewed-on: http://gerrit.dmdirc.com/1251
Automatic-Compile: Shane Mc Cormack <shane@dmdirc.com>
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
tags/0.6.4
Chris Smith 14 jaren geleden
bovenliggende
commit
91a6413801

+ 18
- 21
src/com/dmdirc/addons/audio/AudioCommand.java Bestand weergeven

@@ -24,8 +24,11 @@ package com.dmdirc.addons.audio;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
29 32
 
30 33
 import java.io.File;
31 34
 
@@ -34,7 +37,7 @@ import java.io.File;
34 37
  *
35 38
  * @author Shane "Dataforce" Mc Cormack
36 39
  */
37
-public final class AudioCommand extends GlobalCommand {
40
+public final class AudioCommand extends Command implements CommandInfo {
38 41
 
39 42
     /**
40 43
      * Creates a new instance of LoggingCommand.
@@ -46,46 +49,40 @@ public final class AudioCommand extends GlobalCommand {
46 49
 
47 50
     /** {@inheritDoc} */
48 51
     @Override
49
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
50
-                        final CommandArguments args) {
52
+    public void execute(final FrameContainer<?> origin,
53
+            final CommandArguments args, final CommandContext context) {
51 54
         final String filename = args.getArgumentsAsString();
52 55
         final File file = new File(filename);
53 56
         if (file.exists()) {
54 57
             if (AudioPlayer.isValid(file)) {
55 58
                 new AudioPlayer(file).play();
56 59
             } else {
57
-                sendLine(origin, isSilent, FORMAT_ERROR, "Invalid file type");
60
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Invalid file type");
58 61
             }
59 62
         } else {
60
-            sendLine(origin, isSilent, FORMAT_ERROR, "File does not exist");
63
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "File does not exist");
61 64
         }
62 65
     }
63 66
 
64
-    /**
65
-     * Returns this command's name.
66
-     *
67
-     * @return The name of this command
68
-     */
67
+    /** {@inheritDoc} */
69 68
     @Override
70 69
     public String getName() {
71 70
         return "audio";
72 71
     }
73 72
 
74
-    /**
75
-     * Returns whether or not this command should be shown in help messages.
76
-     *
77
-     * @return True iff the command should be shown, false otherwise
78
-     */
73
+    /** {@inheritDoc} */
79 74
     @Override
80 75
     public boolean showInHelp() {
81 76
         return true;
82 77
     }
83 78
 
84
-    /**
85
-     * Returns a string representing the help message for this command.
86
-     *
87
-     * @return the help message for this command
88
-     */
79
+    /** {@inheritDoc} */
80
+    @Override
81
+    public CommandType getType() {
82
+        return CommandType.TYPE_GLOBAL;
83
+    }
84
+
85
+    /** {@inheritDoc} */
89 86
     @Override
90 87
     public String getHelp() {
91 88
         return this.getName() + " <file>";

+ 16
- 19
src/com/dmdirc/addons/audio/BeepCommand.java Bestand weergeven

@@ -24,8 +24,11 @@ package com.dmdirc.addons.audio;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
29 32
 
30 33
 import java.awt.Toolkit;
31 34
 
@@ -34,7 +37,7 @@ import java.awt.Toolkit;
34 37
  *
35 38
  * @author Shane "Dataforce" Mc Cormack
36 39
  */
37
-public final class BeepCommand extends GlobalCommand {
40
+public final class BeepCommand extends Command implements CommandInfo {
38 41
 
39 42
     /**
40 43
      * Creates a new instance of BeepCommand.
@@ -46,36 +49,30 @@ public final class BeepCommand extends GlobalCommand {
46 49
 
47 50
     /** {@inheritDoc} */
48 51
     @Override
49
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
50
-                        final CommandArguments args) {
52
+    public void execute(final FrameContainer<?> origin,
53
+            final CommandArguments args, final CommandContext context) {
51 54
         Toolkit.getDefaultToolkit().beep();
52 55
     }
53 56
 
54
-    /**
55
-     * Returns this command's name.
56
-     *
57
-     * @return The name of this command
58
-     */
57
+    /** {@inheritDoc} */
59 58
     @Override
60 59
     public String getName() {
61 60
         return "beep";
62 61
     }
63 62
 
64
-    /**
65
-     * Returns whether or not this command should be shown in help messages.
66
-     *
67
-     * @return True iff the command should be shown, false otherwise
68
-     */
63
+    /** {@inheritDoc} */
69 64
     @Override
70 65
     public boolean showInHelp() {
71 66
         return true;
72 67
     }
73 68
 
74
-    /**
75
-     * Returns a string representing the help message for this command.
76
-     *
77
-     * @return the help message for this command
78
-     */
69
+    /** {@inheritDoc} */
70
+    @Override
71
+    public CommandType getType() {
72
+        return CommandType.TYPE_GLOBAL;
73
+    }
74
+
75
+    /** {@inheritDoc} */
79 76
     @Override
80 77
     public String getHelp() {
81 78
         return this.getName();

+ 16
- 7
src/com/dmdirc/addons/calc/CalcCommand.java Bestand weergeven

@@ -24,7 +24,10 @@ package com.dmdirc.addons.calc;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
-import com.dmdirc.commandparser.commands.GlobalCommand;
27
+import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandType;
29
+import com.dmdirc.commandparser.commands.Command;
30
+import com.dmdirc.commandparser.commands.context.CommandContext;
28 31
 
29 32
 import java.text.ParseException;
30 33
 
@@ -34,12 +37,12 @@ import java.text.ParseException;
34 37
  *
35 38
  * @author chris
36 39
  */
37
-public class CalcCommand extends GlobalCommand {
40
+public class CalcCommand extends Command implements CommandInfo {
38 41
 
39 42
     /** {@inheritDoc} */
40 43
     @Override
41
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
42
-            final CommandArguments args) {
44
+    public void execute(final FrameContainer<?> origin,
45
+            final CommandArguments args, final CommandContext context) {
43 46
         try {
44 47
             int offset = 0;
45 48
             boolean showexpr = false;
@@ -54,13 +57,13 @@ public class CalcCommand extends GlobalCommand {
54 57
             final Parser parser = new Parser(lexer);
55 58
             final Evaluator evaluator = new Evaluator(parser.parse());
56 59
             final Number result = evaluator.evaluate();
57
-            sendLine(origin, isSilent, FORMAT_OUTPUT,
60
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
58 61
                     (showexpr ? input + " = " : "") + result);
59 62
         } catch (ParseException ex) {
60
-            sendLine(origin, isSilent, FORMAT_ERROR, "Unable to parse expression: "
63
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to parse expression: "
61 64
                     + ex.getMessage());
62 65
         } catch (ArithmeticException ex) {
63
-            sendLine(origin, isSilent, FORMAT_ERROR, "Unable to calculate expression: "
66
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to calculate expression: "
64 67
                     + ex.getMessage());
65 68
         }
66 69
     }
@@ -77,6 +80,12 @@ public class CalcCommand extends GlobalCommand {
77 80
         return true;
78 81
     }
79 82
 
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public CommandType getType() {
86
+        return CommandType.TYPE_GLOBAL;
87
+    }
88
+
80 89
     /** {@inheritDoc} */
81 90
     @Override
82 91
     public String getHelp() {

+ 22
- 9
src/com/dmdirc/addons/dcc/DCCCommand.java Bestand weergeven

@@ -32,9 +32,13 @@ import com.dmdirc.addons.dcc.actions.DCCActions;
32 32
 import com.dmdirc.addons.dcc.kde.KFileChooser;
33 33
 import com.dmdirc.addons.ui_swing.SwingController;
34 34
 import com.dmdirc.commandparser.CommandArguments;
35
+import com.dmdirc.commandparser.CommandInfo;
35 36
 import com.dmdirc.commandparser.CommandManager;
37
+import com.dmdirc.commandparser.CommandType;
38
+import com.dmdirc.commandparser.commands.Command;
36 39
 import com.dmdirc.commandparser.commands.IntelligentCommand;
37
-import com.dmdirc.commandparser.commands.ServerCommand;
40
+import com.dmdirc.commandparser.commands.context.CommandContext;
41
+import com.dmdirc.commandparser.commands.context.ServerCommandContext;
38 42
 import com.dmdirc.config.IdentityManager;
39 43
 import com.dmdirc.parser.interfaces.Parser;
40 44
 import com.dmdirc.plugins.PluginManager;
@@ -51,7 +55,8 @@ import javax.swing.JOptionPane;
51 55
  *
52 56
  * @author Shane "Dataforce" Mc Cormack
53 57
  */
54
-public final class DCCCommand extends ServerCommand implements IntelligentCommand {
58
+public final class DCCCommand extends Command implements IntelligentCommand,
59
+        CommandInfo {
55 60
 
56 61
     /** My Plugin */
57 62
     private final DCCPlugin myPlugin;
@@ -69,8 +74,10 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
69 74
 
70 75
     /** {@inheritDoc} */
71 76
     @Override
72
-    public void execute(final FrameContainer<?> origin, final Server server,
73
-            final boolean isSilent, final CommandArguments args) {
77
+    public void execute(final FrameContainer<?> origin,
78
+            final CommandArguments args, final CommandContext context) {
79
+        final Server server = ((ServerCommandContext) context).getServer();
80
+        
74 81
         if (args.getArguments().length > 1) {
75 82
             final String type = args.getArguments()[0];
76 83
             final String target = args.getArguments()[1];
@@ -110,22 +117,22 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
110 117
                     ActionManager.processEvent(DCCActions.DCC_CHAT_REQUEST_SENT,
111 118
                             null, server, target);
112 119
 
113
-                    sendLine(origin, isSilent, "DCCChatStarting", target,
120
+                    sendLine(origin, args.isSilent(), "DCCChatStarting", target,
114 121
                             chat.getHost(), chat.getPort());
115 122
                     window.addLine("DCCChatStarting", target,
116 123
                             chat.getHost(), chat.getPort());
117 124
                 } else {
118
-                    sendLine(origin, isSilent, "DCCChatError",
125
+                    sendLine(origin, args.isSilent(), "DCCChatError",
119 126
                             "Unable to start chat with " + target
120 127
                             + " - unable to create listen socket");
121 128
                 }
122 129
             } else if (type.equalsIgnoreCase("send")) {
123
-                sendFile(target, origin, server, isSilent, args.getArgumentsAsString(2));
130
+                sendFile(target, origin, server, args.isSilent(), args.getArgumentsAsString(2));
124 131
             } else {
125
-                sendLine(origin, isSilent, FORMAT_ERROR, "Unknown DCC Type: '" + type + "'");
132
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown DCC Type: '" + type + "'");
126 133
             }
127 134
         } else {
128
-            sendLine(origin, isSilent, FORMAT_ERROR, "Syntax: dcc <type> <target> [params]");
135
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Syntax: dcc <type> <target> [params]");
129 136
         }
130 137
     }
131 138
 
@@ -236,6 +243,12 @@ public final class DCCCommand extends ServerCommand implements IntelligentComman
236 243
         return true;
237 244
     }
238 245
 
246
+    /** {@inheritDoc} */
247
+    @Override
248
+    public CommandType getType() {
249
+        return CommandType.TYPE_SERVER;
250
+    }
251
+
239 252
     /** {@inheritDoc} */
240 253
     @Override
241 254
     public String getHelp() {

+ 2
- 19
src/com/dmdirc/addons/dcc/DCCCommandParser.java Bestand weergeven

@@ -24,17 +24,14 @@ package com.dmdirc.addons.dcc;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.WritableFrameContainer;
27
-import com.dmdirc.commandparser.CommandArguments;
28 27
 import com.dmdirc.commandparser.CommandManager;
29 28
 import com.dmdirc.commandparser.CommandType;
30
-import com.dmdirc.commandparser.commands.Command;
31
-import com.dmdirc.commandparser.commands.GlobalCommand;
32
-import com.dmdirc.commandparser.parsers.CommandParser;
29
+import com.dmdirc.commandparser.parsers.GlobalCommandParser;
33 30
 
34 31
 /**
35 32
  * DCC CommandParser
36 33
  */
37
-public class DCCCommandParser extends CommandParser {
34
+public class DCCCommandParser extends GlobalCommandParser {
38 35
 
39 36
     /** The singleton instance of the DCC command parser. */
40 37
     private static DCCCommandParser me;
@@ -68,20 +65,6 @@ public class DCCCommandParser extends CommandParser {
68 65
         CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
69 66
     }
70 67
 
71
-    /**
72
-     * Executes the specified command with the given arguments.
73
-     *
74
-     * @param origin The window in which the command was typed
75
-     * @param isSilent Whether the command is being silenced or not
76
-     * @param command The command to be executed
77
-     * @param args The arguments to the command
78
-     */
79
-    @Override
80
-    protected void executeCommand(final FrameContainer<?> origin,
81
-            final boolean isSilent, final Command command, final CommandArguments args) {
82
-        ((GlobalCommand) command).execute(origin, isSilent, args);
83
-    }
84
-
85 68
     /**
86 69
      * Called when the input was a line of text that was not a command.
87 70
      * This normally means it is sent to the server/channel/user as-is, with

+ 17
- 6
src/com/dmdirc/addons/dcop/DcopCommand.java Bestand weergeven

@@ -25,8 +25,12 @@ package com.dmdirc.addons.dcop;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27 27
 import com.dmdirc.commandparser.CommandArguments;
28
+import com.dmdirc.commandparser.CommandInfo;
28 29
 import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.commandparser.commands.ServerCommand;
30
+import com.dmdirc.commandparser.CommandType;
31
+import com.dmdirc.commandparser.commands.Command;
32
+import com.dmdirc.commandparser.commands.context.CommandContext;
33
+import com.dmdirc.commandparser.commands.context.ServerCommandContext;
30 34
 
31 35
 import java.util.List;
32 36
 
@@ -34,7 +38,7 @@ import java.util.List;
34 38
  * The dcop command retrieves information from a dcop application.
35 39
  * @author chris
36 40
  */
37
-public final class DcopCommand extends ServerCommand {
41
+public final class DcopCommand extends Command implements CommandInfo {
38 42
     
39 43
     /**
40 44
      * Creates a new instance of DcopCommand.
@@ -47,16 +51,17 @@ public final class DcopCommand extends ServerCommand {
47 51
 
48 52
     /** {@inheritDoc} */
49 53
     @Override
50
-    public void execute(final FrameContainer<?> origin, final Server server,
51
-            final boolean isSilent, final CommandArguments args) {
54
+    public void execute(final FrameContainer<?> origin,
55
+            final CommandArguments args, final CommandContext context) {
56
+        final Server server = ((ServerCommandContext) context).getServer();
52 57
         if (args.getArguments().length != 3) {
53
-            showUsage(origin, isSilent, "dcop", "<app> <object> <function>");
58
+            showUsage(origin, args.isSilent(), "dcop", "<app> <object> <function>");
54 59
             return;
55 60
         }
56 61
         
57 62
         final List<String> res = DcopPlugin.getDcopResult("dcop " + args.getArgumentsAsString());
58 63
         for (String line : res) {
59
-            sendLine(origin, isSilent, FORMAT_OUTPUT, line);
64
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, line);
60 65
         }
61 66
     }
62 67
     
@@ -72,6 +77,12 @@ public final class DcopCommand extends ServerCommand {
72 77
     public boolean showInHelp() {
73 78
         return true;
74 79
     }
80
+
81
+    /** {@inheritDoc} */
82
+    @Override
83
+    public CommandType getType() {
84
+        return CommandType.TYPE_SERVER;
85
+    }
75 86
     
76 87
     /** {@inheritDoc} */
77 88
     @Override

+ 17
- 8
src/com/dmdirc/addons/dns/DNSCommand.java Bestand weergeven

@@ -24,8 +24,11 @@ package com.dmdirc.addons.dns;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
29 32
 
30 33
 import java.util.Timer;
31 34
 import java.util.TimerTask;
@@ -33,7 +36,7 @@ import java.util.TimerTask;
33 36
 /**
34 37
  * Performs DNS lookups for nicknames, hostnames or IPs.
35 38
  */
36
-public final class DNSCommand extends GlobalCommand {
39
+public final class DNSCommand extends Command implements CommandInfo {
37 40
     
38 41
     /** Creates a new instance of DNSCommand. */
39 42
     public DNSCommand() {
@@ -44,24 +47,24 @@ public final class DNSCommand extends GlobalCommand {
44 47
     
45 48
     /** {@inheritDoc} */
46 49
     @Override
47
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
48
-            final CommandArguments args) {
50
+    public void execute(final FrameContainer<?> origin,
51
+            final CommandArguments args, final CommandContext context) {
49 52
         if (args.getArguments().length == 0) {
50
-            showUsage(origin, isSilent, "dns", "<IP|hostname>");
53
+            showUsage(origin, args.isSilent(), "dns", "<IP|hostname>");
51 54
             return;
52 55
         }
53 56
         
54
-        sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
57
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Resolving: " + args.getArguments()[0]);
55 58
         new Timer("DNS Command Timer").schedule(new TimerTask() {
56 59
             /** {@inheritDoc} */
57 60
             @Override
58 61
             public void run() {
59 62
                 if (args.getArguments()[0].matches("\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b")) {
60
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
63
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Resolved: "
61 64
                             + args.getArguments()[0] + ": "
62 65
                             + DNSPlugin.getHostname(args.getArguments()[0]));
63 66
                 } else {
64
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Resolved: "
67
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Resolved: "
65 68
                             + args.getArguments()[0] + ": "
66 69
                             + DNSPlugin.getIPs(args.getArguments()[0]));
67 70
                 }
@@ -80,6 +83,12 @@ public final class DNSCommand extends GlobalCommand {
80 83
     public boolean showInHelp() {
81 84
         return true;
82 85
     }
86
+
87
+    /** {@inheritDoc} */
88
+    @Override
89
+    public CommandType getType() {
90
+        return CommandType.TYPE_GLOBAL;
91
+    }
83 92
     
84 93
     /** {@inheritDoc} */
85 94
     @Override

+ 13
- 4
src/com/dmdirc/addons/freedesktop_notifications/FDNotifyCommand.java Bestand weergeven

@@ -24,8 +24,11 @@ package com.dmdirc.addons.freedesktop_notifications;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
29 32
 
30 33
 /**
31 34
  * The FDNotify Command shows a nice popup on using the FreeDesktop
@@ -33,7 +36,7 @@ import com.dmdirc.commandparser.commands.GlobalCommand;
33 36
  *
34 37
  * @author Shane 'Dataforce' McCormack
35 38
  */
36
-public final class FDNotifyCommand extends GlobalCommand {
39
+public final class FDNotifyCommand extends Command implements CommandInfo {
37 40
     /** Plugin that owns this command. */
38 41
     final FreeDesktopNotificationsPlugin myPlugin;
39 42
     
@@ -50,8 +53,8 @@ public final class FDNotifyCommand extends GlobalCommand {
50 53
 
51 54
     /** {@inheritDoc} */
52 55
     @Override
53
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
54
-            final CommandArguments args) {
56
+    public void execute(final FrameContainer<?> origin,
57
+            final CommandArguments args, final CommandContext context) {
55 58
         myPlugin.showNotification("", args.getArgumentsAsString());
56 59
     }
57 60
     
@@ -67,6 +70,12 @@ public final class FDNotifyCommand extends GlobalCommand {
67 70
     public boolean showInHelp() {
68 71
         return true;
69 72
     }
73
+
74
+    /** {@inheritDoc} */
75
+    @Override
76
+    public CommandType getType() {
77
+        return CommandType.TYPE_GLOBAL;
78
+    }
70 79
     
71 80
     /** {@inheritDoc} */
72 81
     @Override

+ 29
- 29
src/com/dmdirc/addons/logging/LoggingCommand.java Bestand weergeven

@@ -25,9 +25,13 @@ package com.dmdirc.addons.logging;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27 27
 import com.dmdirc.commandparser.CommandArguments;
28
+import com.dmdirc.commandparser.CommandInfo;
28 29
 import com.dmdirc.commandparser.CommandManager;
30
+import com.dmdirc.commandparser.CommandType;
31
+import com.dmdirc.commandparser.commands.Command;
29 32
 import com.dmdirc.commandparser.commands.IntelligentCommand;
30
-import com.dmdirc.commandparser.commands.ServerCommand;
33
+import com.dmdirc.commandparser.commands.context.CommandContext;
34
+import com.dmdirc.commandparser.commands.context.ServerCommandContext;
31 35
 import com.dmdirc.plugins.Plugin;
32 36
 import com.dmdirc.plugins.PluginInfo;
33 37
 import com.dmdirc.plugins.PluginManager;
@@ -38,7 +42,8 @@ import com.dmdirc.ui.input.AdditionalTabTargets;
38 42
  *
39 43
  * @author Shane "Dataforce" Mc Cormack
40 44
  */
41
-public final class LoggingCommand extends ServerCommand implements IntelligentCommand {
45
+public final class LoggingCommand extends Command implements IntelligentCommand,
46
+        CommandInfo {
42 47
 
43 48
     /**
44 49
      * Creates a new instance of LoggingCommand.
@@ -50,17 +55,18 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
50 55
 
51 56
     /** {@inheritDoc} */
52 57
     @Override
53
-    public void execute(final FrameContainer<?> origin, final Server server,
54
-                        final boolean isSilent, final CommandArguments args) {
58
+    public void execute(final FrameContainer<?> origin,
59
+            final CommandArguments args, final CommandContext context) {
60
+        final Server server = ((ServerCommandContext) context).getServer();
55 61
         final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName("logging");
56 62
         if (pluginInfo == null) {
57
-            sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
63
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
58 64
             return;
59 65
         }
60 66
         final Plugin gotPlugin = pluginInfo.getPlugin();
61 67
 
62 68
         if (!(gotPlugin instanceof LoggingPlugin)) {
63
-            sendLine(origin, isSilent, FORMAT_ERROR, "Logging Plugin is not loaded.");
69
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Logging Plugin is not loaded.");
64 70
             return;
65 71
         }
66 72
 
@@ -69,23 +75,23 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
69 75
         if (args.getArguments().length > 0) {
70 76
             if (args.getArguments()[0].equalsIgnoreCase("reload")) {
71 77
                 if (PluginManager.getPluginManager().reloadPlugin(pluginInfo.getFilename())) {
72
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Plugin reloaded.");
78
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Plugin reloaded.");
73 79
                 } else {
74
-                    sendLine(origin, isSilent, FORMAT_ERROR, "Plugin failed to reload.");
80
+                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Plugin failed to reload.");
75 81
                 }
76 82
             } else if (args.getArguments()[0].equalsIgnoreCase("history")) {
77 83
                 if (!plugin.showHistory(origin)) {
78
-                    sendLine(origin, isSilent, FORMAT_ERROR, "Unable to open history for this window.");
84
+                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unable to open history for this window.");
79 85
                 }
80 86
             } else if (args.getArguments()[0].equalsIgnoreCase("help")) {
81
-                sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " reload           - Reload the logging plugin.");
82
-                sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " history          - Open the history of this window, if available.");
83
-                sendLine(origin, isSilent, FORMAT_OUTPUT, getName() + " help             - Show this help.");
87
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " reload           - Reload the logging plugin.");
88
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " history          - Open the history of this window, if available.");
89
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, getName() + " help             - Show this help.");
84 90
             } else {
85
-                sendLine(origin, isSilent, FORMAT_ERROR, "Unknown command '" + args.getArguments()[0] + "'. Use " + getName() + " help for a list of commands.");
91
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown command '" + args.getArguments()[0] + "'. Use " + getName() + " help for a list of commands.");
86 92
             }
87 93
         } else {
88
-            sendLine(origin, isSilent, FORMAT_ERROR, "Use " + getName() + " help for a list of commands.");
94
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Use " + getName() + " help for a list of commands.");
89 95
         }
90 96
     }
91 97
 
@@ -103,31 +109,25 @@ public final class LoggingCommand extends ServerCommand implements IntelligentCo
103 109
         return res;
104 110
     }
105 111
 
106
-    /**
107
-     * Returns this command's name.
108
-     *
109
-     * @return The name of this command
110
-     */
112
+    /** {@inheritDoc} */
111 113
     @Override
112 114
     public String getName() {
113 115
         return "logging";
114 116
     }
115 117
 
116
-    /**
117
-     * Returns whether or not this command should be shown in help messages.
118
-     *
119
-     * @return True iff the command should be shown, false otherwise
120
-     */
118
+    /** {@inheritDoc} */
121 119
     @Override
122 120
     public boolean showInHelp() {
123 121
         return true;
124 122
     }
125 123
 
126
-    /**
127
-     * Returns a string representing the help message for this command.
128
-     *
129
-     * @return the help message for this command
130
-     */
124
+    /** {@inheritDoc} */
125
+    @Override
126
+    public CommandType getType() {
127
+        return CommandType.TYPE_SERVER;
128
+    }
129
+
130
+    /** {@inheritDoc} */
131 131
     @Override
132 132
     public String getHelp() {
133 133
         return this.getName() + " <set|help> [parameters]";

+ 23
- 12
src/com/dmdirc/addons/nowplaying/NowPlayingCommand.java Bestand weergeven

@@ -24,11 +24,14 @@ package com.dmdirc.addons.nowplaying;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.MessageTarget;
27
-import com.dmdirc.Server;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29
-import com.dmdirc.commandparser.commands.ChatCommand;
28
+import com.dmdirc.commandparser.CommandInfo;
30 29
 import com.dmdirc.commandparser.CommandManager;
30
+import com.dmdirc.commandparser.CommandType;
31
+import com.dmdirc.commandparser.commands.Command;
31 32
 import com.dmdirc.commandparser.commands.IntelligentCommand;
33
+import com.dmdirc.commandparser.commands.context.ChatCommandContext;
34
+import com.dmdirc.commandparser.commands.context.CommandContext;
32 35
 import com.dmdirc.config.IdentityManager;
33 36
 import com.dmdirc.ui.input.AdditionalTabTargets;
34 37
 import com.dmdirc.ui.input.TabCompleter;
@@ -41,7 +44,8 @@ import java.util.List;
41 44
  * variety of media players.
42 45
  * @author chris
43 46
  */
44
-public final class NowPlayingCommand extends ChatCommand implements IntelligentCommand {
47
+public final class NowPlayingCommand extends Command implements 
48
+        IntelligentCommand, CommandInfo {
45 49
     
46 50
     /** The plugin that's using this command. */
47 51
     final NowPlayingPlugin parent;
@@ -61,11 +65,12 @@ public final class NowPlayingCommand extends ChatCommand implements IntelligentC
61 65
     
62 66
     /** {@inheritDoc} */
63 67
     @Override
64
-    public void execute(final FrameContainer<?> origin, final Server server,
65
-            final MessageTarget<?> target, final boolean isSilent, final CommandArguments args) {
68
+    public void execute(final FrameContainer<?> origin,
69
+            final CommandArguments args, final CommandContext context) {
70
+        final MessageTarget<?> target = ((ChatCommandContext) context).getChat();
66 71
         if (args.getArguments().length > 0 && args.getArguments()[0]
67 72
                 .equalsIgnoreCase("--sources")) {
68
-            doSourceList(origin, isSilent, args.getArgumentsAsString(1));
73
+            doSourceList(origin, args.isSilent(), args.getArgumentsAsString(1));
69 74
         } else if (args.getArguments().length > 0 && args.getArguments()[0]
70 75
                 .equalsIgnoreCase("--source")) {
71 76
             if (args.getArguments().length > 1) {
@@ -73,26 +78,26 @@ public final class NowPlayingCommand extends ChatCommand implements IntelligentC
73 78
                 final MediaSource source = parent.getSource(sourceName);
74 79
                 
75 80
                 if (source == null) {
76
-                    sendLine(origin, isSilent, FORMAT_ERROR, "Source not found.");
81
+                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source not found.");
77 82
                 } else {
78 83
                     if (source.getState() != MediaSourceState.CLOSED) {
79
-                        target.getCommandParser().parseCommand(origin,
84
+                        target.getCommandParser().parseCommand(origin, context.getSource(),
80 85
                                 getInformation(source, args.getArgumentsAsString(2)));
81 86
                     } else {
82
-                        sendLine(origin, isSilent, FORMAT_ERROR, "Source is not running.");
87
+                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "Source is not running.");
83 88
                     }
84 89
                 }
85 90
             } else {
86
-                sendLine(origin, isSilent, FORMAT_ERROR,
91
+                sendLine(origin, args.isSilent(), FORMAT_ERROR,
87 92
                         "You must specify a source when using --source.");
88 93
             }
89 94
         } else {
90 95
             if (parent.hasRunningSource()) {
91
-                target.getCommandParser().parseCommand(origin,
96
+                target.getCommandParser().parseCommand(origin, context.getSource(),
92 97
                         getInformation(parent.getBestSource(), args.
93 98
                         getArgumentsAsString(0)));
94 99
             } else {
95
-                sendLine(origin, isSilent, FORMAT_ERROR, "No running media sources available.");
100
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "No running media sources available.");
96 101
             }
97 102
         }
98 103
     }
@@ -169,6 +174,12 @@ public final class NowPlayingCommand extends ChatCommand implements IntelligentC
169 174
         return "nowplaying [--sources|--source <source>] [format] - " +
170 175
                 "tells the channel the song you're currently playing";
171 176
     }
177
+
178
+    /** {@inheritDoc} */
179
+    @Override
180
+    public CommandType getType() {
181
+        return CommandType.TYPE_CHAT;
182
+    }
172 183
     
173 184
     /** {@inheritDoc} */
174 185
     @Override

+ 14
- 4
src/com/dmdirc/addons/osd/OsdCommand.java Bestand weergeven

@@ -24,9 +24,12 @@ package com.dmdirc.addons.osd;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
29 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32
+import com.dmdirc.commandparser.commands.context.CommandContext;
30 33
 import com.dmdirc.ui.input.AdditionalTabTargets;
31 34
 import com.dmdirc.ui.messages.Styliser;
32 35
 
@@ -34,7 +37,8 @@ import com.dmdirc.ui.messages.Styliser;
34 37
  * The osd command shows an on screen message.
35 38
  * @author chris
36 39
  */
37
-public final class OsdCommand extends GlobalCommand implements IntelligentCommand {
40
+public final class OsdCommand extends Command implements 
41
+        IntelligentCommand, CommandInfo {
38 42
 
39 43
     /** The plugin that owns this command. */
40 44
     private final OsdPlugin plugin;
@@ -70,8 +74,8 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
70 74
 
71 75
     /** {@inheritDoc} */
72 76
     @Override
73
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
74
-            final CommandArguments args) {
77
+    public void execute(final FrameContainer<?> origin,
78
+            final CommandArguments args, final CommandContext context) {
75 79
         if (args.getArguments().length > 0
76 80
                 && "--close".equalsIgnoreCase(args.getArguments()[0])) {
77 81
             osdManager.closeAll();
@@ -91,6 +95,12 @@ public final class OsdCommand extends GlobalCommand implements IntelligentComman
91 95
     public boolean showInHelp() {
92 96
         return true;
93 97
     }
98
+
99
+    /** {@inheritDoc} */
100
+    @Override
101
+    public CommandType getType() {
102
+        return CommandType.TYPE_GLOBAL;
103
+    }
94 104
     
95 105
     /** {@inheritDoc}. */
96 106
     @Override

+ 17
- 6
src/com/dmdirc/addons/redirect/RedirectCommand.java Bestand weergeven

@@ -24,10 +24,13 @@ package com.dmdirc.addons.redirect;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.MessageTarget;
27
-import com.dmdirc.Server;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29
-import com.dmdirc.commandparser.commands.ChatCommand;
28
+import com.dmdirc.commandparser.CommandInfo;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
30 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32
+import com.dmdirc.commandparser.commands.context.ChatCommandContext;
33
+import com.dmdirc.commandparser.commands.context.CommandContext;
31 34
 import com.dmdirc.ui.input.AdditionalTabTargets;
32 35
 import com.dmdirc.ui.input.TabCompleter;
33 36
 
@@ -38,17 +41,19 @@ import com.dmdirc.ui.input.TabCompleter;
38 41
  *
39 42
  * @author Chris
40 43
  */
41
-public class RedirectCommand extends ChatCommand implements IntelligentCommand {
44
+public class RedirectCommand extends Command implements IntelligentCommand,
45
+        CommandInfo {
42 46
     
43 47
     public RedirectCommand() {
44 48
     }
45 49
     
46 50
     /** {@inheritDoc} */
47 51
     @Override
48
-    public void execute(final FrameContainer<?> origin, final Server server,
49
-            final MessageTarget<?> target, final boolean isSilent, final CommandArguments args) {
52
+    public void execute(final FrameContainer<?> origin,
53
+            final CommandArguments args, final CommandContext context) {
54
+        final MessageTarget<?> target = ((ChatCommandContext) context).getChat();
50 55
         target.getCommandParser().parseCommand(new FakeWriteableFrameContainer(target),
51
-                args.getArgumentsAsString());
56
+                context.getSource(), args.getArgumentsAsString());
52 57
     }
53 58
     
54 59
     /** {@inheritDoc} */
@@ -62,6 +67,12 @@ public class RedirectCommand extends ChatCommand implements IntelligentCommand {
62 67
     public boolean showInHelp() {
63 68
         return true;
64 69
     }
70
+
71
+    /** {@inheritDoc} */
72
+    @Override
73
+    public CommandType getType() {
74
+        return CommandType.TYPE_CHAT;
75
+    }
65 76
     
66 77
     /** {@inheritDoc} */
67 78
     @Override

+ 74
- 68
src/com/dmdirc/addons/scriptplugin/ScriptCommand.java Bestand weergeven

@@ -24,10 +24,13 @@ package com.dmdirc.addons.scriptplugin;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.config.IdentityManager;
28 29
 import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.commandparser.commands.GlobalCommand;
30
+import com.dmdirc.commandparser.CommandType;
31
+import com.dmdirc.commandparser.commands.Command;
30 32
 import com.dmdirc.commandparser.commands.IntelligentCommand;
33
+import com.dmdirc.commandparser.commands.context.CommandContext;
31 34
 import com.dmdirc.ui.input.AdditionalTabTargets;
32 35
 
33 36
 import java.util.LinkedList;
@@ -43,12 +46,15 @@ import java.lang.reflect.Method;
43 46
  *
44 47
  * @author Shane 'Dataforce' McCormack
45 48
  */
46
-public final class ScriptCommand extends GlobalCommand implements IntelligentCommand {
49
+public final class ScriptCommand extends Command implements IntelligentCommand,
50
+        CommandInfo {
47 51
     /** My Plugin */
48 52
     final ScriptPlugin myPlugin;
49 53
 
50 54
     /**
51 55
      * Creates a new instance of ScriptCommand.
56
+     *
57
+     * @param plugin Parent plugin
52 58
      */
53 59
     public ScriptCommand(final ScriptPlugin plugin) {
54 60
         super();
@@ -58,31 +64,31 @@ public final class ScriptCommand extends GlobalCommand implements IntelligentCom
58 64
         
59 65
     /** {@inheritDoc} */
60 66
     @Override
61
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
62
-            final CommandArguments commandArgs) {
63
-        final String[] args = commandArgs.getArguments();
67
+    public void execute(final FrameContainer<?> origin,
68
+            final CommandArguments args, final CommandContext context) {
69
+        final String[] sargs = args.getArguments();
64 70
     
65
-        if (args.length > 0 && (args[0].equalsIgnoreCase("rehash") || args[0].equalsIgnoreCase("reload"))) {
66
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Reloading scripts");
71
+        if (sargs.length > 0 && (sargs[0].equalsIgnoreCase("rehash") || sargs[0].equalsIgnoreCase("reload"))) {
72
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Reloading scripts");
67 73
             myPlugin.rehash();
68
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("load")) {
69
-            if (args.length > 1) {
70
-                final String filename = commandArgs.getArgumentsAsString(1);
71
-                sendLine(origin, isSilent, FORMAT_OUTPUT, "Loading: "+filename+" ["+myPlugin.loadScript(myPlugin.getScriptDir()+filename)+"]");
74
+        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("load")) {
75
+            if (sargs.length > 1) {
76
+                final String filename = args.getArgumentsAsString(1);
77
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Loading: "+filename+" ["+myPlugin.loadScript(myPlugin.getScriptDir()+filename)+"]");
72 78
             } else {
73
-                sendLine(origin, isSilent, FORMAT_ERROR, "You must specify a script to load");
79
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to load");
74 80
             }
75
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("unload")) {
76
-            if (args.length > 1) {
77
-                final String filename = commandArgs.getArgumentsAsString(1);
78
-                sendLine(origin, isSilent, FORMAT_OUTPUT, "Unloading: "+filename+" ["+myPlugin.loadScript(myPlugin.getScriptDir()+filename)+"]");
81
+        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("unload")) {
82
+            if (sargs.length > 1) {
83
+                final String filename = args.getArgumentsAsString(1);
84
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Unloading: "+filename+" ["+myPlugin.loadScript(myPlugin.getScriptDir()+filename)+"]");
79 85
             } else {
80
-                sendLine(origin, isSilent, FORMAT_ERROR, "You must specify a script to unload");
86
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a script to unload");
81 87
             }
82
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("eval")) {
83
-            if (args.length > 1) {
84
-                final String script = commandArgs.getArgumentsAsString(1);
85
-                sendLine(origin, isSilent, FORMAT_OUTPUT, "Evaluating: "+script);
88
+        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("eval")) {
89
+            if (sargs.length > 1) {
90
+                final String script = args.getArgumentsAsString(1);
91
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Evaluating: "+script);
86 92
                 try {
87 93
                     ScriptEngineWrapper wrapper;
88 94
                     if (IdentityManager.getGlobalConfig().hasOptionString(myPlugin.getDomain(), "eval.baseFile")) {
@@ -96,11 +102,11 @@ public final class ScriptCommand extends GlobalCommand implements IntelligentCom
96 102
                         wrapper = new ScriptEngineWrapper(myPlugin, null);
97 103
                     }
98 104
                     wrapper.getScriptEngine().put("cmd_origin", origin);
99
-                    wrapper.getScriptEngine().put("cmd_isSilent", isSilent);
100
-                    wrapper.getScriptEngine().put("cmd_args", args);
101
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Result: "+wrapper.getScriptEngine().eval(script));
105
+                    wrapper.getScriptEngine().put("cmd_isSilent", args.isSilent());
106
+                    wrapper.getScriptEngine().put("cmd_args", sargs);
107
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Result: "+wrapper.getScriptEngine().eval(script));
102 108
                 } catch (Exception e) {
103
-                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Exception: "+e+" -> "+e.getMessage());
109
+                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Exception: "+e+" -> "+e.getMessage());
104 110
                     
105 111
                     if (IdentityManager.getGlobalConfig().getOptionBool(myPlugin.getDomain(), "eval.showStackTrace")) {
106 112
                         try {
@@ -111,24 +117,24 @@ public final class ScriptCommand extends GlobalCommand implements IntelligentCom
111 117
                                 
112 118
                                 final String[] stacktrace = (String[])exceptionToStringArray.invoke(null, e);
113 119
                                 for (String line : stacktrace) {
114
-                                    sendLine(origin, isSilent, FORMAT_OUTPUT, "Stack trace: "+line);
120
+                                    sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Stack trace: "+line);
115 121
                                 }
116 122
                             }
117 123
                         } catch (Exception ex) {
118
-                            sendLine(origin, isSilent, FORMAT_OUTPUT, "Stack trace: Exception showing stack trace: "+ex+" -> "+ex.getMessage());
124
+                            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Stack trace: Exception showing stack trace: "+ex+" -> "+ex.getMessage());
119 125
                         }
120 126
                     }
121 127
                     
122 128
                 }
123 129
             } else {
124
-                sendLine(origin, isSilent, FORMAT_ERROR, "You must specify some script to eval.");
130
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify some script to eval.");
125 131
             }
126
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("savetobasefile")) {
127
-            if (args.length > 2) {
128
-                final String[] bits = args[1].split("/");
132
+        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("savetobasefile")) {
133
+            if (sargs.length > 2) {
134
+                final String[] bits = sargs[1].split("/");
129 135
                 final String functionName = bits[0];
130
-                final String script = commandArgs.getArgumentsAsString(2);
131
-                sendLine(origin, isSilent, FORMAT_OUTPUT, "Saving as '"+functionName+"': "+script);
136
+                final String script = args.getArgumentsAsString(2);
137
+                sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Saving as '"+functionName+"': "+script);
132 138
                 if (IdentityManager.getGlobalConfig().hasOptionString(myPlugin.getDomain(), "eval.baseFile")) {
133 139
                     try {
134 140
                         final String baseFile = myPlugin.getScriptDir()+'/'+IdentityManager.getGlobalConfig().getOption(myPlugin.getDomain(), "eval.baseFile");
@@ -146,29 +152,29 @@ public final class ScriptCommand extends GlobalCommand implements IntelligentCom
146 152
                         writer.flush();
147 153
                         writer.close();
148 154
                     } catch (IOException ioe) {
149
-                        sendLine(origin, isSilent, FORMAT_ERROR, "IOException: "+ioe.getMessage());
155
+                        sendLine(origin, args.isSilent(), FORMAT_ERROR, "IOException: "+ioe.getMessage());
150 156
                     }
151 157
                 } else {
152
-                    sendLine(origin, isSilent, FORMAT_ERROR, "No baseFile specified, please /set "+myPlugin.getDomain()+" eval.baseFile filename (stored in scripts dir of profile)");
158
+                    sendLine(origin, args.isSilent(), FORMAT_ERROR, "No baseFile specified, please /set "+myPlugin.getDomain()+" eval.baseFile filename (stored in scripts dir of profile)");
153 159
                 }
154
-            } else if (args.length > 1) {
155
-                sendLine(origin, isSilent, FORMAT_ERROR, "You must specify some script to save.");
160
+            } else if (sargs.length > 1) {
161
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify some script to save.");
156 162
             } else {
157
-                sendLine(origin, isSilent, FORMAT_ERROR, "You must specify a function name and some script to save.");
163
+                sendLine(origin, args.isSilent(), FORMAT_ERROR, "You must specify a function name and some script to save.");
158 164
             }
159
-        } else if (args.length > 0 && args[0].equalsIgnoreCase("help")) {
160
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "This command allows you to interact with the script plugin");
161
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "-------------------");
162
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "reload/rehash                  - Reload all loaded scripts");
163
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "load <script>                  - load scripts/<script> (file name relative to scripts dir)");
164
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "unload <script>                - unload <script> (full file name)");
165
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "eval <script>                  - evaluate the code <script> and return the result");
166
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "savetobasefile <name> <script> - save the code <script> to the eval basefile ("+myPlugin.getDomain()+".eval.basefile)");
167
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "                                 as the function <name> (name/foo/bar will save it as 'name' with foo and");
168
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "                                 bar as arguments.");
169
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "-------------------");
165
+        } else if (sargs.length > 0 && sargs[0].equalsIgnoreCase("help")) {
166
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "This command allows you to interact with the script plugin");
167
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
168
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "reload/rehash                  - Reload all loaded scripts");
169
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "load <script>                  - load scripts/<script> (file name relative to scripts dir)");
170
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "unload <script>                - unload <script> (full file name)");
171
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "eval <script>                  - evaluate the code <script> and return the result");
172
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "savetobasefile <name> <script> - save the code <script> to the eval basefile ("+myPlugin.getDomain()+".eval.basefile)");
173
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "                                 as the function <name> (name/foo/bar will save it as 'name' with foo and");
174
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "                                 bar as arguments.");
175
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "-------------------");
170 176
         } else {
171
-            sendLine(origin, isSilent, FORMAT_ERROR, "Unknown subcommand.");
177
+            sendLine(origin, args.isSilent(), FORMAT_ERROR, "Unknown subcommand.");
172 178
         }
173 179
     }
174 180
 
@@ -230,28 +236,28 @@ public final class ScriptCommand extends GlobalCommand implements IntelligentCom
230 236
         return res;
231 237
     }
232 238
 
233
-    /**
234
-     * Returns this command's name.
235
-     *
236
-     * @return The name of this command
237
-     */
239
+    /** {@inheritDoc} */
238 240
     @Override
239
-    public String getName() { return "script"; }
241
+    public String getName() { 
242
+        return "script";
243
+    }
240 244
     
241
-    /**
242
-     * Returns whether or not this command should be shown in help messages.
243
-     *
244
-     * @return True iff the command should be shown, false otherwise
245
-     */
245
+    /** {@inheritDoc} */
246 246
     @Override
247
-    public boolean showInHelp() { return true; }
247
+    public boolean showInHelp() { 
248
+        return true;
249
+    }
250
+
251
+    /** {@inheritDoc} */
252
+    @Override
253
+    public CommandType getType() {
254
+        return CommandType.TYPE_GLOBAL;
255
+    }
248 256
     
249
-    /**
250
-     * Returns a string representing the help message for this command.
251
-     *
252
-     * @return the help message for this command
253
-     */
257
+    /** {@inheritDoc} */
254 258
     @Override
255
-    public String getHelp() { return "script - Allows controlling the script plugin"; }
259
+    public String getHelp() { 
260
+        return "script - Allows controlling the script plugin";
261
+    }
256 262
 }
257 263
 

+ 13
- 5
src/com/dmdirc/addons/systray/PopupCommand.java Bestand weergeven

@@ -23,17 +23,19 @@
23 23
 package com.dmdirc.addons.systray;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.Server;
27 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
28 28
 import com.dmdirc.commandparser.CommandManager;
29
-import com.dmdirc.commandparser.commands.ServerCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
30 32
 
31 33
 /**
32 34
  * The /popup command allows the user to show a popup message from the system
33 35
  * tray icon.
34 36
  * @author chris
35 37
  */
36
-public final class PopupCommand extends ServerCommand {
38
+public final class PopupCommand extends Command implements CommandInfo {
37 39
     
38 40
     /** The SystrayPlugin that we belong to. */
39 41
     private final SystrayPlugin parent;
@@ -64,8 +66,8 @@ public final class PopupCommand extends ServerCommand {
64 66
 
65 67
     /** {@inheritDoc} */
66 68
     @Override
67
-    public void execute(final FrameContainer<?> origin, final Server server,
68
-            final boolean isSilent, final CommandArguments args) {
69
+    public void execute(final FrameContainer<?> origin,
70
+            final CommandArguments args, final CommandContext context) {
69 71
         showPopup("DMDirc", args.getArgumentsAsString());
70 72
     }
71 73
 
@@ -81,6 +83,12 @@ public final class PopupCommand extends ServerCommand {
81 83
         return true;
82 84
     }
83 85
 
86
+    /** {@inheritDoc} */
87
+    @Override
88
+    public CommandType getType() {
89
+        return CommandType.TYPE_SERVER;
90
+    }
91
+
84 92
     /** {@inheritDoc} */
85 93
     @Override
86 94
     public String getHelp() {

+ 11
- 4
src/com/dmdirc/addons/time/TimedCommand.java Bestand weergeven

@@ -26,6 +26,7 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.WritableFrameContainer;
27 27
 import com.dmdirc.commandparser.parsers.CommandParser;
28 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
+import com.dmdirc.ui.interfaces.Window;
29 30
 
30 31
 import java.util.Timer;
31 32
 import java.util.TimerTask;
@@ -41,8 +42,11 @@ public final class TimedCommand extends TimerTask {
41 42
     /** The command to execute. */
42 43
     private final String command;
43 44
     
44
-    /** The window to use for executing commands. */
45
+    /** The container to use for executing commands. */
45 46
     private final FrameContainer<?> origin;
47
+
48
+    /** The window the command came from. */
49
+    private final Window window;
46 50
     
47 51
     /** The timer we're using for scheduling this command. */
48 52
     private final Timer timer;
@@ -52,15 +56,18 @@ public final class TimedCommand extends TimerTask {
52 56
      * @param repetitions The number of times this command will be executed
53 57
      * @param delay The number of seconds between each execution
54 58
      * @param command The command to be executed
55
-     * @param origin The command window to use for the execution
59
+     * @param origin The frame container to use for the execution
60
+     * @param window The window the command came from
56 61
      */
57 62
     public TimedCommand(final int repetitions, final int delay,
58
-            final String command, final FrameContainer<?> origin) {
63
+            final String command, final FrameContainer<?> origin,
64
+            final Window window) {
59 65
         super();
60 66
         
61 67
         this.repetitions = repetitions;
62 68
         this.command = command;
63 69
         this.origin = origin;
70
+        this.window = window;
64 71
         
65 72
         timer = new Timer("Timed Command Timer");
66 73
         timer.schedule(this, delay * 1000L, delay * 1000L);
@@ -76,7 +83,7 @@ public final class TimedCommand extends TimerTask {
76 83
             parser = ((WritableFrameContainer<?>) origin).getCommandParser();
77 84
         }
78 85
         
79
-        parser.parseCommand(origin, command);
86
+        parser.parseCommand(origin, window, command);
80 87
                 
81 88
         if (--repetitions <= 0) {
82 89
             timer.cancel();

+ 18
- 8
src/com/dmdirc/addons/time/TimerCommand.java Bestand weergeven

@@ -24,9 +24,12 @@ package com.dmdirc.addons.time;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.CommandInfo;
27 28
 import com.dmdirc.commandparser.CommandManager;
28
-import com.dmdirc.commandparser.commands.GlobalCommand;
29
+import com.dmdirc.commandparser.CommandType;
30
+import com.dmdirc.commandparser.commands.Command;
29 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32
+import com.dmdirc.commandparser.commands.context.CommandContext;
30 33
 import com.dmdirc.ui.input.AdditionalTabTargets;
31 34
 import com.dmdirc.ui.input.TabCompleter;
32 35
 
@@ -35,7 +38,8 @@ import com.dmdirc.ui.input.TabCompleter;
35 38
  * interval, or to repeatedly occur with a specified delay.
36 39
  * @author chris
37 40
  */
38
-public final class TimerCommand extends GlobalCommand implements IntelligentCommand {
41
+public final class TimerCommand extends Command implements IntelligentCommand,
42
+        CommandInfo {
39 43
     
40 44
     /**
41 45
      * Creates a new instance of TimerCommand.
@@ -46,10 +50,10 @@ public final class TimerCommand extends GlobalCommand implements IntelligentComm
46 50
     
47 51
     /** {@inheritDoc} */
48 52
     @Override
49
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
50
-            final CommandArguments args) {
53
+    public void execute(final FrameContainer<?> origin,
54
+            final CommandArguments args, final CommandContext context) {
51 55
         if (args.getArguments().length < 3) {
52
-            doUsage(origin, isSilent);
56
+            doUsage(origin, args.isSilent());
53 57
         } else {
54 58
             int repetitions = 0;
55 59
             int interval = 0;
@@ -59,12 +63,12 @@ public final class TimerCommand extends GlobalCommand implements IntelligentComm
59 63
                 repetitions = Integer.parseInt(args.getArguments()[0]);
60 64
                 interval = Integer.parseInt(args.getArguments()[1]);
61 65
             } catch (NumberFormatException ex) {
62
-                doUsage(origin, isSilent);
66
+                doUsage(origin, args.isSilent());
63 67
                 return;
64 68
             }
65 69
             
66
-            new TimedCommand(repetitions, interval, command, origin);
67
-            sendLine(origin, isSilent, FORMAT_OUTPUT, "Command scheduled.");
70
+            new TimedCommand(repetitions, interval, command, origin, context.getSource());
71
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Command scheduled.");
68 72
         }
69 73
     }
70 74
     
@@ -88,6 +92,12 @@ public final class TimerCommand extends GlobalCommand implements IntelligentComm
88 92
     public boolean showInHelp() {
89 93
         return true;
90 94
     }
95
+
96
+    /** {@inheritDoc} */
97
+    @Override
98
+    public CommandType getType() {
99
+        return CommandType.TYPE_GLOBAL;
100
+    }
91 101
     
92 102
     /** {@inheritDoc} */
93 103
     @Override

+ 1
- 1
src/com/dmdirc/addons/ui_swing/actions/CommandAction.java Bestand weergeven

@@ -74,7 +74,7 @@ public class CommandAction extends AbstractAction {
74 74
      */
75 75
     @Override
76 76
     public void actionPerformed(final ActionEvent e) {
77
-        parser.parseCommand(window.getContainer(), command);
77
+        parser.parseCommand(window.getContainer(), window, command);
78 78
     }
79 79
     
80 80
 }

+ 22
- 6
src/com/dmdirc/addons/urlcatcher/UrlListCommand.java Bestand weergeven

@@ -24,8 +24,11 @@ package com.dmdirc.addons.urlcatcher;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27
-import com.dmdirc.commandparser.commands.GlobalCommand;
27
+import com.dmdirc.commandparser.CommandInfo;
28
+import com.dmdirc.commandparser.CommandType;
29
+import com.dmdirc.commandparser.commands.Command;
28 30
 import com.dmdirc.commandparser.commands.IntelligentCommand;
31
+import com.dmdirc.commandparser.commands.context.CommandContext;
29 32
 import com.dmdirc.ui.input.AdditionalTabTargets;
30 33
 
31 34
 import java.util.Map;
@@ -34,18 +37,25 @@ import java.util.Map;
34 37
  *
35 38
  * @author chris
36 39
  */
37
-public class UrlListCommand extends GlobalCommand implements IntelligentCommand {
40
+public class UrlListCommand extends Command implements IntelligentCommand,
41
+        CommandInfo {
38 42
     
39 43
     private final UrlCatcherPlugin plugin;
40
-    
44
+
45
+    /**
46
+     * Creates a new URL List command, outputting all known URLs seen by the URL
47
+     * catcher plugin to the active window.
48
+     *
49
+     * @param plugin Parent plugin
50
+     */
41 51
     public UrlListCommand(final UrlCatcherPlugin plugin) {
42 52
         this.plugin = plugin;
43 53
     }
44 54
 
45 55
     /** {@inheritDoc} */
46 56
     @Override
47
-    public void execute(final FrameContainer<?> origin, final boolean isSilent,
48
-            final CommandArguments args) {
57
+    public void execute(final FrameContainer<?> origin,
58
+            final CommandArguments args, final CommandContext context) {
49 59
         final String[] headers = {"URL", "Count"};
50 60
         final Map<String, Integer> map = plugin.getURLS();
51 61
         final String[][] data = new String[map.size()][];
@@ -55,7 +65,7 @@ public class UrlListCommand extends GlobalCommand implements IntelligentCommand
55 65
             data[i++] = new String[]{entry.getKey(), entry.getValue().toString()};
56 66
         }
57 67
         
58
-        sendLine(origin, isSilent, FORMAT_OUTPUT, doTable(headers, data));
68
+        sendLine(origin, args.isSilent(), FORMAT_OUTPUT, doTable(headers, data));
59 69
     }
60 70
 
61 71
     /** {@inheritDoc} */
@@ -70,6 +80,12 @@ public class UrlListCommand extends GlobalCommand implements IntelligentCommand
70 80
         return true;
71 81
     }
72 82
 
83
+    /** {@inheritDoc} */
84
+    @Override
85
+    public CommandType getType() {
86
+        return CommandType.TYPE_GLOBAL;
87
+    }
88
+
73 89
     /** {@inheritDoc} */
74 90
     @Override
75 91
     public String getHelp() {

+ 8
- 4
test/com/dmdirc/addons/redirect/RedirectCommandTest.java Bestand weergeven

@@ -25,11 +25,14 @@ package com.dmdirc.addons.redirect;
25 25
 import com.dmdirc.MessageTarget;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandManager;
28
+import com.dmdirc.commandparser.commands.context.ChatCommandContext;
28 29
 import com.dmdirc.commandparser.parsers.CommandParser;
29 30
 import com.dmdirc.commandparser.parsers.ServerCommandParser;
30 31
 import com.dmdirc.config.IdentityManager;
31 32
 import com.dmdirc.config.InvalidIdentityFileException;
32 33
 import com.dmdirc.ui.interfaces.InputWindow;
34
+import java.util.ArrayList;
35
+import java.util.Arrays;
33 36
 import org.junit.BeforeClass;
34 37
 import org.junit.Ignore;
35 38
 import org.junit.Test;
@@ -47,14 +50,15 @@ public class RedirectCommandTest {
47 50
     @Test
48 51
     public void testExecute() {
49 52
         final RedirectCommand command = new RedirectCommand();
50
-        final MessageTarget<?> target = mock(MessageTarget.class);
53
+        final MessageTarget<InputWindow> target = mock(MessageTarget.class);
51 54
         final InputWindow window = mock(InputWindow.class);
52
-        when(target.getFrame()).thenReturn(window);
55
+        when(target.getWindows()).thenReturn(new ArrayList<InputWindow>(Arrays.asList(window)));
53 56
         final CommandParser parser = new ServerCommandParser();
54 57
         when(window.getCommandParser()).thenReturn(parser);
55
-        when(window.getConfigManager()).thenReturn(IdentityManager.getGlobalConfig());
58
+        when(window.getContainer().getConfigManager()).thenReturn(IdentityManager.getGlobalConfig());
56 59
 
57
-        command.execute(target, null, target, false, new CommandArguments("/redirect /echo test"));
60
+        command.execute(target, new CommandArguments("/redirect /echo test"),
61
+                new ChatCommandContext(window, command, target));
58 62
         
59 63
         verify(target).sendLine("test");
60 64
     }

Laden…
Annuleren
Opslaan