aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java63
4 files changed, 35 insertions, 35 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 1b90f6b..3b80a47 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -2,8 +2,6 @@ package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.config.core.ConfigCore;
-import io.polyfrost.oneconfig.config.profiles.Profiles;
import io.polyfrost.oneconfig.test.TestConfig;
import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
index de9bf92..12c15a2 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
@@ -6,7 +6,6 @@ import io.polyfrost.oneconfig.config.interfaces.Config;
import java.io.*;
import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
public class OneConfigConfig extends Config {
public OneConfigConfig() {
@@ -39,6 +38,5 @@ public class OneConfigConfig extends Config {
}
}
- public static HashMap<String, String> profiles = new HashMap<>();
public static String currentProfile;
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index 73696a5..4cd6fdf 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -136,8 +136,7 @@ public class Config {
Object object = adapter.fromJsonTree(value);
field.setAccessible(true);
field.set(null, object);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- e.printStackTrace();
+ } catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
index 0ad7620..8c2f695 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
@@ -7,39 +7,48 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Arrays;
public class Profiles {
- public static Map.Entry<String, String> getCurrentProfile() {
- if (OneConfigConfig.currentProfile == null) {
- OneConfigConfig.currentProfile = createProfile("Default Profile").getKey();
- OneConfig.config.save();
- }
- return getProfile(OneConfigConfig.currentProfile);
- }
+ private static ArrayList<String> profiles;
+ private static final File profileDir = new File("OneConfig/profiles");
- public static Map.Entry<String, String> createProfile(String name) {
- File profileDir = new File("OneConfig/profiles");
+ public static String getCurrentProfile() {
if (!profileDir.exists() && !profileDir.mkdir()) {
System.out.println("Could not create profiles folder");
return null;
}
+ if (profiles == null) {
+ String[] profilesArray = new File("OneConfig/profiles").list((file, s) -> file.isDirectory());
+ if (profilesArray != null)
+ profiles = new ArrayList<>(Arrays.asList(profilesArray));
+ }
+ if (!getProfileDir(OneConfigConfig.currentProfile).exists()) {
+ createProfile(OneConfigConfig.currentProfile);
+ }
+ return OneConfigConfig.currentProfile;
+ }
+
+ public static void createProfile(String name) {
File folder = new File(profileDir, name);
if (!folder.exists() && !folder.mkdir()) {
System.out.println("Could not create profile folder");
- return null;
+ return;
}
- OneConfigConfig.profiles.put(name, folder.getAbsolutePath());
- OneConfig.config.save();
- return getProfile(name);
+ profiles.add(name);
+ }
+
+ public static File getProfileDir() {
+ return getProfileDir(getCurrentProfile());
}
- public static Map.Entry<String, String> getProfile(String name) {
- return OneConfigConfig.profiles.entrySet().stream().filter(entry -> entry.getKey().equals(name)).findFirst().get();
+ public static File getProfileDir(String profile) {
+ return new File(new File("OneConfig/profiles"), profile);
}
public static File getProfileFile(String file) {
- return new File(new File(getCurrentProfile().getValue()), file);
+ return new File(getProfileDir(), file);
}
public static void loadProfile(String profile) {
@@ -51,32 +60,28 @@ public class Profiles {
public static void renameProfile(String name, String newName) {
try {
- Map.Entry<String, String> profile = getProfile(name);
File newFile = new File(new File("OneConfig/profiles"), newName);
- FileUtils.moveDirectory(new File(profile.getValue()), newFile);
+ FileUtils.moveDirectory(getProfileDir(name), newFile);
if (OneConfigConfig.currentProfile.equals(name))
OneConfigConfig.currentProfile = newName;
- OneConfigConfig.profiles.remove(name);
- OneConfigConfig.profiles.put(newName, newFile.getAbsolutePath());
- OneConfig.config.save();
+ profiles.remove(name);
+ profiles.add(newName);
} catch (IOException e) {
System.out.println("Failed to rename profile");
}
}
public static void deleteProfile(String name) {
- Map.Entry<String, String> profile = getProfile(name);
- if (profile.equals(getCurrentProfile())) {
- if (OneConfigConfig.profiles.size() == 1) {
+ if (name.equals(getCurrentProfile())) {
+ if (profiles.size() == 1) {
System.out.println("Cannot delete only profile!");
return;
}
- loadProfile(OneConfigConfig.profiles.entrySet().stream().filter(entry -> !entry.getKey().equals(name)).findFirst().get().getKey());
+ loadProfile(profiles.stream().filter(entry -> !entry.equals(name)).findFirst().get());
}
try {
- FileUtils.deleteDirectory(new File(profile.getValue()));
- OneConfigConfig.profiles.remove(name);
- OneConfig.config.save();
+ FileUtils.deleteDirectory(getProfileDir(name));
+ profiles.remove(name);
} catch (IOException e) {
System.out.println("Failed to delete profile");
}