private static void checkAddPrefixes(Field field, String fieldName, Class<? extends Annotation> annotation, Set<String> fieldNames, SimpleCharPrefixTree pathPrefixes) { if (field.isAnnotationPresent(annotation)) { fieldNames.add(fieldName); addPrefixesField(field, pathPrefixes); } else { for (final String refName : fieldNames) { if (fieldName.startsWith(refName)) { addPrefixesField(field, pathPrefixes); } } } }
protected static void addWorldConfigSection(final ConfigurationSection config, final ConfigurationSection section, final String path, final char sep) { final Map<String, Object> values = section.getValues(false); for (final Entry<String, Object> entry : values.entrySet()) { final String fullPath = path + sep + entry.getKey(); if (!mayBeInWorldConfig(fullPath)) { continue; } final Object value = entry.getValue(); if (value instanceof ConfigurationSection) { addWorldConfigSection(config, (ConfigurationSection) value, fullPath, sep); } else { config.set(fullPath, value); } } }
public static boolean mayBeInWorldConfig(final String path) { if (globalOnlyPrefixes.hasPrefix(path)) { return false; } else { return mayBeInConfig(path); } }
if (isWorldConfig) { processGlobalOnlyPaths(config, configName, null); processDeprecatedPaths(config, configName, removePaths); processMovedPaths(config, configName, removePaths, addPaths); boolean changed = false; if (!removePaths.isEmpty()) { config = removePaths(config, removePaths); changed = true; setPaths(config, addPaths, false); changed = true;
/** * Initialize annotation-based path properties. * @return */ private static void initPaths() { // TODO: Retrieving such entries should be (instance...) methods of ConfPaths or a specific configuration instance. deprecatedFields.clear(); deprecatedPrefixes.clear(); globalOnlyFields.clear(); globalOnlyPrefixes.clear(); movedPaths.clear(); for (final WrapMoved moved : ConfPaths.getExtraMovedPaths()) { movedPaths.put(moved.oldPath, moved); } for (final Field field : ConfPaths.class.getDeclaredFields()) { if (field.getType() != String.class) { // Only process strings. continue; } final String fieldName = field.getName(); checkAddPrefixes(field, fieldName, GlobalConfig.class, globalOnlyFields, globalOnlyPrefixes); checkAddPrefixes(field, fieldName, Deprecated.class, deprecatedFields, deprecatedPrefixes); if (field.isAnnotationPresent(Moved.class)) { // TODO: Prefixes: Might later support relocating entire sections with one annotation? addMoved(field, field.getAnnotation(Moved.class)); } } }
final int maxBuildContained = defaultConfig.getMaxLastChangedBuildNumber(); PathUtils.processPaths(globalFile, "global config", false); final ConfigFile globalConfig = new ConfigFile(); globalConfig.setDefaults(defaultConfig); final MemoryConfiguration worldDefaults = PathUtils.getWorldsDefaultConfig(globalConfig); PathUtils.processPaths(worldFile, "world " + worldEntry.getKey(), true); final ConfigFile worldConfig = new ConfigFile(); worldConfig.setDefaults(worldDefaults);
/** * A config file only containing the entries that are not set as global only. * @param defaultConfig * @return */ public static MemoryConfiguration getWorldsDefaultConfig(final MemoryConfiguration defaultConfig) { final char sep = defaultConfig.options().pathSeparator(); final MemoryConfiguration config = new ConfigFile(); config.options().pathSeparator(sep); final Map<String, Object> defaults = defaultConfig.getValues(false); for (final Entry<String, Object> entry : defaults.entrySet()) { final String part = entry.getKey(); if (!part.isEmpty() && !mayBeInWorldConfig(part)) { continue; } final Object value = entry.getValue(); if (value instanceof ConfigurationSection) { addWorldConfigSection(config, (ConfigurationSection) value, part, sep); } else { config.set(part, value); } } return config; }