Java Code Examples for ninja.leaping.configurate.commented.CommentedConfigurationNode#getValue()

The following examples show how to use ninja.leaping.configurate.commented.CommentedConfigurationNode#getValue() . 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: BloodEffects.java    From UltimateCore with MIT License 6 votes vote down vote up
public static void reload() {
    effects.clear();
    ModuleConfig config = Modules.BLOOD.get().getConfig().get();
    for (EntityType type : Sponge.getRegistry().getAllOf(CatalogTypes.ENTITY_TYPE)) {
        CommentedConfigurationNode node = config.get().getNode("types", type.getId());
        try {
            BloodEffect effect = node.getValue(TypeToken.of(BloodEffect.class));
            if (effect == null) {
                continue;
            }
            effects.put(type, effect);
        } catch (ObjectMappingException e) {
            ErrorLogger.log(e, "Failed to deserialize bloodeffect for " + type.getId() + " (" + e.getMessage() + ")");
        }
    }
}
 
Example 2
Source File: Utils.java    From EssentialCmds with MIT License 6 votes vote down vote up
public static void removeLockedWeatherWorld(UUID worldUuid)
{
	CommentedConfigurationNode valueNode = Configs.getConfig(worldConfig).getNode("world", "weather", "locked");

	if (valueNode.getValue() != null)
	{
		if (valueNode.getString().contains(worldUuid.toString() + ", "))
		{
			Configs.setValue(worldConfig, valueNode.getPath(), valueNode.getString().replace(worldUuid.toString() + ", ", ""));
		}
		else
		{
			Configs.setValue(worldConfig, valueNode.getPath(), valueNode.getString().replace(worldUuid.toString(), ""));
		}
	}
}
 
Example 3
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean isTeleportCooldownEnabled()
{
	CommentedConfigurationNode node = Configs.getConfig(mainConfig).getNode("teleport", "cooldown", "enabled");

	if (node.getValue() != null)
		return node.getBoolean();
	else
		Utils.setTeleportCooldownEnabled(false);

	return false;
}
 
Example 4
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean isOtherCommandLoggingEnabled()
{
	CommentedConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode("log", "command", "other");

	if (valueNode.getValue() != null)
	{
		return valueNode.getBoolean();
	}
	else
	{
		Configs.setValue(mainConfig, valueNode.getPath(), true);
		return true;
	}
}
 
Example 5
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean isCommandBlockCommandLoggingEnabled()
{
	CommentedConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode("log", "command", "command-block");

	if (valueNode.getValue() != null)
	{
		return valueNode.getBoolean();
	}
	else
	{
		Configs.setValue(mainConfig, valueNode.getPath(), true);
		return true;
	}
}
 
Example 6
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean isConsoleCommandLoggingEnabled()
{
	CommentedConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode("log", "command", "console");

	if (valueNode.getValue() != null)
	{
		return valueNode.getBoolean();
	}
	else
	{
		Configs.setValue(mainConfig, valueNode.getPath(), true);
		return true;
	}
}
 
Example 7
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean isPlayerCommandLoggingEnabled()
{
	CommentedConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode("log", "command", "player");

	if (valueNode.getValue() != null)
	{
		return valueNode.getBoolean();
	}
	else
	{
		Configs.setValue(mainConfig, valueNode.getPath(), true);
		return true;
	}
}
 
Example 8
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static void addLockedWeatherWorld(UUID worldUuid)
{
	CommentedConfigurationNode valueNode = Configs.getConfig(worldConfig).getNode("world", "weather", "locked");

	if (valueNode.getValue() != null)
	{
		Configs.setValue(worldConfig, valueNode.getPath(), valueNode.getString() + ", " + worldUuid.toString());
	}
	else
	{
		Configs.setValue(worldConfig, valueNode.getPath(), worldUuid.toString());
	}
}
 
Example 9
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static List<String> getLockedWeatherWorlds()
{
	CommentedConfigurationNode valueNode = Configs.getConfig(worldConfig).getNode("world", "weather", "locked");

	if (valueNode.getValue() != null)
	{
		List<String> worlds = Arrays.asList(valueNode.getString().split("\\s*,\\s*"));
		return worlds;
	}
	else
	{
		return Lists.newArrayList();
	}
}
 
Example 10
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean areBlacklistMsgsEnabled()
{
	CommentedConfigurationNode node = Configs.getConfig(mainConfig).getNode("blacklist", "messages");

	if (node.getValue() != null)
		return node.getBoolean();
	else
		Configs.setValue(mainConfig, node.getPath(), true);

	return true;
}
 
Example 11
Source File: ConfigManager.java    From EssentialCmds with MIT License 5 votes vote down vote up
private boolean checkNull(CommentedConfigurationNode node)
{
	if (node.getValue() == null)
		return true;
	else
		return false;
}
 
Example 12
Source File: ConfigHandler.java    From Nations with MIT License 5 votes vote down vote up
public static void ensureBoolean(CommentedConfigurationNode node, boolean def)
{
	if (!(node.getValue() instanceof Boolean))
	{
		node.setValue(def);
	}
}
 
Example 13
Source File: ConfigHandler.java    From Nations with MIT License 5 votes vote down vote up
public static void ensurePositiveNumber(CommentedConfigurationNode node, Number def)
{
	if (!(node.getValue() instanceof Number) || node.getDouble(-1) < 0)
	{
		node.setValue(def);
	}
}
 
