wandItem = node.getNode("wand-item").getString(wandItem); try { wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId(); logFile = node.getNode("logging", "file").getString(logFile); logFormat = node.getNode("logging", "format").getString(logFormat); useInventoryCreativeOverride = node.getNode("use-inventory", "creative-mode-overrides").getBoolean(useInventoryCreativeOverride); navigationWand = node.getNode("navigation-wand", "item").getString(navigationWand); try { navigationWand = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(navigationWand)).getId(); scriptsDir = node.getNode("scripting", "dir").getString(scriptsDir); saveDir = node.getNode("saving", "dir").getString(saveDir); serverSideCUI = node.getNode("server-side-cui").getBoolean(true); String snapshotsDir = node.getNode("snapshots", "directory").getString(""); if (!snapshotsDir.isEmpty()) { snapshotRepo = new SnapshotRepository(snapshotsDir); String type = node.getNode("shell-save-type").getString("").trim(); shellSaveType = type.equals("") ? null : type;
@Override public String getString(String path) { return file.getNode(path).getString(); }
@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; }
serverUUID = node.getNode("serverUuid").getString(); logFailedRequests = node.getNode("logFailedRequests").getBoolean(false);
/** * Loads the configuration */ private void loadConfiguration() { configurationFile = getConfigFile(); configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build(); try { if (!configurationFile.exists()) { configurationFile.createNewFile(); config = configurationLoader.load(); config.setComment("This contains settings for MCStats: http://mcstats.org"); config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString()); config.getNode("mcstats.opt-out").setValue(false); config.getNode("mcstats.debug").setValue(false); configurationLoader.save(config); } else { config = configurationLoader.load(); } guid = config.getNode("mcstats.guid").getString(); debug = config.getNode("mcstats.debug").getBoolean(); } catch (final IOException e) { e.printStackTrace(); } }
serverUUID = node.getNode("serverUuid").getString(); logFailedRequests = node.getNode("logFailedRequests").getBoolean(false); logSentData = node.getNode("logSentData").getBoolean(false);
serverUUID = node.getNode("serverUuid").getString(); logFailedRequests = node.getNode("logFailedRequests").getBoolean(false); logSentData = node.getNode("logSentData").getBoolean(false);
assertEquals("Changed value", node.getNode("inner").getNode("test").getString()); assertEquals("Changed value", node.getNode("list").getChildrenList().get(0).getNode("test").getString()); assertEquals("Something", node.getNode("inner").getNode("test").getComment().get()); assertEquals("Something", node.getNode("list").getChildrenList().get(0).getNode("test").getComment().get()); assertEquals(ChildObject.class.getName(), node.getNode("inner").getNode("__class__").getString()); assertEquals(ChildObject.class.getName(), node.getNode("list").getChildrenList().get(0).getNode("__class__").getString());
@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 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 testCommentsMerged() { CommentedConfigurationNode source = SimpleCommentedConfigurationNode.root(); CommentedConfigurationNode target = SimpleCommentedConfigurationNode.root(); source.getNode("no-value").setValue("a").setComment("yeah"); source.getNode("existing-value-no-comment").setValue("orig").setComment("maybe"); source.getNode("existing-value").setValue("a").setComment("yeah"); source.getNode("no-parent", "child").setValue("x").setComment("always"); target.getNode("existing-value-no-comment").setValue("new"); target.getNode("existing-value").setValue("b").setComment("nope"); target.mergeValuesFrom(source); assertEquals("yeah", target.getNode("no-value").getComment().orElse(null)); assertEquals("maybe", target.getNode("existing-value-no-comment").getComment().orElse(null)); assertEquals("new", target.getNode("existing-value-no-comment").getString()); assertEquals("nope", target.getNode("existing-value").getComment().orElse(null)); assertEquals("always", target.getNode("no-parent", "child").getComment().orElse(null)); } }