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

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#getString() . 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: ComponentConfigSerializer.java    From GriefDefender with MIT License 6 votes vote down vote up
@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 2
Source File: ComponentConfigSerializer.java    From GriefDefender with MIT License 6 votes vote down vote up
@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: 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 4
Source File: Utils.java    From EssentialCmds with MIT License 5 votes vote down vote up
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 5
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 6
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 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 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 9
Source File: VirtualChestItemStackSerializer.java    From VirtualChest with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Text deserialize(TypeToken<?> t, ConfigurationNode value) throws ObjectMappingException
{
    String string = value.getString();
    return string == null ? null : TextSerializers.FORMATTING_CODE.deserialize(string);
}