|
4 | 4 | import java.io.FileWriter; |
5 | 5 | import java.io.IOException; |
6 | 6 | import java.nio.file.Files; |
7 | | -import java.nio.file.Paths; |
8 | 7 | import java.util.List; |
9 | 8 | import java.util.Map; |
10 | 9 | import java.util.logging.Logger; |
11 | 10 |
|
12 | 11 | import com.google.gson.Gson; |
13 | 12 |
|
14 | | -import codekey.level.CSVParser; |
| 13 | +import codekey.level.JSONParser; |
15 | 14 | import codekey.level.Player; |
16 | 15 | import codekey.main.commands.CommandStatus; |
| 16 | +import io.discloader.discloader.client.command.CommandHelp; |
17 | 17 | import io.discloader.discloader.client.logger.DLLogger; |
18 | 18 | import io.discloader.discloader.common.DLOptions; |
19 | 19 | import io.discloader.discloader.common.DiscLoader; |
|
26 | 26 | public class Main { |
27 | 27 |
|
28 | 28 | public static String token; |
29 | | - public static final String DATABASE = "data.csv"; |
30 | | - public static final String DATABASE_BACKUP = "data_backup.csv"; |
| 29 | + public static final String DATABASE = "players.json"; |
| 30 | + public static final String DATABASE_BACKUP = "players_backup.json"; |
31 | 31 | // To avoid uploading my token to github, I am going to read it from a file. |
32 | | - private static final String TOKEN_FILE = "token.txt"; |
33 | | - // data.csv contains the database. |
| 32 | + private static final String CONFIG_FILE = "options.json"; |
| 33 | + // players.json contains the database. |
34 | 34 | public static Map<Long, Player> players; |
35 | 35 | public static DiscLoader loader; |
36 | 36 |
|
37 | 37 | public static final String PREFIX = "~"; |
38 | 38 |
|
39 | | - |
40 | 39 | public static final Logger logger = new DLLogger("Codekey").getLogger(); |
41 | 40 |
|
42 | | - public static Config config; // because having to change the PREFIX string every time I upload a new build it annoying |
43 | | - |
| 41 | + public static Config config; // because having to change the PREFIX string every time I upload a new build it |
| 42 | + // annoying |
| 43 | + |
44 | 44 | public static void main(String[] args) throws Exception { |
45 | 45 | try { |
46 | 46 | readConfig(); |
47 | 47 | } catch (IOException e) { |
48 | 48 | e.printStackTrace(); |
49 | 49 | logger.severe("Failed to load the config file."); |
| 50 | + System.exit(1); |
50 | 51 | } |
51 | | - new CSVParser(DATABASE); |
| 52 | + new JSONParser(DATABASE); |
52 | 53 | // DLOptions options = new DLOptions(token); |
53 | | - loader = new DiscLoader(new DLOptions(config.auth.token, config.prefix)).addEventListener(new Listener()).login().get(); |
| 54 | + loader = new DiscLoader(new DLOptions(config.auth.token, config.prefix, false)).addEventListener(new Listener()).login().get(); |
54 | 55 | CommandRegistry.registerCommand(new CommandStatus(), "status"); |
| 56 | + CommandRegistry.registerCommand(new CommandHelp(), "help"); |
55 | 57 | // JDA jda = new |
56 | 58 | // JDABuilder(AccountType.BOT).setToken(token).addEventListener(new |
57 | 59 | // Listener()).buildBlocking(); |
58 | | - new CSVThread().start(); |
| 60 | + new JSONThread().start(); |
59 | 61 | // new SpamThread().start(); |
60 | 62 | } |
61 | 63 |
|
62 | | -// // This is probably the best way... |
63 | | -// private static void readToken() throws IOException { |
64 | | -// BufferedReader reader = new BufferedReader(new FileReader(TOKEN_FILE)); |
65 | | -// token = reader.readLine(); |
66 | | -// reader.close(); |
67 | | -// } |
68 | | - |
| 64 | + /** |
| 65 | + * Reads the config file from disk |
| 66 | + * |
| 67 | + * @throws IOException |
| 68 | + */ |
69 | 69 | private static void readConfig() throws IOException { |
70 | 70 | Gson gson = new Gson(); |
71 | | - File options = new File("options.json"); |
| 71 | + File options = new File(CONFIG_FILE); |
72 | 72 | if (options.exists() && !options.isDirectory()) { |
73 | | - String content = ""; |
74 | | - List<String> lines = Files.readAllLines(Paths.get("./options.json")); |
| 73 | + String content = ""; // something to concatenate the lines into |
| 74 | + List<String> lines = Files.readAllLines(options.toPath()); // pretty self explanatory |
75 | 75 | for (String line : lines) |
76 | 76 | content += line; |
77 | 77 | config = gson.fromJson(content, Config.class); |
|
0 commit comments