Added createSection(String path, Map<String, object> map)
This commit is contained in:
parent
841872d591
commit
c00f47e0e2
@ -165,6 +165,17 @@ public interface ConfigurationSection {
|
|||||||
*/
|
*/
|
||||||
public ConfigurationSection createSection(String path);
|
public ConfigurationSection createSection(String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link ConfigurationSection} at the specified path, with specified values.
|
||||||
|
* <p>
|
||||||
|
* Any value that was previously set at this path will be overwritten. If the
|
||||||
|
* previous value was itself a {@link ConfigurationSection}, it will be orphaned.
|
||||||
|
*
|
||||||
|
* @param path Path to create the section at.
|
||||||
|
* @return Newly created section
|
||||||
|
*/
|
||||||
|
public ConfigurationSection createSection(String path, Map<String, Object> map);
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
/**
|
/**
|
||||||
* Gets the requested String by path.
|
* Gets the requested String by path.
|
||||||
|
@ -267,6 +267,20 @@ public class MemorySection implements ConfigurationSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigurationSection createSection(String path, Map<String, Object> map) {
|
||||||
|
ConfigurationSection section = createSection(path);
|
||||||
|
|
||||||
|
for(Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
if(entry.getValue() instanceof Map) {
|
||||||
|
section.createSection(entry.getKey(), (Map<String, Object>)entry.getValue());
|
||||||
|
} else {
|
||||||
|
section.set(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
public String getString(String path) {
|
public String getString(String path) {
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
|
@ -3,6 +3,7 @@ package org.bukkit.configuration;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -182,6 +183,19 @@ public abstract class ConfigurationSectionTest {
|
|||||||
assertEquals("subsection", subsection.getName());
|
assertEquals("subsection", subsection.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSectionMap() {
|
||||||
|
ConfigurationSection config = getConfigurationSection();
|
||||||
|
Map<String, Object> testMap = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
testMap.put("string", "Hello World");
|
||||||
|
testMap.put("integer", 15);
|
||||||
|
|
||||||
|
config.createSection("test.path", testMap);
|
||||||
|
|
||||||
|
assertEquals(testMap, config.getConfigurationSection("test.path").getValues(false));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetString_String() {
|
public void testGetString_String() {
|
||||||
ConfigurationSection section = getConfigurationSection();
|
ConfigurationSection section = getConfigurationSection();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bukkit.configuration;
|
package org.bukkit.configuration;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user