package com.hyperfresh.mchyperchat;

import com.hyperfresh.mchyperchat.field.Field;
import com.hyperfresh.mchyperchat.field.FieldManager;

import java.util.Collection;
import java.util.Map;

public class HyperChat
{
	private HyperChat()
	{

	}

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

	/**
	 * The currently used plugin.
	 */
	private static HyperChatPlugin plugin = null;

	private static ThemeManager themeManager = new ThemeManager();

	/**
	 * This will run when this plugin is enabled.
	 */
	public static void onEnable(HyperChatPlugin plugin)
	{
		HyperChat.plugin = plugin;
		//READ "field" FOLDER HERE
	}

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

	/**
	 * Gets the current console.
	 *
	 * @return the current console
	 */
	public static User getConsole()
	{
		return HyperChat.plugin.getConsole();
	}

	public static Collection<Player> getPlayers()
	{
		return HyperChat.plugin.getPlayers();
	}

	public static ThemeManager getThemeManager()
	{
		return themeManager;
	}

	/**
	 * Get the main list of field.
	 *
	 * @return the main list of field
	 */
	public static FieldManager getFieldManager()
	{
		return fieldManager;
	}

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

	/**
	 * Replaces all field in a string with their values.
	 * Fields are detected by the pattern <code>"${<field name>}"</code>
	 *
	 * @param str
	 * @param user
	 * @return
	 */
	public static String processDynamicFields(String str, User user)
	{
		for (Map.Entry<String, Field> e : fieldManager.getDynamicFields().entrySet())
		{
			str = str.replaceAll("(?i)\\$\\{" + e.getKey() + "\\}(?-i)", e.getValue().getFieldValue(user));
		}

		return str;
	}

	/**
	 * Replaces all field in a string with their values.
	 * Fields are detected by the pattern <code>"${<field name>}"</code>
	 * If {@code onlyConstants} is true, then only field marked as static
	 * will be replaced.
	 *
	 * @param str
	 * @return
	 */
	public static String processStaticFields(String str)
	{
		for (Map.Entry<String, Field> e : fieldManager.getStaticFields().entrySet())
		{
			str = str.replaceAll("(?i)\\$\\{" + e.getKey() + "\\}(?-i)", e.getValue().getFieldValue(null));
		}

		return str;
	}
}
@@ -275,18 +275,17 @@
  of 
-FieldList.
+HyperChat
 %0A%09 *
@@ -306,161 +306,171 @@
 tic 
-FieldManager fieldManager = new FieldManager();%0A%0A%09/**%0A%09 * The currently used plugin.%0A%09 */%0A%09private static HyperChatPlugin plugin = null;%0A%0A%09private static
+final HyperChat instance = new HyperChat();%0A%0A%09private HyperChatPlugin plugin = null;%0A%0A%09private final FieldManager fieldManager = new FieldManager();%0A%09private final
  The
@@ -576,31 +576,24 @@
  */%0A%09public 
-static 
 void onEnabl
@@ -619,33 +619,28 @@
 lugin)%0A%09%7B%0A%09%09
-HyperChat
+this
 .plugin = pl
@@ -740,31 +740,24 @@
  */%0A%09public 
-static 
 void onDisab
@@ -766,25 +766,20 @@
 ()%0A%09%7B%0A%09%09
-HyperChat
+this
 .plugin 
@@ -788,16 +788,21 @@
 null;%0A%09%09
+this.
 fieldMan
@@ -903,23 +903,16 @@
 %09public 
-static 
 User get
@@ -929,33 +929,28 @@
 %09%7B%0A%09%09return 
-HyperChat
+this
 .plugin.getC
@@ -971,23 +971,16 @@
 %09public 
-static 
 Collecti
@@ -1015,25 +1015,20 @@
 %09return 
-HyperChat
+this
 .plugin.
@@ -1053,23 +1053,16 @@
 %09public 
-static 
 ThemeMan
@@ -1096,16 +1096,21 @@
 %09return 
+this.
 themeMan
@@ -1208,23 +1208,16 @@
 %09public 
-static 
 FieldMan
@@ -1251,16 +1251,21 @@
 %09return 
+this.
 fieldMan
@@ -1389,23 +1389,16 @@
 %09public 
-static 
 void res
@@ -1413,16 +1413,21 @@
 ()%0A%09%7B%0A%09%09
+this.
 fieldMan
@@ -1430,34 +1430,21 @@
 dManager
- = new FieldManage
+.clea
 r();%0A%09%7D%0A
@@ -1625,39 +1625,32 @@
 rn%0A%09 */%0A%09public 
-static 
 String processDy
@@ -1715,32 +1715,37 @@
 ing, Field%3E e : 
+this.
 fieldManager.get
@@ -2164,23 +2164,16 @@
 %09public 
-static 
 String p
@@ -2242,16 +2242,21 @@
 ld%3E e : 
+this.
 fieldMan

convert HyperChat class to singleton