Java Code Examples for ninja.leaping.configurate.SimpleConfigurationNode#root()
The following examples show how to use
ninja.leaping.configurate.SimpleConfigurationNode#root() .
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: VirtualChestItemStackSerializer.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private Optional<Object> deserializeItemEnchantment(String s) { try { int colonFirst = s.indexOf(':'), colonIndex = s.lastIndexOf(':'); String enchantmentId = colonFirst == colonIndex ? s : s.substring(0, colonIndex); int enchantmentLevel = colonFirst == colonIndex ? 1 : Coerce.toInteger(s.substring(colonIndex + 1)); ConfigurationNode node = SimpleConfigurationNode.root(/* default deserializer */); node.getNode(Queries.ENCHANTMENT_ID.toString()).setValue(enchantmentId); node.getNode(Queries.LEVEL.toString()).setValue(enchantmentLevel); return Optional.ofNullable(node.getValue(ITEM_ENCHANTMENT)); } catch (Exception e) { return Optional.empty(); } }
Example 2
Source File: ContextSetConfigurateSerializer.java From LuckPerms with MIT License | 6 votes |
public static ConfigurationNode serializeContextSet(ContextSet contextSet) { ConfigurationNode data = SimpleConfigurationNode.root(); Map<String, Set<String>> map = contextSet.toMap(); for (Map.Entry<String, Set<String>> entry : map.entrySet()) { List<String> values = new ArrayList<>(entry.getValue()); int size = values.size(); if (size == 1) { data.getNode(entry.getKey()).setValue(values.get(0)); } else if (size > 1) { data.getNode(entry.getKey()).setValue(values); } } return data; }
Example 3
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 4
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 6 votes |
@Override public Group createAndLoadGroup(String name) { Group group = this.plugin.getGroupManager().getOrMake(name); group.getIoLock().lock(); try { ConfigurationNode object = readFile(StorageLocation.GROUP, name); if (object != null) { group.setNodes(DataType.NORMAL, readNodes(object)); } else { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("name").setValue(group.getName()); } writeNodes(data, group.normalData().immutable().values()); saveFile(StorageLocation.GROUP, name, data); } } catch (Exception e) { throw reportException(name, e); } finally { group.getIoLock().unlock(); } return group; }
Example 5
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 6 votes |
@Override public void saveGroup(Group group) { group.getIoLock().lock(); try { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("name").setValue(group.getName()); } writeNodes(data, group.normalData().immutable().values()); saveFile(StorageLocation.GROUP, group.getName(), data); } catch (Exception e) { throw reportException(group.getName(), e); } finally { group.getIoLock().unlock(); } }
Example 6
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 6 votes |
@Override public void saveTrack(Track track) { track.getIoLock().lock(); try { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("name").setValue(track.getName()); } data.getNode("groups").setValue(track.getGroups()); saveFile(StorageLocation.TRACK, track.getName(), data); } catch (Exception e) { throw reportException(track.getName(), e); } finally { track.getIoLock().unlock(); } }
Example 7
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 5 votes |
@Override public Track createAndLoadTrack(String name) { Track track = this.plugin.getTrackManager().getOrMake(name); track.getIoLock().lock(); try { ConfigurationNode object = readFile(StorageLocation.TRACK, name); if (object != null) { List<String> groups = object.getNode("groups").getChildrenList().stream() .map(ConfigurationNode::getString) .collect(ImmutableCollectors.toList()); track.setGroups(groups); } else { ConfigurationNode data = SimpleConfigurationNode.root(); if (this instanceof SeparatedConfigurateStorage) { data.getNode("name").setValue(name); } data.getNode("groups").setValue(track.getGroups()); saveFile(StorageLocation.TRACK, name, data); } } catch (Exception e) { throw reportException(name, e); } finally { track.getIoLock().unlock(); } return track; }