mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-09-30 04:59:05 +02:00
fix alphabetical sorting and reformat/cleanup
This commit is contained in:
parent
3b0df41008
commit
b1ab51a932
5 changed files with 306 additions and 297 deletions
|
@ -43,6 +43,7 @@ public class Commands {
|
|||
|
||||
/**
|
||||
* Adds a mod to the modpack
|
||||
*
|
||||
* @param modlink Can be a link to a curseforge file or to a file download
|
||||
*/
|
||||
public static void addMod(String[] modlink) {
|
||||
|
@ -96,10 +97,10 @@ public class Commands {
|
|||
} catch(CurseException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
System.out.println("Link Must match " + regex);
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
System.out.println("Syntax: addmod <curseforge url>");
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +128,7 @@ public class Commands {
|
|||
|
||||
/**
|
||||
* Builds the modpack as a server
|
||||
*
|
||||
* @param dir The directory where to create the server
|
||||
*/
|
||||
public static void buildServer(String[] dir) {
|
||||
|
@ -135,6 +137,7 @@ public class Commands {
|
|||
|
||||
/**
|
||||
* Downloads all mods in this pack
|
||||
*
|
||||
* @param dir The mods directory
|
||||
*/
|
||||
public static void downloadMods(String[] dir) {
|
||||
|
@ -143,6 +146,7 @@ public class Commands {
|
|||
|
||||
/**
|
||||
* Creates a modlist of this pack
|
||||
*
|
||||
* @param format 1 Can be html or csv, 2 can be any valid file to write to
|
||||
*/
|
||||
public static void createModlist(String[] format) {
|
||||
|
@ -154,13 +158,11 @@ public class Commands {
|
|||
return;
|
||||
}
|
||||
System.out.println("Printing CSV into " + csvFile);
|
||||
Appendable out;
|
||||
CSVFormat format1;
|
||||
try(CSVPrinter printer = new CSVPrinter(new FileWriter(csvFile), CSVFormat.EXCEL.withDelimiter(';'))) {
|
||||
printer.printRecord("Name", "Authors", "Link", "Downloads", "ID");
|
||||
printer.println();
|
||||
ArrayList<ModInfo> modlist = ModInfo.getModInfo();
|
||||
Collections.sort(modlist, Comparator.comparing(ModInfo :: getName));
|
||||
Collections.sort(modlist, Comparator.comparing(a -> a.getName().toLowerCase()));
|
||||
for(ModInfo mod : modlist) {
|
||||
String name = mod.getName();
|
||||
String[] authorArr = mod.getAuthors();
|
||||
|
@ -177,7 +179,7 @@ public class Commands {
|
|||
|
||||
printer.printRecord(name, authors, link, downloads, id);
|
||||
}
|
||||
}catch(IOException e) {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if(format[1].equalsIgnoreCase("html")) {
|
||||
|
@ -187,7 +189,7 @@ public class Commands {
|
|||
return;
|
||||
}
|
||||
ArrayList<ModInfo> mods = ModInfo.getModInfo();
|
||||
Collections.sort(mods, Comparator.comparing(ModInfo :: getName));
|
||||
Collections.sort(mods, Comparator.comparing(a -> a.getName().toLowerCase()));
|
||||
ContainerTag table = body(
|
||||
TagCreator.table(TagCreator.attrs("#mods"), TagCreator.tbody(
|
||||
tr(td(b("Name")),
|
||||
|
@ -222,10 +224,10 @@ public class Commands {
|
|||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
System.out.println("Expected Either HTML or CSV as format");
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
System.out.println("Syntax: createmodlist <csv/html> <file>");
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +237,7 @@ public class Commands {
|
|||
|
||||
/**
|
||||
* Creates a server from a modpack zip file
|
||||
*
|
||||
* @param args The path to the zip file, The directory where to create the server
|
||||
*/
|
||||
public static void makeServer(String[] args) {
|
||||
|
@ -242,5 +245,4 @@ public class Commands {
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ public class Config {
|
|||
public final File JAR_LOCATION;
|
||||
public final File CONFIG_LOCATION;
|
||||
public final JsonObject CONFIG;
|
||||
|
||||
public Config() {
|
||||
//Get the Location of the jarfile
|
||||
File JAR_LOCATION1;
|
||||
|
@ -35,13 +36,14 @@ public class Config {
|
|||
|
||||
/**
|
||||
* reads the config it it exists and otherwise copies it
|
||||
*
|
||||
* @return the json object of the config file
|
||||
*/
|
||||
private JsonObject readConfig() {
|
||||
if(CONFIG_LOCATION.exists()) {
|
||||
//parse file to json
|
||||
return Util.readJsonFile(CONFIG_LOCATION);
|
||||
}else {
|
||||
} else {
|
||||
//copy from resources
|
||||
try {
|
||||
InputStream in = ClassLoader.getSystemResourceAsStream(CONFIG_NAME);
|
||||
|
@ -52,9 +54,10 @@ public class Config {
|
|||
in.close();
|
||||
out.close();
|
||||
return readConfig();
|
||||
}catch(IOException e) {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import com.google.gson.JsonParser;
|
|||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Util {
|
||||
/**
|
||||
* Reads a Json File
|
||||
*
|
||||
* @param file the file to read
|
||||
* @return the file content as JsonObject
|
||||
*/
|
||||
|
@ -31,6 +33,7 @@ public class Util {
|
|||
|
||||
/**
|
||||
* sends a http post request
|
||||
*
|
||||
* @param url the url to send the request to
|
||||
* @param contentType what content type should be used. Example: "application/json; utf-8"
|
||||
* @param accept what content is accepted. Example: "application/json"
|
||||
|
@ -46,10 +49,10 @@ public class Util {
|
|||
con.setDoOutput(true);
|
||||
|
||||
OutputStream outs = con.getOutputStream();
|
||||
byte[] input = payload.getBytes("UTF-8");
|
||||
byte[] input = payload.getBytes(StandardCharsets.UTF_8);
|
||||
outs.write(input);
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8));
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String responseLine;
|
||||
while((responseLine = br.readLine()) != null) {
|
||||
|
@ -59,6 +62,7 @@ public class Util {
|
|||
return sb.toString();
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue