@Override public Object read(String key, ConfigurationSection section) { List<?> list; if (section.isConfigurationSection(key)) { list = new ArrayList<>(section.getConfigurationSection(key).getValues(false).values()); } else { list = section.getList(key); } Object array = Array.newInstance(type, list.size()); for (int i = 0; i < list.size(); i++) { Object obj = list.get(i); ConfigurationSection dummySection = new MemoryConfiguration(); dummySection.set("dummy", obj); Array.set(array, i, handler.adaptIn(dummySection, "dummy", obj.getClass())); } return array; }
@Override public Collection read(String key, ConfigurationSection section) { Collection collection; List<?> originalList; if (section.isConfigurationSection(key)) { originalList = new ArrayList<>(section.getConfigurationSection(key).getValues(false).values()); } else { originalList = section.getList(key); } try { collection = implementationClass.getDeclaredConstructor(int.class).newInstance(originalList.size()); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { throw new InternalProcessingException("Could not create new instance of " + implementationClass.getName(), e); } for (Object obj: originalList) { ConfigurationSection dummySection = new MemoryConfiguration(); dummySection.set("dummy", obj); collection.add(handler.adaptIn(dummySection, "dummy", type)); } return collection; }
public static ConfigurationSection replaceParameters(ConfigurationSection configuration, ConfigurationSection parameters) { if (configuration == null) return null; ConfigurationSection replaced = new MemoryConfiguration(); Set<String> keys = configuration.getKeys(false); for (String key : keys) { Object value = configuration.get(key); if (value == null) continue; Object replacement = replaceParameters(value, parameters); if (replacement != null) { replaced.set(key, replacement); } } return replaced; }
public void save(ConfigurationSection configuration) { List<ConfigurationSection> mobsConfigurations = new ArrayList<ConfigurationSection>(); for (ArenaMobSpawner mob : mobs) { ConfigurationSection section = new MemoryConfiguration(); mob.save(section); mobsConfigurations.add(section); } configuration.set("mobs", mobsConfigurations); configuration.set("spell_start", startSpell); configuration.set("spell_end", endSpell); List<String> mobSpawnList = new ArrayList<String>(); for (Location spawn : mobSpawns) { mobSpawnList.add(ConfigurationUtils.fromLocation(spawn)); } configuration.set("mob_spawns", mobSpawnList); }
private Configuration getItemAttributes(ItemStack stack) { AttributeStorage storage = AttributeStorage.newTarget(stack, STB_ATTRIBUTE_ID); YamlConfiguration conf = new YamlConfiguration(); try { String s = storage.getData(""); if (s != null) { conf.loadFromString(s); if (Debugger.getInstance().getLevel() > 2) { Debugger.getInstance().debug(3, "get item attributes for " + STBUtil.describeItemStack(stack) + ":"); for (String k : conf.getKeys(false)) { Debugger.getInstance().debug(3, "- " + k + " = " + conf.get(k)); } } return conf; } else { throw new IllegalStateException("ItemStack " + stack + " has no STB attribute data!"); } } catch (InvalidConfigurationException e) { e.printStackTrace(); return new MemoryConfiguration(); } }
@SuppressWarnings("unchecked") public static List<OreRule> LoadFromList (List<Map<?, ?>> configList) { List<OreRule> result = new ArrayList<OreRule>(); if (configList == null) return result; for (Map<?, ?> item : configList) { Map<String, Object> castItem = (Map<String, Object>)item; MemoryConfiguration config = new MemoryConfiguration(); config.addDefaults(castItem); result.add(new OreRule(config.getDefaults())); } return result; }
@SuppressWarnings("unchecked") public static List<ClearRule> LoadFromList (List<Map<?, ?>> configList) { List<ClearRule> result = new ArrayList<ClearRule>(); if (configList == null) return result; for (Map<?, ?> item : configList) { Map<String, Object> castItem = (Map<String, Object>)item; MemoryConfiguration config = new MemoryConfiguration(); config.addDefaults(castItem); result.add(new ClearRule(config.getDefaults())); } return result; }
private ConfigurationSection _getKitTimestamps() { if (config.isConfigurationSection("timestamps.kits")) { final ConfigurationSection section = config.getConfigurationSection("timestamps.kits"); final ConfigurationSection newSection = new MemoryConfiguration(); for (String command : section.getKeys(false)) { if (section.isLong(command)) { newSection.set(command.toLowerCase(Locale.ENGLISH), section.getLong(command)); } else if (section.isInt(command)) { newSection.set(command.toLowerCase(Locale.ENGLISH), (long)section.getInt(command)); } } return newSection; } return new MemoryConfiguration(); }
public ConfigurationSection _getCommandCosts() { if (config.isConfigurationSection("command-costs")) { final ConfigurationSection section = config.getConfigurationSection("command-costs"); final ConfigurationSection newSection = new MemoryConfiguration(); for (String command : section.getKeys(false)) { if (section.isDouble(command)) { newSection.set(command.toLowerCase(Locale.ENGLISH), section.getDouble(command)); } else if (section.isInt(command)) { newSection.set(command.toLowerCase(Locale.ENGLISH), (double)section.getInt(command)); } } return newSection; } return null; }
public ConfigurationSection _getKits() { if (config.isConfigurationSection("kits")) { final ConfigurationSection section = config.getConfigurationSection("kits"); final ConfigurationSection newSection = new MemoryConfiguration(); for (String kitItem : section.getKeys(false)) { if (section.isConfigurationSection(kitItem)) { newSection.set(kitItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(kitItem)); } } return newSection; } return null; }
@Override public Map read(String key, ConfigurationSection section) { ConfigurationSection originalMap = section.getConfigurationSection(key); Map map = new HashMap(); originalMap.getValues(false).forEach((k, v) -> { ConfigurationSection dummySection = new MemoryConfiguration(); dummySection.set("dummy", v); map.put(k, handler.adaptIn(dummySection, "dummy", valueClass)); }); return map; }
public ConfigurationSection getConfig() { ConfigurationSection section = new MemoryConfiguration(); section.set("id", id); section.set("world", world.getName()); section.set("image", imgName); return section; }
@Test public void testFlatten() throws Exception { ConfigurationSection config = new MemoryConfiguration(); config.set("foo", "bar"); config.set("deeply.nested.property", "value"); Map<String, String> flattened = ConfigurationSectionUtil.flatten(config); assertEquals(2, flattened.size()); assertEquals("bar", flattened.get("foo")); assertEquals("value", flattened.get("deeply.nested.property")); }
/** * Loads a file into memory as a MemoryConfiguration * * @param file The file to load, then delete after loading * @return The MemoryConfiguration resulting from loading the file */ public static MemoryConfiguration loadResource(String file) { initFiles(file); FileConfiguration fc = loadFile(file); MemoryConfiguration mc = new MemoryConfiguration(fc); deleteFile(file); return mc; }
public static MemorySection serialize(Transaction transaction) { MemoryConfiguration serialized = new MemoryConfiguration(); serialized.set("sender", transaction.getSender().toString()); serialized.set("itemstack", transaction.getItemStack()); serialized.set("timestamp", transaction.getTimeStamp()); serialized.set("lifetime", transaction.getLifeTime()); return serialized; }
public static ConfigurationSection toConfigurationSection(Map<?, ?> nodeMap) { ConfigurationSection newSection = new MemoryConfiguration(); for (Map.Entry<?, ?> entry : nodeMap.entrySet()) { set(newSection, entry.getKey().toString(), entry.getValue()); } return newSection; }
public static ConfigurationSection cloneConfiguration(ConfigurationSection section) { return addConfigurations(new MemoryConfiguration(), section); }
@Override protected void loadTemplate(ConfigurationSection template) { castOnNoTarget = true; super.loadTemplate(template); undoable = false; requiresBuildPermission = false; requiresBreakPermission = false; usesBrush = template.getBoolean("uses_brush", false); if (template.contains("actions")) { ConfigurationSection parameters = template.getConfigurationSection("parameters"); ConfigurationSection actionsNode = template.getConfigurationSection("actions"); Object baseActions = actionsNode.get("cast"); Collection<String> templateKeys = template.getKeys(false); for (String templateKey : templateKeys) { if (templateKey.endsWith("_parameters")) { ConfigurationSection overrides = new MemoryConfiguration(); ConfigurationUtils.addConfigurations(overrides, template.getConfigurationSection(templateKey)); String handlerKey = templateKey.substring(0, templateKey.length() - 11); handlerParameters.put(handlerKey, overrides); // Auto-register base actions, kind of hacky to check for alternates though. if (baseActions != null && !actionsNode.contains(handlerKey) && handlerKey.startsWith("alternate_")) { actionsNode.set(handlerKey, baseActions); } } } actionsNode = ConfigurationUtils.replaceParameters(actionsNode, parameters); if (actionsNode != null) { Collection<String> actionKeys = actionsNode.getKeys(false); for (String actionKey : actionKeys) { ActionHandler handler = new ActionHandler(); handler.load(this, actionsNode, actionKey); handler.initialize(this, parameters); usesBrush = usesBrush || handler.usesBrush(); undoable = undoable || handler.isUndoable(); requiresBuildPermission = requiresBuildPermission || handler.requiresBuildPermission(); requiresBreakPermission = requiresBreakPermission || handler.requiresBreakPermission(); actions.put(actionKey, handler); } } } undoable = template.getBoolean("undoable", undoable); }
protected MemoryConfigurationOptions(MemoryConfiguration configuration) { super(configuration); }
public MemoryConfiguration configuration() { return null; }
protected FileConfigurationOptions(MemoryConfiguration configuration) { super(configuration); }
/** * Updates the configuration data. * * @param configuration The new ConfigurationSection. */ public void update(MemoryConfiguration configuration) { this.section = configuration; // A little hack to enforce a cast from Map<String, String> to Map<String, Object>. this.section.addDefaults((Map<String, Object>) (Map) TranslationManager.getDefaults()); }
/** * Initializes the command handler. * * @param configuration The configuration to use. */ public BukkitConfigurationLocalizationHandler(MemoryConfiguration configuration) { update(configuration); }