1414import ru .intervi .jsplugins .api .InvalidPluginException ;
1515import ru .intervi .jsplugins .api .PluginListener ;
1616
17+ /**
18+ * управление плагинами
19+ */
1720public class PluginManager {
1821 public PluginManager () {
1922 STANDALONE = false ;
@@ -27,6 +30,16 @@ public PluginManager(Main main) {
2730 private ConcurrentHashMap <String , String > cmdsMap = new ConcurrentHashMap <String , String >();
2831 private final boolean STANDALONE ;
2932
33+ /**
34+ * загрузить плагин
35+ * @param path
36+ * @throws NullPointerException
37+ * @throws IOException
38+ * @throws InvalidPluginException
39+ * @throws ClassNotFoundException
40+ * @throws InstantiationException
41+ * @throws IllegalAccessException
42+ */
3043 public void loadPlugin (File path ) throws NullPointerException , IOException , InvalidPluginException , ClassNotFoundException , InstantiationException , IllegalAccessException {
3144 if (!path .isFile ()) throw new NullPointerException ("not found: " + path .getAbsolutePath ());
3245 URLClassLoader loader = new URLClassLoader (new URL [] {path .toURI ().toURL ()});
@@ -47,20 +60,54 @@ public void loadPlugin(File path) throws NullPointerException, IOException, Inva
4760 } finally {loader .close ();}
4861 }
4962
63+ /**
64+ * загрузить плагин
65+ * @param path
66+ * @throws NullPointerException
67+ * @throws IOException
68+ * @throws InvalidPluginException
69+ * @throws ClassNotFoundException
70+ * @throws InstantiationException
71+ * @throws IllegalAccessException
72+ */
5073 public void loadPlugin (String path ) throws NullPointerException , IOException , InvalidPluginException , ClassNotFoundException , InstantiationException , IllegalAccessException {
5174 loadPlugin (new File (path ));
5275 }
5376
77+ /**
78+ * перезагрузить плагин
79+ * @param plugin
80+ * @throws NullPointerException
81+ * @throws ClassNotFoundException
82+ * @throws InstantiationException
83+ * @throws IllegalAccessException
84+ * @throws IOException
85+ * @throws InvalidPluginException
86+ */
5487 public void reloadPlugin (PluginListener plugin ) throws NullPointerException , ClassNotFoundException , InstantiationException , IllegalAccessException , IOException , InvalidPluginException {
5588 File path = new File (plugin .getClass ().getProtectionDomain ().getCodeSource ().getLocation ().getPath ());
5689 unloadPlugin (plugin );
5790 loadPlugin (path );
5891 }
5992
93+ /**
94+ * перезагрузить плагин
95+ * @param name
96+ * @throws NullPointerException
97+ * @throws ClassNotFoundException
98+ * @throws InstantiationException
99+ * @throws IllegalAccessException
100+ * @throws IOException
101+ * @throws InvalidPluginException
102+ */
60103 public void reloadPlugin (String name ) throws NullPointerException , ClassNotFoundException , InstantiationException , IllegalAccessException , IOException , InvalidPluginException {
61104 reloadPlugin (map .get (name ));
62105 }
63106
107+ /**
108+ * выгрузить плагин
109+ * @param plugin
110+ */
64111 public void unloadPlugin (PluginListener plugin ) {
65112 plugin .onUnload ();
66113 for (PluginListener p : map .values ()) p .onUnloadPlugin (plugin );
@@ -69,50 +116,105 @@ public void unloadPlugin(PluginListener plugin) {
69116 if (STANDALONE ) Main .LOGGER .warning (plugin .getName () + " unloaded" );
70117 }
71118
119+ /**
120+ * выгрузить плагин
121+ * @param name
122+ */
72123 public void unloadPlugin (String name ) {
73124 unloadPlugin (map .get (name ));
74125 }
75126
127+ /**
128+ * проверка плагина на валидность
129+ * @param path
130+ * @return
131+ */
76132 public boolean isValidPlugin (File path ) {
77- return true ;
133+ return true ; //будет написано позже
78134 }
79135
136+ /**
137+ * проверка плагина на валидность
138+ * @param path
139+ * @return
140+ */
80141 public boolean isValidPlugin (String path ) {
81142 return isValidPlugin (new File (path ));
82143 }
83144
145+ /**
146+ * проверка, загружен ли плагин
147+ * @param plugin
148+ * @return true если да
149+ */
84150 public boolean hasPlugin (PluginListener plugin ) {
85151 return map .containsValue (plugin );
86152 }
87153
154+ /**
155+ * проверка, загружен ли плагин
156+ * @param name
157+ * @return true если да
158+ */
88159 public boolean hasPlugin (String name ) {
89160 return map .containsKey (name );
90161 }
91162
163+ /**
164+ * получить плагин по названию
165+ * @param name
166+ * @return
167+ */
92168 public PluginListener getPluginFromName (String name ) {
93169 return map .get (name );
94170 }
95171
172+ /**
173+ * получить все плагины
174+ * @return
175+ */
96176 public Collection <PluginListener > getPlugins () {
97177 return map .values ();
98178 }
99179
180+ /**
181+ * проверка, есть ли загруженные плагины
182+ * @return true если да
183+ */
100184 public boolean isEmpty () {
101185 return map .isEmpty ();
102186 }
103187
188+ /**
189+ * количество загруженных плагинов
190+ * @return
191+ */
104192 public int size () {
105193 return map .size ();
106194 }
107195
196+ /**
197+ * получить директорию с плагинами
198+ * @return
199+ */
108200 public static File getPluginsFolder () {
109201 return new File ('.' + File .separatorChar + "plugins" );
110202 }
111203
204+ /**
205+ * получить JAR-файл библиотеки
206+ * @return
207+ */
112208 public File getJarPath () {
113209 return new File (this .getClass ().getProtectionDomain ().getCodeSource ().getLocation ().getPath ());
114210 }
115211
212+ /**
213+ * отправить команду
214+ * @param message команда
215+ * @param args аргументы
216+ * @return вывод пользователю
217+ */
116218 public String sendCommand (String message , String [] args ) {
117219 return map .get (cmdsMap .get (message )).onCommand (message , args );
118220 }
0 commit comments