Переглянути джерело

Added skeleton dcop plugin

Added /loadplugin command
Made PluginManager a singleton

git-svn-id: http://svn.dmdirc.com/trunk@837 00569f92-eb28-0410-84fd-f71c24880f
tags/0.3
Chris Smith 17 роки тому
джерело
коміт
1519239079

+ 1
- 0
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java Переглянути файл

@@ -115,6 +115,7 @@ public final class CommandManager {
115 115
         new Help();
116 116
         new Join();
117 117
         new LoadFormatter();
118
+        new LoadPlugin();
118 119
         new Motd();
119 120
         new Nick();
120 121
         new Quit();

+ 1
- 1
src/uk/org/ownage/dmdirc/commandparser/ServerCommand.java Переглянути файл

@@ -37,5 +37,5 @@ public abstract class ServerCommand extends Command {
37 37
      * @param server The server instance that this command is being executed on
38 38
      * @param args Arguments passed to this command
39 39
      */
40
-    public abstract void execute(CommandWindow origin, Server server, String... args);
40
+    public abstract void execute(CommandWindow origin, Server server, String ... args);
41 41
 }

+ 89
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/server/LoadPlugin.java Переглянути файл

@@ -0,0 +1,89 @@
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 uk.org.ownage.dmdirc.commandparser.commands.server;
24
+
25
+import uk.org.ownage.dmdirc.Server;
26
+import uk.org.ownage.dmdirc.commandparser.CommandManager;
27
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
28
+import uk.org.ownage.dmdirc.commandparser.ServerCommand;
29
+import uk.org.ownage.dmdirc.plugins.PluginManager;
30
+import uk.org.ownage.dmdirc.ui.messages.Formatter;
31
+
32
+/**
33
+ * Allows the user to load a plugin.
34
+ * @author chris
35
+ */
36
+public final class LoadPlugin extends ServerCommand {
37
+    
38
+    /**
39
+     * Creates a new instance of LoadPlugin.
40
+     */
41
+    public LoadPlugin() {
42
+        super();
43
+        
44
+        CommandManager.registerCommand(this);
45
+    }
46
+    
47
+    /**
48
+     * Executes this command.
49
+     * @param origin The frame in which this command was issued
50
+     * @param server The server object that this command is associated with
51
+     * @param args The user supplied arguments
52
+     */
53
+    public void execute(final CommandWindow origin, final Server server,
54
+            final String... args) {
55
+        try {
56
+            PluginManager.getPluginManager().addPlugin(args[0], args[0]);
57
+            origin.addLine("Plugin loaded.");
58
+        } catch (Exception ex) {
59
+            origin.addLine("Load failed: " + ex.getMessage());
60
+        }
61
+    }
62
+    
63
+    
64
+    /** {@inheritDoc}. */
65
+    public String getName() {
66
+        return "loadplugin";
67
+    }
68
+    
69
+    /** {@inheritDoc}. */
70
+    public boolean showInHelp() {
71
+        return true;
72
+    }
73
+    
74
+    /** {@inheritDoc}. */
75
+    public boolean isPolyadic() {
76
+        return false;
77
+    }
78
+    
79
+    /** {@inheritDoc}. */
80
+    public int getArity() {
81
+        return 1;
82
+    }
83
+    
84
+    /** {@inheritDoc}. */
85
+    public String getHelp() {
86
+        return "loadplugin <class> - loads the specified class as a plugin";
87
+    }
88
+    
89
+}

+ 23
- 17
src/uk/org/ownage/dmdirc/plugins/PluginManager.java Переглянути файл

@@ -23,16 +23,11 @@
23 23
  */
24 24
 package uk.org.ownage.dmdirc.plugins;
25 25
 
26
-import java.util.Hashtable;
27 26
 import java.lang.reflect.Constructor;
28 27
 import java.lang.reflect.InvocationTargetException;
28
+import java.util.Hashtable;
29 29
 
30
-import java.io.BufferedReader;
31
-import java.io.FileInputStream;
32
-import java.io.IOException;
33
-import java.io.InputStream;
34
-import java.io.InputStreamReader;
35
-import java.net.URL;
30
+import uk.org.ownage.dmdirc.Config;
36 31
 
37 32
 public class PluginManager {
38 33
 	/**
@@ -47,22 +42,33 @@ public class PluginManager {
47 42
 	/**
48 43
 	 * Directory where plugins are stored.
49 44
 	 */
50
-	 private String myDir;
51
-	
45
+	 private final String myDir;
46
+         
52 47
 	/**
53
-	 * Create a new PluginManager.
54
-	 */
55
-	public PluginManager() {
56
-		myDir = ".";
57
-	}
48
+         * Singleton instance of the plugin manager.
49
+         */
50
+         private static PluginManager me;
58 51
 	
59 52
 	/**
60 53
 	 * Create a new PluginManager.
61 54
 	 */
62
-	public PluginManager(final String directory) {
63
-		myDir = directory;
55
+	private PluginManager() {
56
+		final String fs = System.getProperty("file.separator");
57
+		myDir = Config.getConfigDir() + "plugins" + fs;
64 58
 	}
65
-	
59
+        
60
+        /**
61
+         * Retrieves the singleton instance of the plugin manager.
62
+         * @return A singleton instance of PluginManager.
63
+         */
64
+        public final static synchronized PluginManager getPluginManager() {
65
+            if (me == null) {
66
+                me = new PluginManager();
67
+            }
68
+            
69
+            return me;
70
+        }
71
+		
66 72
 	/**
67 73
 	 * Add a new plugin.
68 74
 	 *

+ 86
- 0
src/uk/org/ownage/dmdirc/plugins/plugins/dcop/DcopPlugin.java Переглянути файл

@@ -0,0 +1,86 @@
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 uk.org.ownage.dmdirc.plugins.plugins.dcop;
24
+
25
+import uk.org.ownage.dmdirc.Server;
26
+import uk.org.ownage.dmdirc.commandparser.CommandManager;
27
+import uk.org.ownage.dmdirc.commandparser.CommandWindow;
28
+import uk.org.ownage.dmdirc.commandparser.ServerCommand;
29
+import uk.org.ownage.dmdirc.plugins.Plugin;
30
+
31
+/**
32
+ * Allows the user to execute dcop commands (and read the results).
33
+ * @author chris
34
+ */
35
+public class DcopPlugin implements Plugin {
36
+    
37
+    /** Creates a new instance of DcopPlugin */
38
+    public DcopPlugin() {
39
+        
40
+    }
41
+    
42
+    public void onLoad() {
43
+        CommandManager.registerCommand(new ServerCommand() {
44
+            public void execute(CommandWindow origin, Server server, String ... args) {
45
+                origin.addLine("dcop test");
46
+            }
47
+            public int getArity() {
48
+                return 0;
49
+            }
50
+            public String getHelp() {
51
+                return null;
52
+            }
53
+            public String getName() {
54
+                return "dcoptest";
55
+            }
56
+            public boolean isPolyadic() {
57
+                return false;
58
+            }
59
+            public boolean showInHelp() {
60
+                return false;
61
+            }
62
+        });
63
+    }
64
+    
65
+    public void onUnload() {
66
+    }
67
+    
68
+    public void onActivate() {
69
+    }
70
+    
71
+    public void onDeactivate() {
72
+    }
73
+    
74
+    public int getVersion() {
75
+        return 0;
76
+    }
77
+    
78
+    public String getAuthor() {
79
+        return "Chris 'MD87' Smith - chris@dmdirc.com";
80
+    }
81
+    
82
+    public String getDescription() {
83
+        return "Provides commands to interface with DCOP applications";
84
+    }
85
+    
86
+}

Завантаження…
Відмінити
Зберегти