package fr.aumgn.bukkitutils.localization;

import java.text.MessageFormat;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;

/**
 * A set of messages loaded with {@link Localization}
 */
public class PluginMessages {

    private Map<String, MessageFormat> map;

    public PluginMessages(Map<String, MessageFormat> map) {
        Validate.notNull(map);
        this.map = map;
    }

    public boolean has(String key) {
        Validate.notNull(key);
        return map.containsKey(key);
    }

    public String get(String key) {
        return get(key, new Object[0]);
    }

    public String get(String key, Object... arguments) {
        if (!map.containsKey(key)) {
            return ChatColor.RED + "## Missing message for key \""
                    + key + "\" ##";
        }

        MessageFormat message = map.get(key);
        return message.format(arguments);
    }

    public Set<String> keys() {
        return Collections.unmodifiableSet(map.keySet());
    }

    public Set<Entry<String, MessageFormat>> entries() {
        return Collections.unmodifiableSet(map.entrySet());
    }
}

@@ -243,16 +243,62 @@
 Color;%0A%0A
+import com.google.common.base.Preconditions;%0A%0A
 /**%0A * A
@@ -813,33 +813,501 @@
     
-if (!map.containsKey(key)
+String message = rawGet(key, arguments);%0A        if (message == null) %7B%0A            return keyNotFound(key);%0A        %7D%0A%0A        return message;%0A    %7D%0A%0A    public String get(String%5B%5D keys) %7B%0A        return get(keys, new Object%5B0%5D);%0A    %7D%0A%0A    public String get(String%5B%5D keys, Object... arguments) %7B%0A        Preconditions.checkArgument(keys.length %3E 0, %22Keys can't be empty%22);%0A        for (String key : keys) %7B%0A            String message = rawGet(key, arguments);%0A            if (message != null
 ) %7B%0A
@@ -1310,32 +1310,188 @@
 ) %7B%0A            
+  
+  return message;%0A            %7D%0A        %7D%0A%0A        return keyNotFound(keys%5Bkeys.length - 1%5D);%0A    %7D%0A%0A    private String keyNotFound(String key) %7B%0A        
 return ChatColor
@@ -1532,44 +1532,242 @@
  %5C%22%22
+ + key + %22%5C%22 ##%22;
 %0A    
+%7D%0A%0A
     
-            + key + %22%5C%22 ##%22
+public String rawGet(String key) %7B%0A        return rawGet(key, new Object%5B0%5D);%0A    %7D%0A%0A    public String rawGet(String key, Object... arguments) %7B%0A        if (!map.containsKey(key)) %7B%0A            return null
 ;%0A  

Add PluginMessages.get(String[] keys{, Object... arguments})