Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 0069b85

Browse files
author
hub
committed
asset path fixes
and some other minor crap
1 parent 20f653e commit 0069b85

File tree

8 files changed

+81
-115
lines changed

8 files changed

+81
-115
lines changed

.github/workflows/workflow.yaml

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

src/main/java/com/krazzzzymonkey/catalyst/Main.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
import org.lwjgl.opengl.Display;
2727

2828
import java.awt.*;
29-
import java.io.File;
3029
import java.io.IOException;
3130

32-
import static com.krazzzzymonkey.catalyst.managers.FileManager.CATALYST_DIR;
33-
3431

3532
@Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION, clientSideOnly = true, guiFactory = "com.krazzzzymonkey.catalyst.managers.accountManager.config.GuiFactory", acceptableRemoteVersions = "*")
3633
public class Main {
@@ -50,7 +47,6 @@ public static void syncConfig() {
5047
public static final String VERSION = "@version@";
5148
public static int initCount = 0;
5249
public static ModuleManager moduleManager;
53-
public static FontManager fontManager;
5450

5551
public static CFontRenderer fontRenderer;
5652
public static CFontRenderer smallFontRenderer;
@@ -66,11 +62,8 @@ public static void syncConfig() {
6662
private ConfigurationLoader configLoader;
6763
public static Config config;
6864

69-
70-
public File configFolder;
71-
7265
@EventHandler
73-
public void preInit(FMLPreInitializationEvent E) throws IOException {
66+
public void preInit(FMLPreInitializationEvent E) {
7467

7568

7669
logger.info(" ____ _ _ _ ____ _ _ _ ");
@@ -80,7 +73,6 @@ public void preInit(FMLPreInitializationEvent E) throws IOException {
8073
logger.info(" \\____\\__,_|\\__\\__,_|_|\\__, |___/\\__| \\____|_|_|\\___|_| |_|\\__|");
8174
logger.info(" |___/ ");
8275
Display.setTitle("Initializing " + NAME + " " + VERSION);
83-
configFolder = CATALYST_DIR;
8476
config = new Config();
8577
// Load Transparent
8678

@@ -135,7 +127,7 @@ public void init(FMLInitializationEvent E) throws IOException {
135127

136128
@EventHandler
137129
public void postInit(FMLPostInitializationEvent E){
138-
File file = FileManager.getAssetFile("gui" + File.separator + "watermark.png");
130+
// File file = FileManager.getAssetFile("gui" + File.separator + "watermark.png");
139131

140132
Display.setTitle(NAME + " " + VERSION);
141133

src/main/java/com/krazzzzymonkey/catalyst/command/DebugInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void runCommand(String s, String[] args) {
6363
paste.addContent("options.txt", "options.txt not a file or not readable");
6464
}
6565

66-
File hacksConfig = new File(FileManager.CATALYST_DIR, "hacks.json");
66+
File hacksConfig = FileManager.CATALYST_DIR.resolve("hacks.json").toFile();
6767
if (hacksConfig.isFile() && hacksConfig.canRead()) {
6868
try {
6969
paste.addContent("hacks.json", Files

src/main/java/com/krazzzzymonkey/catalyst/command/Profile.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.krazzzzymonkey.catalyst.utils.ChatColor;
66
import com.krazzzzymonkey.catalyst.utils.visual.ChatUtils;
77

8+
import java.io.File;
89
import java.util.Objects;
910

1011
public class Profile extends Command {
@@ -37,9 +38,11 @@ public void runCommand(String s, String[] args) {
3738
}
3839
} else if (args[0].equalsIgnoreCase("list")) {
3940
ChatUtils.normalMessage("Profile List:");
40-
for (int i = 0; i < Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles()).length; i++) {
41-
if (Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles())[i].isFile()) {
42-
ChatUtils.normalMessage(Objects.requireNonNull(FileManager.PROFILES_DIR.listFiles())[i].getName().replace(".json", ""));
41+
File[] files = FileManager.PROFILES_DIR.toFile().listFiles();
42+
Objects.requireNonNull(files);
43+
for (File file : files) {
44+
if (file.isFile()) {
45+
ChatUtils.normalMessage(file.getName().replace(".json", ""));
4346
}
4447
}
4548
}

src/main/java/com/krazzzzymonkey/catalyst/configuration/ConfigurationLoader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.krazzzzymonkey.catalyst.configuration;
22

3-
import com.google.common.io.ByteStreams;
43
import com.google.gson.JsonElement;
54
import com.google.gson.JsonObject;
65
import com.google.gson.JsonParser;
76
import com.google.gson.stream.JsonReader;
87
import com.krazzzzymonkey.catalyst.gui.GuiCustom;
98
import org.apache.commons.io.FileUtils;
10-
import org.apache.commons.io.IOUtils;
119

12-
import java.io.*;
10+
import java.io.File;
11+
import java.io.FileNotFoundException;
12+
import java.io.FileReader;
13+
import java.io.IOException;
1314

1415
import static com.krazzzzymonkey.catalyst.managers.FileManager.CATALYST_DIR;
1516
import static com.krazzzzymonkey.catalyst.managers.FileManager.getAssetFile;
@@ -24,7 +25,7 @@ public ConfigurationLoader(Config config) {
2425
public void load() throws Exception {
2526
JsonParser jsonParser = new JsonParser();
2627

27-
File configFolder = new File(CATALYST_DIR, "CatalystMainMenu");
28+
File configFolder = CATALYST_DIR.resolve("CatalystMainMenu").toFile();
2829
if (!configFolder.exists()) {
2930
configFolder.mkdir();
3031
}

src/main/java/com/krazzzzymonkey/catalyst/managers/FileManager.java

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,45 @@
1616
import com.krazzzzymonkey.catalyst.value.types.ModeValue;
1717
import com.krazzzzymonkey.catalyst.value.types.SubMenu;
1818
import com.krazzzzymonkey.catalyst.xray.XRayData;
19-
import net.minecraft.client.Minecraft;
2019
import net.minecraft.item.Item;
2120
import org.apache.commons.io.FileUtils;
2221

2322
import javax.annotation.Nonnull;
2423
import javax.annotation.Nullable;
2524
import java.io.*;
25+
import java.nio.file.Path;
2626
import java.util.ArrayList;
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Objects;
3030

3131
public class FileManager {
3232

33-
public static final File CATALYST_DIR = new File(String.format("%s%s%s%s",
34-
Wrapper.INSTANCE.mc().gameDir,
35-
File.separator,
36-
Main.NAME,
37-
File.separator));
38-
public static final File ASSET_DIR = new File(CATALYST_DIR + "/Assets/");
39-
private static final Minecraft mc = Minecraft.getMinecraft();
40-
41-
public static final File ALT_DIR = new File(CATALYST_DIR + "/Catalyst Account Manager/");
42-
public static final File PROFILES_DIR = new File(CATALYST_DIR + "/Profiles/");
43-
private static final File HACKS = new File(PROFILES_DIR, "default.json");
44-
public static final File CLICKGUI = new File(CATALYST_DIR, "clickgui.json");
33+
public static final Path CATALYST_DIR = Wrapper.INSTANCE.mc().gameDir.toPath().resolve(Main.NAME);
34+
public static final Path ASSET_DIR = CATALYST_DIR.resolve("Assets");
35+
public static final Path ALT_DIR = CATALYST_DIR.resolve("Catalyst Account Manager");
36+
public static final Path PROFILES_DIR = CATALYST_DIR.resolve("Profiles");
37+
private static final File HACKS = PROFILES_DIR.resolve("default.json").toFile();
38+
public static final File CLICKGUI = CATALYST_DIR.resolve("clickgui.json").toFile();
4539
private static final Gson gsonPretty = new GsonBuilder().setPrettyPrinting().create();
4640
private static final JsonParser jsonParser = new JsonParser();
47-
private static final File CHATMENTION = new File(CATALYST_DIR, "chatmention.json");
48-
private static final File AUTOGGMESSAGES = new File(CATALYST_DIR, "ggmessages.txt");
49-
private static final File XRAYDATA = new File(CATALYST_DIR, "xraydata.json");
50-
private static final File FRIENDS = new File(CATALYST_DIR, "friends.json");
51-
private static final File ENEMYS = new File(CATALYST_DIR, "enemys.json");
52-
private static final File PREFIX = new File(CATALYST_DIR, "prefix.json");
53-
private static final File CURRENTPROFILE = new File(CATALYST_DIR, "currentprofile.json");
54-
private static final File FONT = new File(CATALYST_DIR, "font.json");
55-
private static final File INVENTORY_CLEANER = new File(CATALYST_DIR, "inventorycleaner.json");
41+
private static final File CHATMENTION = CATALYST_DIR.resolve("chatmention.json").toFile();
42+
private static final File AUTOGGMESSAGES = CATALYST_DIR.resolve("ggmessages.txt").toFile();
43+
private static final File XRAYDATA = CATALYST_DIR.resolve("xraydata.json").toFile();
44+
private static final File FRIENDS = CATALYST_DIR.resolve("friends.json").toFile();
45+
private static final File ENEMYS = CATALYST_DIR.resolve("enemys.json").toFile();
46+
private static final File PREFIX = CATALYST_DIR.resolve("prefix.json").toFile();
47+
private static final File CURRENTPROFILE = CATALYST_DIR.resolve("currentprofile.json").toFile();
48+
private static final File FONT = CATALYST_DIR.resolve("font.json").toFile();
49+
private static final File INVENTORY_CLEANER = CATALYST_DIR.resolve("inventorycleaner.json").toFile();
5650

5751
public static @Nullable File getAssetFile(@Nonnull String path) {
52+
Main.logger.info("Requesting asset: " + path);
5853
File file = new File(ASSET_DIR + File.separator + path);
54+
Main.logger.info("Loading asset file: " + file.getPath());
5955
if (file.exists()) return file;
6056
try {
61-
Main.logger.info("Creating asset from default resource: " + path);
57+
Main.logger.info("Asset not found locally, creating from default resource: " + path);
6258
file.getParentFile().mkdirs();
6359
FileUtils.copyInputStreamToFile(resourceAsStream(path), file);
6460
} catch (IOException | SecurityException e) {
@@ -78,9 +74,8 @@ private static void loadInventoryCleaner() {
7874
loadJson = new BufferedReader(new FileReader(INVENTORY_CLEANER));
7975
JsonObject jsonObject = (JsonObject) jsonParser.parse(loadJson);
8076
loadJson.close();
81-
jsonObject.get("items").getAsJsonArray().iterator().forEachRemaining(n -> {
82-
InventoryCleaner.listItems.add(Item.getByNameOrId(n.getAsString()));
83-
});
77+
jsonObject.get("items").getAsJsonArray().iterator().forEachRemaining(n -> InventoryCleaner.listItems.add(
78+
Item.getByNameOrId(n.getAsString())));
8479
} catch (Exception e) {
8580
e.printStackTrace();
8681
}
@@ -167,7 +162,7 @@ public static void saveFont() {
167162
}
168163

169164
public static void loadPrefix() {
170-
BufferedReader loadJson = null;
165+
BufferedReader loadJson;
171166
try {
172167
loadJson = new BufferedReader(new FileReader(PREFIX));
173168
JsonObject moduleJason = (JsonObject) jsonParser.parse(loadJson);
@@ -200,8 +195,8 @@ public static void loadModules(String profile) {
200195
try {
201196
BufferedReader loadJson = new BufferedReader(new FileReader(HACKS));
202197
if (!profile.equals("")) {
203-
if (new File(PROFILES_DIR, profile + ".json").exists()) {
204-
loadJson = new BufferedReader(new FileReader(new File(PROFILES_DIR, profile + ".json")));
198+
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
199+
loadJson = new BufferedReader(new FileReader(PROFILES_DIR.resolve(profile + ".json").toFile()));
205200
}
206201
}
207202

@@ -366,7 +361,7 @@ public static void loadModules(String profile) {
366361

367362
} catch (NullPointerException e) {
368363
Main.logger.warn("Unknown Config for: " + mods.getModuleName() + ". Setting Default config!");
369-
if (new File(PROFILES_DIR, profile + ".json").exists()) {
364+
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
370365
saveModules(profile);
371366
} else saveModules("default");
372367

@@ -375,7 +370,7 @@ public static void loadModules(String profile) {
375370
}
376371
mods.setKey(jsonMod.get("bind").getAsJsonObject().get("key").getAsInt());
377372
mods.setBindHold(jsonMod.get("bind").getAsJsonObject().get("held").getAsBoolean());
378-
if (new File(PROFILES_DIR, profile + ".json").exists()) {
373+
if (PROFILES_DIR.resolve(profile + ".json").toFile().exists()) {
379374
ProfileManager.currentProfile = profile;
380375
} else ProfileManager.currentProfile = "default";
381376
}
@@ -618,7 +613,7 @@ public static void saveModules(String profile) {
618613
}
619614
json.add(module.getModuleName(), jsonHack);
620615
}
621-
PrintWriter saveJson = new PrintWriter(new FileWriter(new File(PROFILES_DIR, profile + ".json")));
616+
PrintWriter saveJson = new PrintWriter(new FileWriter(PROFILES_DIR.resolve(profile + ".json").toFile()));
622617

623618
saveJson.println(gsonPretty.toJson(json));
624619
saveJson.close();
@@ -643,13 +638,14 @@ public static void write(File outputFile, List<String> writeContent, boolean new
643638
if (writer != null) {
644639
writer.close();
645640
}
646-
} catch (Exception ex2) {
641+
} catch (Exception e) {
642+
e.printStackTrace();
647643
}
648644
}
649645
}
650646

651647
public static List<String> read(File inputFile) {
652-
ArrayList<String> readContent = new ArrayList<String>();
648+
ArrayList<String> readContent = new ArrayList<>();
653649
BufferedReader reader = null;
654650
try {
655651
reader = new BufferedReader(new FileReader(inputFile));
@@ -662,7 +658,8 @@ public static List<String> read(File inputFile) {
662658
if (reader != null) {
663659
reader.close();
664660
}
665-
} catch (Exception ex2) {
661+
} catch (Exception e) {
662+
e.printStackTrace();
666663
}
667664
}
668665
return readContent;
@@ -673,21 +670,21 @@ public static void init() {
673670
}
674671

675672
public static void reload() {
676-
if (!CATALYST_DIR.exists()) {
677-
CATALYST_DIR.mkdir();
673+
if (!CATALYST_DIR.toFile().exists()) {
674+
CATALYST_DIR.toFile().mkdir();
678675
}
679-
if (!ALT_DIR.exists()) {
680-
ALT_DIR.mkdir();
676+
if (!ALT_DIR.toFile().exists()) {
677+
ALT_DIR.toFile().mkdir();
681678
}
682-
if (!PROFILES_DIR.exists()) {
683-
PROFILES_DIR.mkdir();
679+
if (!PROFILES_DIR.toFile().exists()) {
680+
PROFILES_DIR.toFile().mkdir();
684681
}
685682
if (!CURRENTPROFILE.exists()) {
686683
saveCurrentProfile();
687684
} else {
688685
loadCurrentProfile();
689686
}
690-
if (!(new File(PROFILES_DIR, ProfileManager.currentProfile + ".json").exists())) {
687+
if (!(PROFILES_DIR.resolve(ProfileManager.currentProfile + ".json").toFile().exists())) {
691688
Main.logger.warn("Profile: " + ProfileManager.currentProfile + " does not exist! Setting default Profile");
692689
ProfileManager.currentProfile = "default";
693690
saveModules(ProfileManager.currentProfile);

0 commit comments

Comments
 (0)