Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#isConfigurationSection()

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#isConfigurationSection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YamlEnumTest.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testConfig() throws Exception {
	System.out.println();
	System.out.println("Testing config enums...");
	YamlConfiguration config = getConfig();
	final List<String> configEnumNames = new ArrayList<>();
	for(ConfigWrapper v : Config.values()) {
		configEnumNames.add(v.getName());
	}

	int missingCount = 0;
	for(String key : config.getKeys(true)) {
		boolean ig = config.isConfigurationSection(key);
		for(String ignore : ignoreConfig) {
			if(key.startsWith(ignore)) {
				ig = true;
				break;
			}
		}

		if(!ig) {
			String name = StringUtils.replace(key, ".", "_").toUpperCase();
			if(!configEnumNames.contains(name)) {
				if(missingCount == 0) {
					System.out.println("Missing keys:");
				}

				System.out.println(name + ",");
				missingCount++;
			}
		}
	}

	if(missingCount == 0) {
		System.out.println("All values are present in Config enum");
	}
	else {
		throw new Exception("Found " + missingCount + " missing Config enums");
	}
}
 
Example 2
Source File: YamlEnumTest.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testMessages() throws Exception {
	System.out.println();
	System.out.println("Testing message wrappers...");
	File motherFile = new File(YamlParseTest.resourcesDirectory, "lang/en-en.yml");
	YamlConfiguration motherConfiguration = Lang.loadConfiguration(motherFile);
	final List<String> messageEnumNames = new ArrayList<>();

	for(MessageWrapper v : Message.values()) {
		messageEnumNames.add(v.getName());
	}

	int missingCount = 0;
	for(String key : motherConfiguration.getKeys(true)) {
		if(!motherConfiguration.isConfigurationSection(key)) {
			String name = StringUtils.replace(key, ".", "_").toUpperCase();
			if(!messageEnumNames.contains(name)) {
				if(missingCount == 0) {
					System.out.println("Missing keys:");
				}

				System.out.println(name + ",");
				missingCount++;
			}
		}
	}

	if(missingCount == 0) {
		System.out.println("All values are present in Message class");
	}
	else {
		throw new Exception("Found " + missingCount + " missing Message wrappers");
	}
}
 
Example 3
Source File: YamlIncompleteTranslationTest.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testTranslations() throws Exception {
	//Mother lang setup
	File motherLangFile = new File(langDir, "en-en.yml");
	YamlConfiguration motherConfiguration = YamlConfiguration.loadConfiguration(motherLangFile);
	final List<String> motherKeys = new ArrayList<>();
	for(String key : motherConfiguration.getKeys(true)) {
		if(!motherConfiguration.isConfigurationSection(key)) {
			motherKeys.add(key);
		}
	}

	//List all languages and configuration sections
	Map<String, YamlConfiguration> configurationMap = new HashMap<>();
	if(langDir.isDirectory()) {
		File[] list = langDir.listFiles();

		if(list != null) {
			for(File langFile : list) {
				if(!langFile.getName().equals("en-en.yml")) {
					configurationMap.put(StringUtils.replace(langFile.getName(), ".yml", ""), Lang.loadConfiguration(langFile));
				}
			}
		}
	}

	//Get keys from all langs
	System.out.println("Testing lang files for missing keys...");
	int globalMissingCount = 0;
	for(Map.Entry<String, YamlConfiguration> entry : configurationMap.entrySet()) {
		int missingCount = 0;
		String name = entry.getKey();
		YamlConfiguration configuration = entry.getValue();

		System.out.println("---");
		System.out.println();
		System.out.println("Testing lang: " + name);

		for(String mKey : motherKeys) {
			if(!configuration.contains(mKey)) {
				if(missingCount == 0) {
					System.out.println("Missing keys:");
				}

				System.out.println(" - " + mKey);
				missingCount++;
			}
		}

		globalMissingCount += missingCount;
	}

	if(globalMissingCount == 0) {
		System.out.println("Result: No missing keys");
	}
	else {
		throw new Exception("Found " + globalMissingCount + " missing keys in lang files");
	}
}