Jump to content

[1.8] Config categories duplicates when using uppercase


ItsTautvydas

Recommended Posts

Hello, I'm trying to write configuration file, so I search around this site and found config handler full class, and not gonna lie - I took it, I was too lazy to make it myself, I edit a bit and added some functions. Problem is when I use upper case letters in category, it duplicates (code below). The uppercase category "Mod" get none of keys and values, lower case gets it. Also when using lower case, no duplicates, everythink is fine, but all lower cased categories doesn't look great, because I have mod config button enabled, so yeah..
 

# Configuration file

Mod {

    settings {
    }

}


mod {
    B:"Mod Enabled"=true

    settings {
        S:"Custom Toggle Command"=ar:toggle
        B:"Toggle Command"=true
    }

}

How I use config handler
 

@EventHandler
public void onInitialization(FMLInitializationEvent event) {

  if (ConfigHandler.hasCategory("Mod") == false) {
  	ConfigHandler.writeConfig("Mod", "Mod Enabled", true);
  }

  if (ConfigHandler.hasCategory("Mod.settings") == false) {
  	ConfigHandler.writeConfig("Mod.settings", "SEOL", 0);
  	ConfigHandler.writeConfig("Mod.settings", "Toggle Command", true);
 	ConfigHandler.writeConfig("Mod.settings", "Custom Toggle Command", "ar:toggle");
  }
}

ConfigHandler class, not full, writeConfig() only, and also init()

	public static void init() {
		config = new Configuration(new File(file));
		try {
			config.load();
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}

	public static void writeConfig(String category, String key, String value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			String set = config.get(category, key, value).getString();
			config.getCategory(category).get(key).set(value);
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
	
	public static void writeConfig(String category, String key, int value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			int set = config.get(category, key, value).getInt();
			config.getCategory(category).get(key).set(value);
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
	
	public static void writeConfig(String category, String key, boolean value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			boolean set = config.get(category, key, value).getBoolean();
			config.getCategory(category).get(key).set(value);
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
	
	public static void writeConfig(String category, String key, long value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			long set = config.get(category, key, value).getInt();
			config.getCategory(category).get(key).set(value);
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
	
	public static void writeConfig(String category, String key, double value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			double set = config.get(category, key, value).getDouble();
			config.getCategory(category).get(key).set(value);
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
	
	public static void writeConfig(String category, String key, short value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			int set = config.get(category, key, value).getInt();
			config.getCategory(category).get(key).set(Integer.valueOf(value));
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}

	public static void writeConfig(String category, String key, byte value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			int set = config.get(category, key, value).getInt();
			config.getCategory(category).get(key).set(Integer.valueOf(value));
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}

	public static void writeConfig(String category, String key, float value) {
		config = new Configuration(new File(file));
		try {
			config.load();
			double set = config.get(category, key, value).getDouble();
			config.getCategory(category).get(key).set(Double.valueOf(value));
		} catch (Exception e) {
			System.out.println("Cannot load configuration file!");
		} finally {
			config.save();
		}
	}
}

 

Edited by ItsTautvydas
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.