Jump to content

[1.15.2] Config changes being reverted


Elrol_Arrowsend

Recommended Posts

Not sure exactly why, but in my config I have a list of strings. When I change the config, and reload the config, some settings work properly (things like booleans, and integers) but the list of strings get reverted back to default.
I feel like it has to deal with them being

ForgeConfigSpec.ConfigValue<List<String>>

 

I can provide more code relating to it, but would prefer to not upload it all.
Any help is appreciated and welcomed

 

FeatureConfig.java

@Mod.EventBusSubscriber
public class FeatureConfig {
    public static ForgeConfigSpec.ConfigValue<String> tag;

    public static ForgeConfigSpec.BooleanValue color_chat_enable;
    public static ForgeConfigSpec.BooleanValue translation_enable;
    public static ForgeConfigSpec.ConfigValue<String> color_chat_perm;
    public static ForgeConfigSpec.ConfigValue<String> link_chat_perm;
    public static ForgeConfigSpec.BooleanValue rainbow_code_enable;
    public static ForgeConfigSpec.BooleanValue holiday_code_enable;
    public static ForgeConfigSpec.BooleanValue enable_global_perms;
    public static ForgeConfigSpec.BooleanValue enable_economy;
    
    public static ForgeConfigSpec.ConfigValue<List<String>> jan_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> feb_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> mar_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> apr_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> may_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> jun_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> jul_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> aug_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> sep_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> oct_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> nov_colors;
    public static ForgeConfigSpec.ConfigValue<List<String>> dec_colors;

    public static ForgeConfigSpec.IntValue clearlag_frequency;
    public static ForgeConfigSpec.BooleanValue clearlag_items;
    public static ForgeConfigSpec.BooleanValue clearlag_hostile;
    public static ForgeConfigSpec.BooleanValue clearlag_passive;
    public static ForgeConfigSpec.BooleanValue auto_clearlag_enabled;

    public static void init(ForgeConfigSpec.Builder server){
        server.comment("The tag used by the mod, leave empty for no tag.");
        tag = server.define("tag", "&8[&9S&aU&8]");
        server.comment("enabling global permissions will make all players op, then restrict command usage based on the permissions.json file (in the config directory) and the permissions the player has.");
        enable_global_perms = server.define("global perms", true);
        server.comment("disabling translations will force all messages to be in english.");
        translation_enable = server.define("translations", true);
        server.push("Auto Clearlag");
            auto_clearlag_enabled = server.define("enabled", false);
            clearlag_frequency = server.defineInRange("frequency", 5, 0, Integer.MAX_VALUE);
            server.push("Entities");
                clearlag_items = server.define("item", true);
                clearlag_passive = server.define("passive", true);
                clearlag_hostile = server.define("hostile", true);
            server.pop();
        server.pop();
        server.push("Color Chat");
            color_chat_perm = server.define("perm", "serverutils.colorchat");
            link_chat_perm = server.define("link-perm", "serverutils.linkchat");
            color_chat_enable = server.define("enabled", true);

            server.push("Color Codes");
                server.comment("This will enable the &g color code, which will change text to rainbow.");
                rainbow_code_enable = server.define("rainbow enabled", true);

                server.comment("This will enable the &h color code, which will change text based on the month it is.");
                holiday_code_enable = server.define("holiday enabled", true);

                server.push("Holiday Colors");
                    jan_colors = server.define("January", Arrays.asList("8", "7", "6", "f"));
                    feb_colors = server.define("Febuary", Arrays.asList("f", "d", "5", "c"));
                    mar_colors = server.define("March", Arrays.asList("2", "a", "f", "6"));
                    apr_colors = server.define("April", Arrays.asList("b", "a", "9", "f"));
                    may_colors = server.define("May", Arrays.asList("a", "e", "b", "9"));
                    jun_colors = server.define("June", Arrays.asList("7", "f", "c"));
                    jul_colors = server.define("July", Arrays.asList("c", "f", "9"));
                    aug_colors = server.define("August", Arrays.asList("6", "c", "a"));
                    sep_colors = server.define("September", Arrays.asList("8", "c", "e"));
                    oct_colors = server.define("October", Arrays.asList("8", "6", "f"));
                    nov_colors = server.define("November", Arrays.asList("c", "6", "e"));
                    dec_colors = server.define("December", Arrays.asList("a", "f", "c"));
                server.pop();
            server.pop();
        server.pop();
        Logger.log("Config has been initialized");
    }

 

Configs.java

public class Configs {
    private static final ForgeConfigSpec.Builder featureBuilder = new ForgeConfigSpec.Builder();
    public static final ForgeConfigSpec featureConfig;

    private static final ForgeConfigSpec.Builder commandBuilder = new ForgeConfigSpec.Builder();
    public static final ForgeConfigSpec commandConfig;

    static {
        Main.getLogger().info("Loading configs");
        FeatureConfig.init(featureBuilder);
        featureConfig = featureBuilder.build();

        CommandConfig.init(commandBuilder);
        commandConfig = commandBuilder.build();
    }

    public static void reload(){
        loadConfig(featureConfig, FMLPaths.CONFIGDIR.get().resolve("ServerUtils_Features.toml").toString());
        loadConfig(commandConfig, FMLPaths.CONFIGDIR.get().resolve("ServerUtils_Commands.toml").toString());
    }

    public static void loadConfig(ForgeConfigSpec config, String path){
        Main.getLogger().info("Loading config: " + path);
        final CommentedFileConfig file = CommentedFileConfig.builder(new File(path)).sync().autosave().writingMode(WritingMode.REPLACE).build();
        Main.getLogger().info("Built config: " + path);
        file.load();
        Main.getLogger().info("Loaded config: " + path);
        config.setConfig(file);
    }
}

 

Edited by Elrol_Arrowsend
Adding code
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.