Skip to content

Commit

Permalink
3.2.0 update, fixes multi-config system
Browse files Browse the repository at this point in the history
  • Loading branch information
uoil committed Dec 5, 2022
1 parent 62a3c1f commit 31ba59f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'

apply plugin: "com.github.johnrengelman.shadow"

version = "3.1.8"
version = "3.2.0"
group = "me.rigamortis"
archivesBaseName = "seppuku"
def buildmode = "IDE"
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/rigamortis/seppuku/Seppuku.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class Seppuku {
public void init() {
this.eventManager = new AnnotatedEventManager();
this.apiManager = new APIManager();
this.configManager = new ConfigManager("Default");
this.configManager = new ConfigManager();
this.ignoredManager = new IgnoredManager();
this.friendManager = new FriendManager();
this.rotationManager = new RotationManager();
Expand Down Expand Up @@ -203,7 +203,7 @@ public void reload() {
this.capeManager = new CapeManager();

this.configManager.getConfigurableList().clear();
this.configManager = new ConfigManager(this.configManager.activeConfig);
this.configManager = new ConfigManager();
this.configManager.init();

this.getEventManager().dispatchEvent(new EventReload());
Expand Down Expand Up @@ -266,7 +266,7 @@ public FriendManager getFriendManager() {

public ConfigManager getConfigManager() {
if (this.configManager == null) {
this.configManager = new ConfigManager("Default");
this.configManager = new ConfigManager();
}
return this.configManager;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/rigamortis/seppuku/impl/fml/SeppukuMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

/**
* @author Seth
* @author Seth/riga
* @author noil
* @author the entire github & discordcommunity
* @author GitHub's contributors & our Discord plugin developers
*/
@Mod(modid = "seppukumod", name = "Seppuku", version = SeppukuMod.VERSION, certificateFingerprint = "7979b1d0446af2675fcb5e888851a7f32637fdb9")
@Mod(modid = "seppukumod", name = "Seppuku", version = SeppukuMod.VERSION)
public final class SeppukuMod {

public static final String VERSION = "3.1.8";
public static final String VERSION = "3.2.0";

/**
* Our mods entry point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import me.rigamortis.seppuku.impl.config.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -24,19 +29,40 @@ public final class ConfigManager {
private boolean customMainMenuHidden = false;
private List<Configurable> configurableList = new ArrayList<>();

public ConfigManager(final String config) {
this.activeConfig = config;
public ConfigManager() {
this.activeConfig = readActiveConfig();
this.generateDirectories();
}

public void switchToConfig(final String config) {
this.saveAll();

this.activeConfig = config;
this.writeActiveConfig(config);

Seppuku.INSTANCE.unloadSimple();
Seppuku.INSTANCE.init();
}

public String readActiveConfig() {
try {
final byte[] bytes = Files.readAllBytes(Paths.get("Seppuku/Config/active.txt"));
return new String(bytes, StandardCharsets.UTF_8);
} catch (IOException e) {
return "Default";
}
}

public void writeActiveConfig(final String config) {
try {
final FileOutputStream fos = new FileOutputStream("Seppuku/Config/active.txt");
fos.write(config.getBytes());
fos.close();
} catch (IOException e) {
System.err.println("Could not create file active.txt in config directory.");
}
}

private void generateDirectories() {
this.configDir = new File(String.format(CONFIG_PATH, activeConfig));
if (!this.configDir.exists()) {
Expand Down

0 comments on commit 31ba59f

Please sign in to comment.