package com.elmakers.mine.bukkit.utility;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;


public class Messages {
    public static Map<String, String> messageMap = new HashMap<String, String>();
    public static ConfigurationSection configuration = null;

    public static void load(ConfigurationSection messages) {
        configuration = messages;
        Collection<String> keys = messages.getKeys(true);
        for (String key : keys) {
            messageMap.put(key, messages.getString(key));
        }
    }

    public static List<String> getAll(String path) {
        if (configuration == null) return new ArrayList<String>();
        return configuration.getStringList(path);
    }

    public static void reset() {
        messageMap.clear();
    }

    public static String get(String key, String defaultValue) {
        return messageMap.containsKey(key) ? ChatColor.translateAlternateColorCodes('&', messageMap.get(key)) : defaultValue;
    }

    public static String get(String key) {
        return get(key, key);
    }

    public static String getParameterized(String key, String paramName, String paramValue) {
        return get(key, key).replace(paramName, paramValue);
    }

    public static String getParameterized(String key, String paramName1, String paramValue1, String paramName2, String paramValue2) {
        return get(key, key).replace(paramName1, paramValue1).replace(paramName2, paramValue2);
    }
}

@@ -53,25 +53,17 @@
 va.util.
-ArrayList
+*
 ;%0Aimport
@@ -77,89 +77,21 @@
 til.
-Collection;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
+regex.Pattern
 ;%0A%0Ai
@@ -220,321 +220,1043 @@
 tic 
-Map%3CString, String%3E messageMap = new HashMap%3CString, String%3E();%0A    public static ConfigurationSection configuration = null;%0A%0A    public static void load(ConfigurationSection messages) %7B%0A        configuration = messages;%0A        Collection%3CString%3E keys = messages.getKeys(true);%0A        for (String key : keys) %7B%0A
+String PARAMETER_PATTERN_STRING = %22%5C%5C$(%5B%5E :%5D+)%22;%0A    public static Pattern PARAMETER_PATTERN = Pattern.compile(PARAMETER_PATTERN_STRING);%0A%0A    private static Map%3CString, String%3E messageMap = new HashMap%3CString, String%3E();%0A    private static Map%3CString, List%3CString%3E%3E randomized = new HashMap%3CString, List%3CString%3E%3E();%0A    private static ConfigurationSection configuration = null;%0A    private static Random random = new Random();%0A%0A    public static void load(ConfigurationSection messages) %7B%0A        configuration = messages;%0A        Collection%3CString%3E keys = messages.getKeys(true);%0A        for (String key : keys) %7B%0A            if (key.equals(%22randomized%22)) %7B%0A                ConfigurationSection randomSection = messages.getConfigurationSection(key);%0A                Set%3CString%3E randomKeys = randomSection.getKeys(false);%0A                for (String randomKey : randomKeys) %7B%0A                    randomized.put(randomKey, randomSection.getStringList(randomKey));%0A                %7D%0A            %7D else if (messages.isString(key)) %7B%0A    
     
@@ -1305,24 +1305,38 @@
 ring(key));%0A
+            %7D%0A
         %7D%0A  
@@ -2258,11 +2258,280 @@
 );%0A    %7D
+%0A%0A    public static String getRandomized(String key) %7B%0A        if (!randomized.containsKey(key)) return %22%22;%0A        List%3CString%3E options = randomized.get(key);%0A        if (options.size() == 0) return %22%22;%0A        return options.get(random.nextInt(options.size()));%0A    %7D
 %0A%7D%0A

Add some utility methods for randomized messaging