Skip to content

Commit 79f8fc5

Browse files
committed
Merge branch 'main' into ListAllInteractorUpdate
2 parents b5acd47 + aaef6f4 commit 79f8fc5

File tree

118 files changed

+4120
-683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+4120
-683
lines changed

src/main/java/org/hydev/mcpm/SpigotEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.bukkit.command.CommandSender;
77
import org.bukkit.plugin.java.JavaPlugin;
88
import org.hydev.mcpm.client.arguments.ArgsParser;
9-
import org.hydev.mcpm.client.arguments.CommandsFactory;
9+
import org.hydev.mcpm.client.arguments.ArgsParserFactory;
1010
import org.hydev.mcpm.client.arguments.parsers.CommandParser;
1111
import org.hydev.mcpm.utils.ColorLogger;
1212
import org.jetbrains.annotations.NotNull;
@@ -48,7 +48,7 @@ public void onEnable()
4848
log.info("Enabled!");
4949

5050
// Initialize controller
51-
parser = CommandsFactory.serverArgsParser();
51+
parser = ArgsParserFactory.serverArgsParser();
5252

5353
// Register mcpm command
5454
requireNonNull(this.getCommand("mcpm")).setExecutor(this);

src/main/java/org/hydev/mcpm/client/DatabaseManager.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/main/java/org/hydev/mcpm/client/Downloader.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ public class Downloader
3333
* @param url Remote file URL
3434
* @param to Local file path
3535
*/
36-
public void downloadFile(String url, File to)
36+
public void downloadFile(String url, String to)
3737
{
3838
try (var client = HttpClients.createDefault())
3939
{
40+
File fos = new File(to);
4041
var get = new HttpGet(url);
4142
var bytes = client.execute(get, (req) ->
4243
{
@@ -45,7 +46,7 @@ public void downloadFile(String url, File to)
4546
var builder = new ByteArrayOutputStream((int) total);
4647

4748
// Create progress row
48-
var row = new ProgressRow(total).desc(to.getName()).descLen(30);
49+
var row = new ProgressRow(total).desc(fos.getName()).descLen(30);
4950
bar.appendBar(row);
5051

5152
try (var stream = entity.getContent())
@@ -63,8 +64,12 @@ public void downloadFile(String url, File to)
6364

6465
return builder.toByteArray();
6566
});
66-
67-
Files.write(to.toPath(), bytes);
67+
try {
68+
Files.write(fos.toPath(), bytes);
69+
}
70+
catch (RuntimeException e) {
71+
throw new RuntimeException(e);
72+
}
6873
}
6974
catch (IOException e)
7075
{
@@ -79,7 +84,7 @@ public void downloadFile(String url, File to)
7984
*
8085
* @param urls Mapping of remote urls to local file paths
8186
*/
82-
public void downloadFiles(Map<String, File> urls)
87+
public void downloadFiles(Map<String, String> urls)
8388
{
8489
try (ExecutorService executor = Executors.newFixedThreadPool(threads))
8590
{
@@ -91,7 +96,7 @@ public void downloadFiles(Map<String, File> urls)
9196
{
9297
executor.submit(() ->
9398
{
94-
File to = urls.get(url);
99+
String to = urls.get(url);
95100
downloadFile(url, to);
96101
});
97102
}
@@ -128,26 +133,34 @@ public static void main(String[] args)
128133
{
129134
// Remember to chang link to test
130135
String link = "https://sd.blackball.lv/library/Introduction_to_Algorithms_Third_Edition_(2009).pdf";
131-
File out = new File("./Introduction_to_Algorithms_Third_Edition.pdf");
136+
String out = "./Introduction_to_Algorithms_Third_Edition.pdf";
132137
String link1 = "https://www.iusb.edu/students/academic-success-programs/academic-centers-for-excellence/docs/Basic%20Math%20Review%20Card.pdf";
133-
File out1 = new File("./Math.pdf");
138+
String out1 = "./Math.pdf";
134139
String link2 = "https://ouopentextbooks.org/mathematics/files/2015/07/1503.pdf";
135-
File out2 = new File("./1503");
140+
String out2 = "./1503";
136141
String link3 = "https://faculty.math.illinois.edu/~aydin/math220/lecturenotes/m220_Sec1_4.pdf";
137-
File out3 = new File("./m220_Sec1_4");
142+
String out3 = "./m220_Sec1_4";
138143
String link4 = "https://ocw.mit.edu/ans7870/9/9.00SC/MIT9_00SCF11_text.pdf";
139-
File out4 = new File("./MIT9_00SCF11_text");
144+
String out4 = "./MIT9_00SCF11_text";
140145

141146
final var downloader = new Downloader();
142147

143-
Map<String, File> urls = new HashMap<>();
148+
Map<String, String> urls = new HashMap<>();
144149
urls.put(link, out);
145150
urls.put(link1, out1);
146151
urls.put(link2, out2);
147152
urls.put(link3, out3);
148153
urls.put(link4, out4);
149154
downloader.downloadFiles(urls);
150-
out.delete();
151-
out1.delete();
155+
File outFile = new File(out);
156+
outFile.delete();
157+
File outFile1 = new File(out1);
158+
outFile1.delete();
159+
File outFile2 = new File(out2);
160+
outFile2.delete();
161+
File outFile3 = new File(out3);
162+
outFile3.delete();
163+
File outFile4 = new File(out4);
164+
outFile4.delete();
152165
}
153166
}

src/main/java/org/hydev/mcpm/client/arguments/ArgsParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public List<CommandParser> getRawSubparsers() {
116116
* @param args Arguments are ignored.
117117
*/
118118
public static void main(String[] args) {
119-
var parser = CommandsFactory.baseArgsParser();
119+
var parser = ArgsParserFactory.baseArgsParser();
120120

121121
try {
122122
parser.parse(args, ColorLogger.toStdOut());
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.hydev.mcpm.client.arguments;
2+
3+
/**
4+
* Class that produces default implementations of the Controller and ArgsParser classes.
5+
* These classes are used to handle commands.
6+
* Checkout Command.java for a process on adding a new command!
7+
*/
8+
public class ArgsParserFactory {
9+
// No instantiation.
10+
private ArgsParserFactory() { }
11+
12+
/**
13+
* Creates an ArgsParser object that has general parsers (works in any environment).
14+
*
15+
* @return An ArgsParser object. Invoke ArgsParser#parse to see more.
16+
*/
17+
public static ArgsParser baseArgsParser() {
18+
var interactors = new InteractorFactory(false);
19+
var controllers = new ControllerFactory(interactors);
20+
21+
return new ArgsParser(ParserFactory.baseParsers(controllers));
22+
}
23+
24+
/**
25+
* Creates an ArgsParser object that has all (CLI & Server) parsers.
26+
*
27+
* @return An ArgsParser object. Invoke ArgsParser#parse to see more.
28+
*/
29+
public static ArgsParser serverArgsParser() {
30+
var interactors = new InteractorFactory(true);
31+
var controllers = new ControllerFactory(interactors);
32+
33+
return new ArgsParser(ParserFactory.serverParsers(controllers));
34+
}
35+
}

0 commit comments

Comments
 (0)