package com.hyperfresh.mchyperchat;

import java.util.Map;

public class HyperChat
{
	private HyperChat()
	{
	}

	/**
	 * The current instance of FieldList.
	 */
	private static FieldList FIELD_LIST = new FieldList();

	/**
	 * This will run when this plugin is enabled.
	 */
	public static void onEnable()
	{
		//READ "fields" FOLDER HERE
	}

	/**
	 * This will run when this plugin is disabled.
	 */
	public static void onDisable()
	{
		FIELD_LIST.clear();
	}

	/**
	 * Get the main list of fields.
	 *
	 * @return the main list of fields
	 */
	public static FieldList getFields()
	{
		return FIELD_LIST;
	}

	/**
	 * Replaces the existing FieldList with a new one,
	 * effectively deleting all existing fields.
	 */
	public static void resetFields()
	{
		FIELD_LIST = new FieldList();
	}

	/**
	 * Replaces all fields in a string with their values.
	 * Fields are detected by the pattern <code>"${<field name>}"</code>
	 *
	 * @param str
	 * @return
	 */
	public static String processString(String str)
	{
		return processString(str, false);
	}

	public static String processString(String str, boolean staticOnly)
	{
		for (Map.Entry<String, Field> e : FIELD_LIST.entrySet())
		{
			str = str.replaceAll("(?i)\\$\\{" + e.getKey() + "\\}(?-i)", e.getValue().getFieldValue(null));
		}

		return str;
	}
}
@@ -1042,16 +1042,301 @@
 e);%0A%09%7D%0A%0A
+%09/**%0A%09 * Replaces all fields in a string with their values.%0A%09 * Fields are detected by the pattern %3Ccode%3E%22$%7B%3Cfield name%3E%7D%22%3C/code%3E%0A%09 * If %7B@code onlyConstants%7D is true, then only fields marked as static%0A%09 * will be replaced.%0A%09 *%0A%09 * @param str%0A%09 * @param onlyConstants%0A%09 * @return%0A%09 */%0A
 %09public 
@@ -1387,18 +1387,21 @@
 ean 
-staticOnly
+onlyConstants
 )%0A%09%7B
@@ -1464,16 +1464,73 @@
 ())%0A%09%09%7B%0A
+%09%09%09if(!onlyConstants %7C%7C !e.getValue().isDynamic())%0A%09%09%09%7B%0A%09
 %09%09%09str =
@@ -1620,16 +1620,21 @@
 null));%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%09r

update processString(String, boolean) with documentation