Example 14
Source File: VirtualChestInventoryDispatcher.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Map<String, VirtualChestInventory> scanDir(File file)
{
    Map<String, VirtualChestInventory> newInventories = new LinkedHashMap<>();
    if (file.isDirectory() || file.mkdirs())
    {
        for (File f : Optional.ofNullable(file.listFiles()).orElse(new File[0]))
        {
            String fileName = f.getName();
            if (fileName.endsWith(".conf"))
            {
                String chestName = fileName.substring(0, fileName.lastIndexOf(".conf"));
                try
                {
                    HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setFile(f).build();
                    CommentedConfigurationNode menuRoot = loader.load().getNode(VirtualChestPlugin.PLUGIN_ID);
                    VirtualChestInventory inventory = menuRoot.getValue(TypeToken.of(VirtualChestInventory.class));
                    newInventories.put(chestName, Objects.requireNonNull(inventory));
                }
                catch (Exception e)
                {
                    this.logger.warn("Find error when reading a file (" + f.getAbsolutePath() +
                            "). Don't worry, we will skip this one and continue to read others", e);
                }
            }
        }
    }
    return newInventories;
}
 
Example 15
Source File: GriefDefenderConfig.java    From GriefDefender with MIT License 4 votes vote down vote up
/**
 * Traverses the given {@code root} config node, removing any values which
 * are also present and set to the same value on this configs "parent".
 *
 * @param root The node to process
 */
private void removeDuplicates(CommentedConfigurationNode root) {
    if (this.parent == null) {
        throw new IllegalStateException("parent is null");
    }

    Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root);
    while (it.hasNext()) {
        ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next();
        CommentedConfigurationNode node = next.getNode();

        // remove empty maps
        if (node.hasMapChildren()) {
            if (node.getChildrenMap().isEmpty()) {
                node.setValue(null);
            }
            continue;
        }

        // ignore list values
        if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) {
            continue;
        }

        // if the node already exists in the parent config, remove it
        CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray());
        if (Objects.equals(node.getValue(), parentValue.getValue())) {
            node.setValue(null);
        } else {
            // Fix list bug
            if (parentValue.getValue() == null) {
                if (node.getValueType() == ValueType.LIST) {
                    final List<?> nodeList = (List<?>) node.getValue();
                    if (nodeList.isEmpty()) {
                        node.setValue(null);
                    }
                    continue;
                }
            }
            // Fix double bug
            final Double nodeVal = node.getValue(Types::asDouble);
            if (nodeVal != null) {
                Double parentVal = parentValue.getValue(Types::asDouble);
                if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) {
                    node.setValue(null);
                    continue;
                }
            }
        }
    }
}
 
Example 16
Source File: GriefPreventionConfig.java    From GriefPrevention with MIT License 4 votes vote down vote up
/**
 * Traverses the given {@code root} config node, removing any values which
 * are also present and set to the same value on this configs "parent".
 *
 * @param root The node to process
 */
private void removeDuplicates(CommentedConfigurationNode root) {
    if (this.parent == null) {
        throw new IllegalStateException("parent is null");
    }

    Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root);
    while (it.hasNext()) {
        ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next();
        CommentedConfigurationNode node = next.getNode();

        // remove empty maps
        if (node.hasMapChildren()) {
            if (node.getChildrenMap().isEmpty()) {
                node.setValue(null);
            }
            continue;
        }

        // ignore list values
        if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) {
            continue;
        }

        // if the node already exists in the parent config, remove it
        CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray());
        if (Objects.equals(node.getValue(), parentValue.getValue())) {
            node.setValue(null);
        } else {
            // Fix list bug
            if (parentValue.getValue() == null) {
                if (node.getValueType() == ValueType.LIST) {
                    final List<?> nodeList = (List<?>) node.getValue();
                    if (nodeList.isEmpty()) {
                        node.setValue(null);
                    }
                    continue;
                }
            }
            // Fix double bug
            final Double nodeVal = node.getValue(Types::asDouble);
            if (nodeVal != null) {
                Double parentVal = parentValue.getValue(Types::asDouble);
                if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) {
                    node.setValue(null);
                    continue;
                }
            }
        }
    }
}
 
Example 17
Source File: GriefDefenderConfig.java    From GriefDefender with MIT License 4 votes vote down vote up
/**
 * Traverses the given {@code root} config node, removing any values which
 * are also present and set to the same value on this configs "parent".
 *
 * @param root The node to process
 */
private void removeDuplicates(CommentedConfigurationNode root) {
    if (this.parent == null) {
        throw new IllegalStateException("parent is null");
    }

    Iterator<ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode>> it = ConfigurationNodeWalker.DEPTH_FIRST_POST_ORDER.walkWithPath(root);
    while (it.hasNext()) {
        ConfigurationNodeWalker.VisitedNode<CommentedConfigurationNode> next = it.next();
        CommentedConfigurationNode node = next.getNode();

        // remove empty maps
        if (node.hasMapChildren()) {
            if (node.getChildrenMap().isEmpty()) {
                node.setValue(null);
            }
            continue;
        }

        // ignore list values
        if (node.getParent() != null && node.getParent().getValueType() == ValueType.LIST) {
            continue;
        }

        // if the node already exists in the parent config, remove it
        CommentedConfigurationNode parentValue = this.parent.data.getNode(next.getPath().getArray());
        if (Objects.equals(node.getValue(), parentValue.getValue())) {
            node.setValue(null);
        } else {
            // Fix list bug
            if (parentValue.getValue() == null) {
                if (node.getValueType() == ValueType.LIST) {
                    final List<?> nodeList = (List<?>) node.getValue();
                    if (nodeList.isEmpty()) {
                        node.setValue(null);
                    }
                    continue;
                }
            }
            // Fix double bug
            final Double nodeVal = node.getValue(Types::asDouble);
            if (nodeVal != null) {
                Double parentVal = parentValue.getValue(Types::asDouble);
                if (parentVal == null && nodeVal.doubleValue() == 0 || (parentVal != null && nodeVal.doubleValue() == parentVal.doubleValue())) {
                    node.setValue(null);
                    continue;
                }
            }
        }
    }
}