Jump to content

[Solved] Config Updating


NomNuggetNom

Recommended Posts

My configuration GUI is not triggering a call of

ConfigChangedEvent.OnConfigChangedEvent

and I don't have the slightest clue why. Everything else is working fine: reading values has no problem, the .cfg is fine, etc. On startup, I sync the configuration, and it works perfectly. Also, as a result of this, any events marked as requiring a restart do not actually require a restart. It's really odd. What could be going wrong?

 

My messy config file (please try not to hurt yourselves while viewing). I am probably doing this VERY wrong, please tell me if so:

public class Config extends GuiConfig {

public static Configuration configFile;

/*
 * Actual configuration values.
 */
    public static String membersList = "";
    public static String mercsList = "";

    public Config(GuiScreen parent) {
        super(parent, new ConfigElement(configFile.getCategory(Configuration.CATEGORY_GENERAL)).getChildElements(), "MCCTF Mod", false, true, "MCCTF General Config");
    }

    public static void syncConfig() {
        Pattern usernamePattern = Pattern.compile("([A-Za-z0-9_]+((,){1}( )*|$))+?");

    	/*
    	 * Members List
    	 */
    	membersList = configFile.getString("Members List", Configuration.CATEGORY_GENERAL, "username, username, username", "These people will appear on your \"Clan Mate\" list in white.", usernamePattern);
    	System.out.println("membersList: " + membersList);
    	Matcher matcherMembers = usernamePattern.matcher(membersList);
        while (matcherMembers.find()) {
        	System.out.println("Found member match: " + matcherMembers.group().replace(", ", ""));
        	Main.membersList.add(matcherMembers.group().replace(", ", ""));
        }
    	
        /*
         * Merc List
         */
    	mercsList = configFile.getString("Mercs List", Configuration.CATEGORY_GENERAL, "username, username, username", "These people will appear on your \"Clan Mate\" list in gray.", usernamePattern);
    	Matcher matcherMercs = usernamePattern.matcher(mercsList);
        while (matcherMercs.find()) {
        	Main.mercsList.add(matcherMercs.group());
        }
    	
    	if (configFile.hasChanged()) {
    		configFile.save();
    	}
    }
}

 

My GUIFactory:

public class GuiFactory implements IModGuiFactory {

@Override
public void initialize(Minecraft minecraftInstance) {

}

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
	return Config.class;
}

@Override
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
	return null;
}

@Override
public RuntimeOptionGuiHandler getHandlerFor(
		RuntimeOptionCategoryElement element) {
	return null;
}
}

 

My preInit in Main:

    @EventHandler
    public void preInit(FMLPreInitializationEvent e) {
    	MinecraftForge.EVENT_BUS.register(new Events());
    	FMLCommonHandler.instance().bus().register(new Events());
    	
    	Config.configFile = new Configuration(e.getSuggestedConfigurationFile());
    	Config.syncConfig();
    }

 

My Events class for catching:

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
	System.out.println("Config changed!");
    if(event.modID.equals("mcctf")) {
       Config.syncConfig();
    }
}

 

Note: "Config changed" isn't even printed after I edit my config. It prints when I edit other mods though.

 

 

Link to comment
Share on other sites

My friend got this error after I compiled and send it to him:

cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: cpw/mods/fml/client/event/ConfigChangedEvent$OnConfigChangedEvent

 

This event was just added to Forge, so your friend probably didn't have the correct release of Forge.  I needs to be something like 1133 or later (if I remember correctly, you can check the release notes)

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

My friend got this error after I compiled and send it to him:

cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: cpw/mods/fml/client/event/ConfigChangedEvent$OnConfigChangedEvent

 

This event was just added to Forge, so your friend probably didn't have the correct release of Forge.  I needs to be something like 1133 or later (if I remember correctly, you can check the release notes)

Indeed, this was the problem. I told him to get latest, but he just doesn't listen! :P. Still having the other problem.

Link to comment
Share on other sites

What exactly is the other problem?  I read through this agian and I'm not 100% what you are asking help on.

 

When changes to the config are made, it does not trigger:

ConfigChangedEvent.OnConfigChangedEvent

Like it does with other mods.

Link to comment
Share on other sites

  • 2 years later...
On 7/9/2014 at 6:19 PM, NomNuggetNom said:

 

When changes to the config are made, it does not trigger:

 


ConfigChangedEvent.OnConfigChangedEvent
 

 

Like it does with other mods.

 

Hey, I'm having the same issue. Did you ever figure out why?

 

EDIT:

http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2126328-trying-to-register-configuration-event

Here I found that when you register the event handler in the Mod class create a new class:

FMLCommonHandler.instance().bus().register(new ConfigurationHandler());
Edited by izzie.llg
EDIT
Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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