profile = node.getNode("debug").getBoolean(profile); traceUnflushedSessions = node.getNode("debugging", "trace-unflushed-sessions").getBoolean(traceUnflushedSessions); wandItem = node.getNode("wand-item").getString(wandItem); try { wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId(); defaultChangeLimit = Math.max(-1, node.getNode("limits", "max-blocks-changed", "default").getInt(defaultChangeLimit)); maxChangeLimit = Math.max(-1, node.getNode("limits", "max-blocks-changed", "maximum").getInt(maxChangeLimit)); defaultMaxPolygonalPoints = Math.max(-1, node.getNode("limits", "max-polygonal-points", "default").getInt(defaultMaxPolygonalPoints)); maxPolygonalPoints = Math.max(-1, node.getNode("limits", "max-polygonal-points", "maximum").getInt(maxPolygonalPoints)); maxRadius = Math.max(-1, node.getNode("limits", "max-radius").getInt(maxRadius)); maxBrushRadius = node.getNode("limits", "max-brush-radius").getInt(maxBrushRadius); maxSuperPickaxeSize = Math.max(1, node.getNode("limits", "max-super-pickaxe-size").getInt(maxSuperPickaxeSize)); butcherDefaultRadius = Math.max(-1, node.getNode("limits", "butcher-radius", "default").getInt(butcherDefaultRadius)); butcherMaxRadius = Math.max(-1, node.getNode("limits", "butcher-radius", "maximum").getInt(butcherMaxRadius)); disallowedBlocks = new HashSet<>(node.getNode("limits", "disallowed-blocks").getList(TypeToken.of(String.class))); } catch (ObjectMappingException e) { logger.warn("Error loading WorldEdit configuration", e); allowedDataCycleBlocks = new HashSet<>(node.getNode("limits", "allowed-data-cycle-blocks").getList(TypeToken.of(String.class))); } catch (ObjectMappingException e) { logger.warn("Error loading WorldEdit configuration", e); registerHelp = node.getNode("register-help").getBoolean(true); logCommands = node.getNode("logging", "log-commands").getBoolean(logCommands);
@Override public boolean has(String path) { return !file.getNode(path).isVirtual(); }
@Override public String getString(String path) { return file.getNode(path).getString(); }
@Override public long getLong(String path) { return file.getNode(path).getLong(); }
@Override public boolean getBoolean(String path) { return file.getNode(path).getBoolean(); }
@Override public int getInt(String path) { return file.getNode(path).getInt(); }
@Override public double getDouble(String path) { return file.getNode(path).getDouble(); }
@Override public Map<String, String> getStringMap(String path) { Map<String, String> map = new HashMap<>(); Set<? extends Map.Entry<Object, ? extends CommentedConfigurationNode>> childrens = path.equals("") ? file.getChildrenMap().entrySet(): file.getNode(path).getChildrenMap().entrySet(); for (Map.Entry<Object, ? extends CommentedConfigurationNode> entry : childrens) { map.put(entry.getKey().toString(), entry.getValue().getString()); } return map; }
/** * Loads configuration */ public void load() { try { baseNode = loader.load(); configuration = mapper.populate(Objects.requireNonNull(baseNode).getNode(baseNodeName)); } catch (ObjectMappingException | IOException e) { throw new RuntimeException(e); } }
/** * Saves configuration */ public void save() { try { mapper.serialize(Objects.requireNonNull(baseNode).getNode(baseNodeName)); loader.save(baseNode); } catch (ObjectMappingException | IOException e) { throw new RuntimeException(e); } }
@Override public void setValue(String path, Object value) { file.getNode(path).setValue(value); try { loader.save(file); } catch (IOException e) { e.printStackTrace(); } }
/** * Has the server owner denied plugin metrics? * * @return true if metrics should be opted out of it */ public boolean isOptOut() { synchronized (optOutLock) { loadConfiguration(); return config.getNode("mcstats.opt-out").getBoolean(); } }
@Override public void loadInternal(CommentedConfigurationNode node, BufferedReader reader) throws IOException { Config hoconConfig = ConfigFactory.parseReader(reader, parse); hoconConfig = hoconConfig.resolve(); for (Map.Entry<String, ConfigValue> ent : hoconConfig.root().entrySet()) { readConfigValue(ent.getValue(), node.getNode(ent.getKey())); } }
@Override public void loadInternal(CommentedConfigurationNode node, BufferedReader reader) throws IOException { Config hoconConfig = ConfigFactory.parseReader(reader, parse); hoconConfig = hoconConfig.resolve(); for (Map.Entry<String, ConfigValue> ent : hoconConfig.root().entrySet()) { readConfigValue(ent.getValue(), node.getNode(ent.getKey())); } }
@Test public void testNestedObjectWithComments() throws ObjectMappingException { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(); final ObjectMapper<ParentObject>.BoundInstance mapper = ObjectMapper.forObject(new ParentObject()); mapper.populate(node); assertEquals("Comment on parent", node.getNode("inner").getComment().get()); assertTrue(node.getNode("inner").hasMapChildren()); assertEquals("Default value", node.getNode("inner", "test").getString()); assertEquals("Something", node.getNode("inner", "test").getComment().get()); }
@Test public void testCommentsApplied() throws ObjectMappingException { CommentedConfigurationNode node = SimpleCommentedConfigurationNode.root(); ObjectMapper<CommentedObject>.BoundInstance mapper = ObjectMapper.forClass(CommentedObject.class).bindToNew(); CommentedObject obj = mapper.populate(node); obj.color = "fuchsia"; obj.politician = "All of them"; mapper.serialize(node); assertEquals("You look nice today", node.getNode("commented-key").getComment().orElse(null)); assertEquals("fuchsia", node.getNode("commented-key").getString()); assertFalse(node.getNode("no-comment").getComment().isPresent()); }
@Test public void testHeaderSaved(@TempDirectory.TempDir Path tempDir) throws IOException { final Path saveTo = tempDir.resolve("text3.txt"); HoconConfigurationLoader loader = HoconConfigurationLoader.builder() .setPath(saveTo) .build(); CommentedConfigurationNode node = loader.createEmptyNode(ConfigurationOptions.defaults().setHeader("Hi! I am a header!\n" + "Look at meeeeeee!!!")); node.getNode("node").setComment("I have a comment").getNode("party").setValue("now"); loader.save(node); assertEquals(Resources.readLines(getClass().getResource("/header.conf"), UTF_8), Files.readAllLines(saveTo, UTF_8)); }
@Test public void testBooleansNotShared(@TempDirectory.TempDir Path tempDir) throws IOException { URL url = getClass().getResource("/comments-test.conf"); final Path saveTo = tempDir.resolve("text4.txt"); HoconConfigurationLoader loader = HoconConfigurationLoader.builder() .setPath(saveTo).setURL(url).build(); CommentedConfigurationNode node = loader.createEmptyNode(ConfigurationOptions.defaults()); node.getNode("test", "third").setValue(false).setComment("really?"); node.getNode("test", "apple").setComment("fruit").setValue(false); node.getNode("test", "donut").setValue(true).setComment("tasty"); node.getNode("test", "guacamole").setValue(true).setComment("and chips?"); loader.save(node); assertEquals(Resources.readLines(url, UTF_8), Files.readAllLines(saveTo, UTF_8)); }
@Test public void testCommentsTransferred() { CommentedConfigurationNode subject = SimpleCommentedConfigurationNode.root(); CommentedConfigurationNode firstChild = subject.getNode("first"); firstChild.setValue("test value"); firstChild.setComment("Such comment. Very wow."); CommentedConfigurationNode secondChild = subject.getNode("second"); secondChild.setValue("test value's evil twin"); assertFalse(secondChild.isVirtual()); secondChild.setValue(firstChild); assertEquals("test value", secondChild.getValue()); assertEquals("Such comment. Very wow.", secondChild.getComment().orElse(null)); }