File tree Expand file tree Collapse file tree 4 files changed +65
-19
lines changed
src/main/java/org/hydev/mcpm/client Expand file tree Collapse file tree 4 files changed +65
-19
lines changed Original file line number Diff line number Diff line change 11
11
import org .hydev .mcpm .client .database .export .ExportInteractor ;
12
12
import org .hydev .mcpm .client .database .fetcher .LocalDatabaseFetcher ;
13
13
import org .hydev .mcpm .client .database .searchusecase .SearchInteractor ;
14
+ import org .hydev .mcpm .client .injector .LocalJarFinder ;
14
15
import org .hydev .mcpm .client .injector .PluginLoader ;
15
16
import org .hydev .mcpm .client .installer .InstallInteractor ;
16
17
import org .hydev .mcpm .client .installer .SpigotPluginDownloader ;
@@ -78,7 +79,8 @@ public static List<CommandParser> baseParsers(boolean isMinecraft) {
78
79
* @return Returns a list of argument parsers that require the Server (Minecraft Bukkit Plugin) environment.
79
80
*/
80
81
public static List <CommandParser > serverParsers () {
81
- var loader = new PluginLoader ();
82
+ var jarFinder = new LocalJarFinder ();
83
+ var loader = new PluginLoader (jarFinder );
82
84
83
85
var loadController = new LoadController (loader );
84
86
var reloadController = new ReloadController (loader );
Original file line number Diff line number Diff line change
1
+ package org .hydev .mcpm .client .injector ;
2
+
3
+ import java .io .File ;
4
+
5
+ /**
6
+ * Boundary for finding local jar files
7
+ *
8
+ * @author Azalea (https://github.com/hykilpikonna)
9
+ * @since 2022-11-27
10
+ */
11
+ public interface LocalJarBoundary
12
+ {
13
+ /**
14
+ * Find a jar file of a plugin in file system by name
15
+ *
16
+ * @param name Plugin name in meta
17
+ * @return Plugin jar file
18
+ */
19
+ File findJar (String name ) throws PluginNotFoundException ;
20
+ }
Original file line number Diff line number Diff line change
1
+ package org .hydev .mcpm .client .injector ;
2
+
3
+ import org .hydev .mcpm .client .models .PluginYml ;
4
+ import org .hydev .mcpm .utils .PluginJarFile ;
5
+
6
+ import java .io .File ;
7
+ import java .io .IOException ;
8
+ import java .util .Arrays ;
9
+ import java .util .Optional ;
10
+
11
+ /**
12
+ * Implementation that finds locally installed jars by name
13
+ *
14
+ * @param dir Plugins directory (default to "./plugins")
15
+ * @author Azalea (https://github.com/hykilpikonna)
16
+ * @since 2022-11-27
17
+ */
18
+ public record LocalJarFinder (File dir ) implements LocalJarBoundary
19
+ {
20
+ public LocalJarFinder ()
21
+ {
22
+ this (new File ("plugins" ));
23
+ }
24
+
25
+ @ Override
26
+ public File findJar (String name ) throws PluginNotFoundException
27
+ {
28
+ // 1. Find plugin file by name
29
+ if (!dir .isDirectory ()) throw new PluginNotFoundException (name );
30
+ return Arrays .stream (Optional .ofNullable (dir .listFiles ()).orElseThrow (() -> new PluginNotFoundException (name )))
31
+ .filter (f -> f .getName ().endsWith (".jar" ))
32
+ .filter (f -> {
33
+ try (var jf = new PluginJarFile (f ))
34
+ {
35
+ return jf .readPluginYaml ().name ().equalsIgnoreCase (name );
36
+ }
37
+ catch (IOException | PluginYml .InvalidPluginMetaStructure ignored ) { return false ; }
38
+ }).findFirst ().orElseThrow (() -> new PluginNotFoundException (name ));
39
+ }
40
+ }
Original file line number Diff line number Diff line change 10
10
import org .bukkit .plugin .InvalidPluginException ;
11
11
import org .bukkit .plugin .Plugin ;
12
12
import org .bukkit .plugin .RegisteredListener ;
13
- import org .hydev .mcpm .client .models .PluginYml ;
14
- import org .hydev .mcpm .utils .PluginJarFile ;
15
13
16
14
import java .io .File ;
17
15
import java .io .IOException ;
30
28
* @author Azalea (https://github.com/hykilpikonna)
31
29
* @since 2022-09-27
32
30
*/
33
- public class PluginLoader implements LoadBoundary , UnloadBoundary , ReloadBoundary
31
+ public record PluginLoader ( LocalJarFinder jarFinder ) implements LoadBoundary , UnloadBoundary , ReloadBoundary
34
32
{
35
33
@ Override
36
34
public boolean loadPlugin (String name ) throws PluginNotFoundException
37
35
{
38
- // 1. Find plugin file by name
39
- var dir = new File ("plugins" );
40
- if (!dir .isDirectory ()) throw new PluginNotFoundException (name );
41
- var file = Arrays .stream (Optional .ofNullable (dir .listFiles ())
42
- .orElseThrow (() -> new PluginNotFoundException (name )))
43
- .filter (f -> f .getName ().endsWith (".jar" ))
44
- .filter (f -> {
45
- try (var jf = new PluginJarFile (f ))
46
- {
47
- return jf .readPluginYaml ().name ().equalsIgnoreCase (name );
48
- }
49
- catch (IOException | PluginYml .InvalidPluginMetaStructure ignored ) { return false ; }
50
- }).findFirst ().orElseThrow (() -> new PluginNotFoundException (name ));
51
-
52
- return loadPlugin (file );
36
+ return loadPlugin (jarFinder .findJar (name ));
53
37
}
54
38
55
39
@ Override
You can’t perform that action at this time.
0 commit comments