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

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#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: Utils.java    From EssentialCmds with MIT License 6 votes vote down vote up
public static Text getJoinMsg(String name)
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("message.join").split("\\."));
	String message;

	if (valueNode.getValue() != null)
	{
		message = valueNode.getString();
	}
	else
	{
		Utils.setJoinMsg("&4Welcome");
		message = "&4Welcome";
	}

	if ((message.contains("https://")) || (message.contains("http://")))
	{
		return Utils.getURL(message);
	}

	return TextSerializers.FORMATTING_CODE.deserialize(message.replaceAll("@p", name));
}
 
Example 2
Source File: ConfigUtils.java    From BlueMap with MIT License 6 votes vote down vote up
/**
 * 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 3
Source File: ConfigTabControl.java    From ChatUI with MIT License 6 votes vote down vote up
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 4
Source File: ConfigurateConfigAdapter.java    From LuckPerms with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getStringMap(String path, Map<String, String> def) {
    ConfigurationNode node = resolvePath(path);
    if (node.isVirtual()) {
        return def;
    }

    Map<String, Object> m = (Map<String, Object>) node.getValue(Collections.emptyMap());
    return m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().toString()));
}
 
Example 5
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static boolean shouldAnnounceAFK()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("afk.announce").split("\\."));

	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 getAFKKick()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("afk.kick.use").split("\\."));

	if (valueNode.getValue() != null)
	{
		return valueNode.getBoolean();
	}
	else
	{
		Utils.setAFKKick(false);
		return false;
	}
}
 
Example 7
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static ArrayList<String> getRules()
{
	ConfigurationNode valueNode = Configs.getConfig(rulesConfig).getNode((Object[]) ("rules.rules").split("\\."));

	if (valueNode.getValue() == null)
		return Lists.newArrayList();

	String list = valueNode.getString();
	ArrayList<String> rulesList = Lists.newArrayList();
	boolean finished = false;
	int endIndex = list.indexOf(",");

	if (endIndex != -1)
	{
		String substring = list.substring(0, endIndex);
		rulesList.add(substring);

		while (!finished)
		{
			int startIndex = endIndex;
			endIndex = list.indexOf(",", startIndex + 1);

			if (endIndex != -1)
			{
				String substrings = list.substring(startIndex + 1, endIndex);
				rulesList.add(substrings);
			}
			else
			{
				finished = true;
			}
		}
	}

	return rulesList;
}
 
Example 8
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static String getLastChatCharReplacement()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("chat.lastcharacter").split("\\."));
	if (valueNode.getValue() != null)
	{
		return valueNode.getString();
	}
	else
	{
		Utils.setLastChatCharReplacement(">");
		return ">";
	}
}
 
Example 9
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static String getFirstChatCharReplacement()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("chat.firstcharacter").split("\\."));
	if (valueNode.getValue() != null)
	{
		return valueNode.getString();
	}
	else
	{
		Utils.setFirstChatCharReplacement("<");
		return "<";
	}
}
 
Example 10
Source File: SecurityService.java    From Web-API with MIT License 5 votes vote down vote up
/**
 * 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 11
Source File: PartiesFileDispatcher.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
private PartyPlayerImpl getPlayerFromNode(ConfigurationNode node) {
	PartyPlayerImpl ret = null;
	if (node != null && node.getValue() != null) {
		ret = ((PartiesPlugin) plugin).getPlayerManager().initializePlayer(UUID.fromString(node.getKey().toString()));
		ret.fromDatabase(
				node.getNode("party").getString(""),
				node.getNode("rank").getInt(),
				node.getNode("options", "spy").getBoolean(false),
				node.getNode("options", "mute").getBoolean(false)
		);
	}
	return ret;
}
 
Example 12
Source File: ClaimSetTypeSerializer.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public Set<Claim> deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException
{
    final Set<Claim> claims = new HashSet<>();
    final List<? extends ConfigurationNode> nodes = value.getChildrenList();
    for (final ConfigurationNode configurationNode : nodes)
    {
        final Claim claim = configurationNode.getValue(EFTypeSerializers.CLAIM_TYPE_TOKEN);
        if (claim != null)
            claims.add(claim);
    }
    return claims;
}
 
Example 13
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static List<String> getBlacklistItems()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode("essentialcmds", "items", "blacklist");

	if (valueNode.getValue() == null || valueNode.getString().length() == 0)
	{
		return Lists.newArrayList();
	}

	String list = valueNode.getString();

	List<String> itemList = Lists.newArrayList();
	boolean finished = false;
	int endIndex = list.indexOf(",");

	if (endIndex != -1)
	{
		String substring = list.substring(0, endIndex);
		itemList.add(substring);

		while (!finished)
		{
			int startIndex = endIndex;
			endIndex = list.indexOf(",", startIndex + 1);

			if (endIndex != -1)
			{
				String substrings = list.substring(startIndex + 1, endIndex);
				itemList.add(substrings);
			}
			else
			{
				finished = true;
			}
		}
	}

	return itemList;
}
 
Example 14
Source File: GsonTypeSerializer.java    From helper with MIT License 5 votes vote down vote up
@Override
public JsonElement deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException {
    if (from.getValue() == null) {
        return JsonNull.INSTANCE;
    }

    if (from.hasListChildren()) {
        List<? extends ConfigurationNode> childrenList = from.getChildrenList();
        JsonArray array = new JsonArray();
        for (ConfigurationNode node : childrenList) {
            array.add(node.getValue(TYPE));
        }
        return array;
    }

    if (from.hasMapChildren()) {
        Map<Object, ? extends ConfigurationNode> childrenMap = from.getChildrenMap();
        JsonObject object = new JsonObject();
        for (Map.Entry<Object, ? extends ConfigurationNode> ent : childrenMap.entrySet()) {
            object.add(ent.getKey().toString(), ent.getValue().getValue(TYPE));
        }
        return object;
    }

    Object val = from.getValue();
    try {
        return GsonConverters.IMMUTABLE.wrap(val);
    } catch (IllegalArgumentException e) {
        throw new ObjectMappingException(e);
    }
}
 
Example 15
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
public static double getAFKKickTimer()
{
	ConfigurationNode valueNode = Configs.getConfig(mainConfig).getNode((Object[]) ("afk.kick.timer").split("\\."));

	if (valueNode.getValue() != null)
	{
		return valueNode.getDouble();
	}
	else
	{
		Utils.setAFKKickTimer(30000);
		ConfigurationNode valNode = Configs.getConfig(mainConfig).getNode((Object[]) ("afk.timer").split("\\."));
		return valNode.getDouble();
	}
}
 
Example 16
Source File: ClaimTypeSerializer.java    From GriefDefender with MIT License 5 votes vote down vote up
@Override
public ClaimType deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException {
    ClaimType ret = ClaimTypeRegistryModule.getInstance().getById(node.getString().toLowerCase()).orElse(null);
    if (ret == null) {
        throw new ObjectMappingException("Input '" + node.getValue() + "' was not a valid value for type " + type);
    }
    return ret;
}
 
Example 17
Source File: ItemStackSnapshotSerializer.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public ItemStackSnapshot deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException {
    ItemStack item = node.getValue(TypeToken.of(ItemStack.class));
    return item.createSnapshot();
}
 
Example 18
Source File: ItemStackSerializer.java    From EssentialCmds with MIT License 4 votes vote down vote up
public static Object serializeItemStack(ItemStack itemStack)
{
	ConfigurationNode node = ConfigurateTranslator.instance().translateData(itemStack.toContainer());
	return node.getValue();
}
 
Example 19
Source File: Text3TypeSerializer.java    From helper with MIT License 4 votes vote down vote up
@Override
public Component deserialize(TypeToken<?> typeToken, ConfigurationNode node) throws ObjectMappingException {
    JsonElement json = node.getValue(TypeToken.of(JsonElement.class));
    return GsonProvider.standard().fromJson(json, typeToken.getType());
}
 
Example 20
Source File: TextTypeSerializer.java    From helper with MIT License 4 votes vote down vote up
@Override
public Component deserialize(TypeToken<?> typeToken, ConfigurationNode node) throws ObjectMappingException {
    JsonElement json = node.getValue(TypeToken.of(JsonElement.class));
    return DELEGATE.deserialize(json, typeToken.getType(), new GsonContext());
}