ninja.leaping.configurate.ConfigurationNode Java Examples
The following examples show how to use
ninja.leaping.configurate.ConfigurationNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigUtils.java From BlueMap with MIT License | 6 votes |
/** * Returns an color-integer. The value can be a normal integer, an integer in String-Format, or a string in hexadecimal format prefixed with # (css-style: e.g. #f16 becomes #ff1166). * @param node The Configuration Node with the value * @return The parsed Integer * @throws NumberFormatException If the value is not formatted correctly or if there is no value present. */ public static int readColorInt(ConfigurationNode node) throws NumberFormatException { Object value = node.getValue(); if (value == null) throw new NumberFormatException("No value!"); if (value instanceof Number) { return ((Number) value).intValue(); } String val = value.toString(); if (val.charAt(0) == '#') { val = val.substring(1); if (val.length() == 3) val = "f" + val; if (val.length() == 4) val = "" + val.charAt(0) + val.charAt(0) + val.charAt(1) + val.charAt(1) + val.charAt(2) + val.charAt(2) + val.charAt(3) + val.charAt(3); if (val.length() == 6) val = "ff" + val; return Integer.parseUnsignedInt(val, 16); } return Integer.parseInt(val); }
Example #2
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #3
Source File: ActivePlayerChatView.java From ChatUI with MIT License | 6 votes |
private Tab createSettingsTab(UUID uuid) { ConfigEditTab.Options opts = new ConfigEditTab.Options(false, true, false, "Settings"); ConfigEditTab.ActionHandler handler = new ConfigEditTab.ActionHandler() { @Override public void onNodeChanged(ConfigEditTab tab, ConfigurationNode node) { PlayerSettings playerConfig = LibConfig.playerConfig(uuid); ConfigurationNode config = Config.playerConfig(uuid); try { onConfigChange(node, playerConfig, config); } catch (Exception e) { tab.reloadRootNode(createConfigNode(uuid)); return; } LibConfig.saveConfig(); Config.saveConfig(); } }; return new ConfigEditTab(createConfigNode(uuid), Text.of("Settings"), opts, handler); }
Example #4
Source File: ConfigTabControl.java From ChatUI with MIT License | 6 votes |
private ConfigEntry.ConfigValue nodeToValue(ConfigurationNode node) { if (node.hasMapChildren() || node.hasListChildren()) { return new ConfigEntry.ComplexValue(node); } Object value = node.getValue(); if (value instanceof Number) { return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.NUMBER); } else if (value instanceof Boolean) { return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.BOOLEAN); } else if (value instanceof String) { return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.STRING); } else if (value == null) { return new ConfigEntry.SimpleValue(value, ConfigEntry.ValueType.NULL); } return new ConfigEntry.UnknownValueType(value); }
Example #5
Source File: HOCONPlayerStorage.java From EagleFactions with MIT License | 6 votes |
@Override public Set<String> getServerPlayerNames() { Set<String> playerSet = new HashSet<>(); File playerDir = new File(playersDirectoryPath.toUri()); File[] playerFiles = playerDir.listFiles(); for(File playerFile : playerFiles) { HoconConfigurationLoader configurationLoader = HoconConfigurationLoader.builder().setDefaultOptions(ConfigurateHelper.getDefaultOptions()).setPath(playerFile.toPath()).build(); try { ConfigurationNode configurationNode = configurationLoader.load(); playerSet.add(configurationNode.getNode("name").getString("")); } catch(IOException e) { e.printStackTrace(); } } return playerSet; }
Example #6
Source File: ConfigTabControl.java From ChatUI with MIT License | 6 votes |
ConfigTabControl(ConfigEditTab tab, ConfigurationNode rootNode, ConfigEditTab.Options options, ConfigEditTab.ActionHandler handler) { this.tab = tab; this.currentNode = rootNode; updateEntryList(rootNode); ConfigurationNode parent = rootNode.getParent(); Object[] ignore; if (parent == null) { ignore = new Object[0]; } else { ignore = parent.getPath(); if (ignore.length == 1 && ignore[0] == null) { ignore = new Object[0]; } } this.ignoredPath = ignore; this.options = options; this.handler = handler; }
Example #7
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #8
Source File: ConfigurationVersionUtil.java From AntiVPN with MIT License | 6 votes |
private static void to412(ConfigurationNode config) { // Add proxy to ipqualityscore config.getNode("sources", "ipqualityscore", "proxy").setValue(Boolean.FALSE); // Add mobile to ipqualityscore config.getNode("sources", "ipqualityscore", "mobile").setValue(Boolean.TRUE); // Add strictness to ipqualityscore config.getNode("sources", "ipqualityscore", "strictness").setValue(0); // Add recent-abuse to ipqualityscore config.getNode("sources", "ipqualityscore", "recent-abuse").setValue(Boolean.TRUE); // Forcibly change ipqualityscore from (default) 65% to 98% - this will override any previous customizations config.getNode("sources", "ipqualityscore", "threshold").setValue(0.98d); // Version config.getNode("version").setValue(4.12d); }
Example #9
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 6 votes |
@Override public void saveUser(User user) { user.getIoLock().lock(); try { if (!this.plugin.getUserManager().shouldSave(user)) { saveFile(StorageLocation.USER, user.getUniqueId().toString(), null); } else { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("uuid").setValue(user.getUniqueId().toString()); } data.getNode("name").setValue(user.getUsername().orElse("null")); data.getNode(this.loader instanceof JsonLoader ? "primaryGroup" : "primary-group").setValue(user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME)); writeNodes(data, user.normalData().immutable().values()); saveFile(StorageLocation.USER, user.getUniqueId().toString(), data); } } catch (Exception e) { throw reportException(user.getUniqueId().toString(), e); } finally { user.getIoLock().unlock(); } }
Example #10
Source File: Configuration.java From Prism with MIT License | 6 votes |
public void loadConfiguration() { try { ConfigurationNode configurationNode = getConfigurationLoader().load(); if (!configurationNode.isVirtual() && configurationNode.getNode("general", "schema-version").isVirtual()) { Prism.getInstance().getLogger().info("Converting Configuration..."); convertConfiguration(configurationNode); } else { getObjectMapper().populate(configurationNode); } Prism.getInstance().getLogger().info("Successfully loaded configuration file."); } catch (Exception ex) { Prism.getInstance().getLogger().error("Encountered an error while loading config", ex); } }
Example #11
Source File: ContextSetConfigurateSerializer.java From LuckPerms with MIT License | 6 votes |
public static ContextSet deserializeContextSet(ConfigurationNode data) { Preconditions.checkArgument(data.hasMapChildren()); Map<Object, ? extends ConfigurationNode> dataMap = data.getChildrenMap(); if (dataMap.isEmpty()) { return ImmutableContextSetImpl.EMPTY; } MutableContextSet map = new MutableContextSetImpl(); for (Map.Entry<Object, ? extends ConfigurationNode> e : dataMap.entrySet()) { String k = e.getKey().toString(); ConfigurationNode v = e.getValue(); if (v.hasListChildren()) { List<? extends ConfigurationNode> values = v.getChildrenList(); for (ConfigurationNode value : values) { map.add(k, value.getString()); } } else { map.add(k, v.getString()); } } return map; }
Example #12
Source File: VirtualChestItemStackSerializer.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private <T, U extends BaseValue<T>> void deserializeForKeys( ConfigurationNode node, DataQuery dataQuery, BiConsumer<Key<U>, T> consumer) throws InvalidDataException { if (KEYS.containsKey(dataQuery)) { try { @SuppressWarnings("unchecked") Key<U> key = (Key<U>) KEYS.get(dataQuery); @SuppressWarnings("unchecked") TypeToken<T> elementToken = (TypeToken<T>) key.getElementToken(); consumer.accept(key, Optional.ofNullable(node.getValue(elementToken)) .orElseThrow(() -> new InvalidDataException("No value present"))); } catch (ObjectMappingException e) { throw new InvalidDataException(e); } } else if (!EXCEPTIONS.contains(dataQuery)) { throw new InvalidDataException("No matched query present"); } }
Example #13
Source File: ClaimTypeSerializer.java From EagleFactions with MIT License | 6 votes |
@Override public Claim deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { Vector3i chunkPosition = Vector3i.ZERO; UUID worldUniqueId = new UUID(0, 0); Set<UUID> owners; boolean isAccessibleByFaction; try { worldUniqueId = value.getNode("worldUUID").getValue(TypeTokens.UUID_TOKEN, new UUID(0, 0)); chunkPosition = value.getNode("chunkPosition").getValue(TypeTokens.VECTOR_3I_TOKEN, Vector3i.ZERO); isAccessibleByFaction = value.getNode("accessibleByFaction").getBoolean(true); owners = new HashSet<>(value.getNode("owners").getList(TypeTokens.UUID_TOKEN, Collections.EMPTY_LIST)); } catch (Exception e) { throw new ObjectMappingException("Could not deserialize the claim: " + worldUniqueId.toString() + "|" + chunkPosition, e); } return new Claim(worldUniqueId, chunkPosition, owners, isAccessibleByFaction); }
Example #14
Source File: ConfigurationVersionUtil.java From AntiVPN with MIT License | 6 votes |
private static void to39(ConfigurationNode config) { // Add ip2proxy config.getNode("sources", "ip2proxy", "enabled").setValue(Boolean.TRUE); config.getNode("sources", "ip2proxy", "key").setValue("demo"); List<String> sources; try { sources = new ArrayList<>(config.getNode("sources", "order").getList(TypeToken.of(String.class))); } catch (Exception ex) { sources = new ArrayList<>(); } if (!sources.contains("ip2proxy")) { sources.add("ip2proxy"); } config.getNode("sources", "order").setValue(sources); // Version config.getNode("version").setValue(3.9d); }
Example #15
Source File: ConfigUtils.java From BlueMap with MIT License | 6 votes |
public static Vector4i readVector4i(ConfigurationNode vectorNode){ if (vectorNode.hasListChildren()){ List<? extends ConfigurationNode> list = vectorNode.getChildrenList(); return new Vector4i( list.get(0).getInt(), list.get(1).getInt(), list.get(2).getInt(), list.get(3).getInt() ); } return new Vector4i( vectorNode.getNode("x").getInt(), vectorNode.getNode("y").getInt(), vectorNode.getNode("z").getInt(), vectorNode.getNode("w").getInt() ); }
Example #16
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 5 votes |
private static void writeAttributesTo(ConfigurationNode attributes, Node node, boolean writeValue) { if (writeValue) { attributes.getNode("value").setValue(node.getValue()); } if (node.hasExpiry()) { attributes.getNode("expiry").setValue(node.getExpiry().getEpochSecond()); } if (!node.getContexts().isEmpty()) { attributes.getNode("context").setValue(ContextSetConfigurateSerializer.serializeContextSet(node.getContexts())); } }
Example #17
Source File: ConfigurationFileUtil.java From AntiVPN with MIT License | 5 votes |
public static Configuration getConfig(Plugin plugin, String resourcePath, File fileOnDisk) throws IOException { File parentDir = fileOnDisk.getParentFile(); if (parentDir.exists() && !parentDir.isDirectory()) { Files.delete(parentDir.toPath()); } if (!parentDir.exists()) { if (!parentDir.mkdirs()) { throw new IOException("Could not create parent directory structure."); } } if (fileOnDisk.exists() && fileOnDisk.isDirectory()) { Files.delete(fileOnDisk.toPath()); } if (!fileOnDisk.exists()) { try (InputStreamReader reader = new InputStreamReader(plugin.getResource(resourcePath)); BufferedReader in = new BufferedReader(reader); FileWriter writer = new FileWriter(fileOnDisk); BufferedWriter out = new BufferedWriter(writer)) { String line; while ((line = in.readLine()) != null) { out.write(line + System.lineSeparator()); } } } ConfigurationLoader<ConfigurationNode> loader = YAMLConfigurationLoader.builder().setFlowStyle(DumperOptions.FlowStyle.BLOCK).setIndent(2).setFile(fileOnDisk).build(); ConfigurationNode root = loader.load(ConfigurationOptions.defaults().setHeader("Comments are gone because update :(. Click here for new config + comments: https://www.spigotmc.org/resources/anti-vpn.58291/")); Configuration config = new Configuration(root); ConfigurationVersionUtil.conformVersion(loader, config, fileOnDisk); return config; }
Example #18
Source File: GameModeTypeSerializer.java From GriefDefender with MIT License | 5 votes |
@Override public GameModeType deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { switch(node.getString().toLowerCase()) { case "adventure" : return GameModeTypes.ADVENTURE; case "creative" : return GameModeTypes.CREATIVE; case "spectator" : return GameModeTypes.SPECTATOR; case "survival" : return GameModeTypes.SURVIVAL; default : return GameModeTypes.UNDEFINED; } }
Example #19
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 5 votes |
@Override public void serialize(TypeToken<?> type, Component obj, ConfigurationNode node) throws ObjectMappingException { if (obj == TextComponent.empty()) { node.setValue(""); } else { node.setValue(LegacyComponentSerializer.legacy().serialize(obj, '&')); } }
Example #20
Source File: MarkerSetImpl.java From BlueMap with MIT License | 5 votes |
public synchronized void save(ConfigurationNode node) { node.getNode("id").setValue(this.id); node.getNode("label").setValue(this.label); node.getNode("toggleable").setValue(this.toggleable); node.getNode("defaultHide").setValue(this.isDefaultHidden); for (MarkerImpl marker : markers.values()) { marker.save(node.getNode("marker").getAppendedNode()); } removedMarkers.clear(); this.hasUnsavedChanges = false; }
Example #21
Source File: IPHub.java From AntiVPN with MIT License | 5 votes |
public boolean getResult(String ip) throws APIException { if (ip == null) { throw new IllegalArgumentException("ip cannot be null."); } if (!ValidationUtil.isValidIp(ip)) { throw new IllegalArgumentException("ip is invalid."); } ConfigurationNode sourceConfigNode = getSourceConfigNode(); String key = sourceConfigNode.getNode("key").getString(); if (key == null || key.isEmpty()) { throw new APIException(true, "Key is not defined for " + getName()); } int blockType = sourceConfigNode.getNode("block").getInt(1); Map<String, String> headers = new HashMap<>(); headers.put("X-Key", key); JSONObject json; try { json = JSONWebUtil.getJSONObject(new URL("https://v2.api.iphub.info/ip/" + ip), "GET", (int) getCachedConfig().getTimeout(), "egg82/AntiVPN", headers); } catch (IOException | ParseException | ClassCastException ex) { throw new APIException(false, "Could not get result from " + getName()); } if (json == null || json.get("block") == null) { throw new APIException(false, "Could not get result from " + getName()); } int block = ((Number) json.get("block")).intValue(); return block == blockType; }
Example #22
Source File: JsonLoader.java From LuckPerms with MIT License | 5 votes |
@Override public ConfigurationLoader<? extends ConfigurationNode> loader(Path path) { return GsonConfigurationLoader.builder() .setIndent(2) .setSource(() -> Files.newBufferedReader(path, StandardCharsets.UTF_8)) .setSink(() -> Files.newBufferedWriter(path, StandardCharsets.UTF_8)) .build(); }
Example #23
Source File: ShapeMarkerImpl.java From BlueMap with MIT License | 5 votes |
private static void writeShape(ConfigurationNode node, Shape shape) { for (int i = 0; i < shape.getPointCount(); i++) { ConfigurationNode pointNode = node.getAppendedNode(); Vector2d point = shape.getPoint(i); pointNode.getNode("x").setValue(Math.round(point.getX() * 1000d) / 1000d); pointNode.getNode("z").setValue(Math.round(point.getY() * 1000d) / 1000d); } }
Example #24
Source File: ConfigurateConfigAdapter.java From LuckPerms with MIT License | 5 votes |
@Override public List<String> getKeys(String path, List<String> def) { ConfigurationNode node = resolvePath(path); if (node.isVirtual() || !node.hasMapChildren()) { return def; } return node.getChildrenMap().keySet().stream().map(Object::toString).collect(Collectors.toList()); }
Example #25
Source File: Utils.java From EssentialCmds with MIT License | 5 votes |
public static void removeBlacklistItem(String itemId) { ConfigurationNode blacklistNode = Configs.getConfig(mainConfig).getNode("essentialcmds", "items", "blacklist"); String blacklist = blacklistNode.getString(); String newValue = blacklist.replace(itemId + ",", ""); Configs.setValue(mainConfig, blacklistNode.getPath(), newValue); }
Example #26
Source File: SecurityService.java From Web-API with MIT License | 5 votes |
/** * Returns a permissions tree representing the passed configuration node * @param config The configuration node which represents a permission set * @return A tree structure representing the config node */ public static TreeNode permissionTreeFromConfig(ConfigurationNode config) { if (config == null || config.getValue() == null) { return new TreeNode(false); } if (!config.hasMapChildren()) { if (config.getValue().getClass() == Boolean.class) return new TreeNode(config.getKey().toString(), config.getBoolean()); else { TreeNode node = new TreeNode(config.getKey().toString(), true); node.addChild(new TreeNode("*", true)); return node; } } TreeNode root = new TreeNode(config.getKey().toString(), true); for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) { if (entry.getKey().toString().equalsIgnoreCase(".")) { root.setValue(entry.getValue().getBoolean()); continue; } root.addChild(permissionTreeFromConfig(entry.getValue())); } return root; }
Example #27
Source File: ConfigurationVersionUtil.java From AntiVPN with MIT License | 5 votes |
private static void to20(ConfigurationNode config) { // Rabbit -> Messaging boolean rabbitEnabled = config.getNode("rabbit", "enabled").getBoolean(); String rabbitAddress = config.getNode("rabbit", "address").getString(""); int rabbitPort = config.getNode("rabbit", "port").getInt(5672); String rabbitUser = config.getNode("rabbit", "user").getString("guest"); String rabbitPass = config.getNode("rabbit", "pass").getString("guest"); config.removeChild("rabbit"); config.getNode("messaging", "type").setValue((rabbitEnabled) ? "rabbit" : "bungee"); config.getNode("messaging", "rabbit", "address").setValue(rabbitAddress); config.getNode("messaging", "rabbit", "port").setValue(rabbitPort); config.getNode("messaging", "rabbit", "user").setValue(rabbitUser); config.getNode("messaging", "rabbit", "pass").setValue(rabbitPass); // sources.order String -> List String[] order = config.getNode("sources", "order").getString("").split(",\\s?"); config.getNode("sources", "order").setValue(Arrays.asList(order)); // Add ignore config.getNode("ignore").setValue(Arrays.asList("127.0.0.1", "localhost", "::1")); // Remove async config.removeChild("async"); // Version config.getNode("version").setValue(2.0d); }
Example #28
Source File: ShapeMarkerImpl.java From BlueMap with MIT License | 5 votes |
@Override public void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwriteChanges) throws MarkerFileFormatException { super.load(api, markerNode, overwriteChanges); if (!overwriteChanges && hasUnsavedChanges) return; this.hasUnsavedChanges = false; this.shape = readShape(markerNode.getNode("shape")); this.height = markerNode.getNode("height").getFloat(64); this.depthTest = markerNode.getNode("depthTest").getBoolean(true); this.borderColor = readColor(markerNode.getNode("borderColor")); this.fillColor = readColor(markerNode.getNode("fillColor")); }
Example #29
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 5 votes |
@Override public Optional<Track> loadTrack(String name) { Track track = this.plugin.getTrackManager().getIfLoaded(name); if (track != null) { track.getIoLock().lock(); } try { ConfigurationNode object = readFile(StorageLocation.TRACK, name); if (object == null) { return Optional.empty(); } if (track == null) { track = this.plugin.getTrackManager().getOrMake(name); track.getIoLock().lock(); } List<String> groups = object.getNode("groups").getChildrenList().stream() .map(ConfigurationNode::getString) .collect(ImmutableCollectors.toList()); track.setGroups(groups); } catch (Exception e) { throw reportException(name, e); } finally { if (track != null) { track.getIoLock().unlock(); } } return Optional.of(track); }
Example #30
Source File: ConfigFactory.java From helper with MIT License | 5 votes |
@Nonnull public static <T> T generate(@Nonnull Class<T> clazz, @Nonnull ConfigurationNode node) { try { return classMapper(clazz).bindToNew().populate(node); } catch (ObjectMappingException e) { throw new ConfigurationException(e); } }