package net.ghostrealms.lib;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

/**
 * Created by Cliff on 8/23/2015.
 */
public class GhostMessage
{
    public static final String TITLE = ChatColor.GRAY + "[Realms] " + ChatColor.WHITE;

    public static void messagePlayer(Player player, String msg, boolean title)
    {
        if(title)
            player.sendMessage(TITLE + formatMessage(msg));
        else
            player.sendMessage(formatMessage(msg));
    }

    public static void broadcast(String msg, boolean title)
    {
        if(title)
            Bukkit.getServer().broadcastMessage(TITLE + formatMessage(msg));
        else
            Bukkit.getServer().broadcastMessage(formatMessage(msg));
    }

    /*
        Replaces color markers with bukkit chat color characters
     */
    public static String formatMessage(String msg)
    {
        if(msg.contains("&0"))
            msg.replace("&0", ChatColor.BLACK.toString());
        if(msg.contains("&1"))
            msg.replace("&1", ChatColor.DARK_BLUE.toString());
        if(msg.contains("&2"))
            msg.replace("&2", ChatColor.DARK_GREEN.toString());
        if(msg.contains("&3"))
            msg.replace("&3", ChatColor.DARK_AQUA.toString());
        if(msg.contains("&4"))
            msg.replace("&4", ChatColor.DARK_RED.toString());
        if(msg.contains("&5"))
            msg.replace("&5", ChatColor.DARK_PURPLE.toString());
        if(msg.contains("&6"))
            msg.replace("&6", ChatColor.GOLD.toString());
        if(msg.contains("&7"))
            msg.replace("&7", ChatColor.GRAY.toString());
        if(msg.contains("&8"))
            msg.replace("&8", ChatColor.DARK_GRAY.toString());
        if(msg.contains("&9"))
            msg.replace("&9", ChatColor.BLUE.toString());
        if(msg.contains("&a"))
            msg.replace("&a", ChatColor.GREEN.toString());
        if(msg.contains("&b"))
            msg.replace("&b", ChatColor.AQUA.toString());
        if(msg.contains("&c"))
            msg.replace("&c", ChatColor.RED.toString());
        if(msg.contains("&d"))
            msg.replace("&d", ChatColor.LIGHT_PURPLE.toString());
        if(msg.contains("&e"))
            msg.replace("&e", ChatColor.YELLOW.toString());
        if(msg.contains("&f"))
            msg.replace("&f", ChatColor.WHITE.toString());

        return msg;
    }

}

@@ -926,32 +926,38 @@
 0%22))%0A           
+ msg =
  msg.replace(%22&0
@@ -952,16 +952,19 @@
 .replace
+All
 (%22&0%22, C
@@ -1025,32 +1025,38 @@
 1%22))%0A           
+ msg =
  msg.replace(%22&1
@@ -1051,16 +1051,19 @@
 .replace
+All
 (%22&1%22, C
@@ -1128,32 +1128,38 @@
 2%22))%0A           
+ msg =
  msg.replace(%22&2
@@ -1154,16 +1154,19 @@
 .replace
+All
 (%22&2%22, C
@@ -1232,32 +1232,38 @@
 3%22))%0A           
+ msg =
  msg.replace(%22&3
@@ -1258,16 +1258,19 @@
 .replace
+All
 (%22&3%22, C
@@ -1335,32 +1335,38 @@
 4%22))%0A           
+ msg =
  msg.replace(%22&4
@@ -1361,16 +1361,19 @@
 .replace
+All
 (%22&4%22, C
@@ -1437,32 +1437,38 @@
 5%22))%0A           
+ msg =
  msg.replace(%22&5
@@ -1463,16 +1463,19 @@
 .replace
+All
 (%22&5%22, C
@@ -1542,32 +1542,38 @@
 6%22))%0A           
+ msg =
  msg.replace(%22&6
@@ -1568,16 +1568,19 @@
 .replace
+All
 (%22&6%22, C
@@ -1640,32 +1640,38 @@
 7%22))%0A           
+ msg =
  msg.replace(%22&7
@@ -1666,16 +1666,19 @@
 .replace
+All
 (%22&7%22, C
@@ -1738,32 +1738,38 @@
 8%22))%0A           
+ msg =
  msg.replace(%22&8
@@ -1764,16 +1764,19 @@
 .replace
+All
 (%22&8%22, C
@@ -1841,32 +1841,38 @@
 9%22))%0A           
+ msg =
  msg.replace(%22&9
@@ -1867,16 +1867,19 @@
 .replace
+All
 (%22&9%22, C
@@ -1939,32 +1939,38 @@
 a%22))%0A           
+ msg =
  msg.replace(%22&a
@@ -1965,16 +1965,19 @@
 .replace
+All
 (%22&a%22, C
@@ -2038,32 +2038,38 @@
 b%22))%0A           
+ msg =
  msg.replace(%22&b
@@ -2064,16 +2064,19 @@
 .replace
+All
 (%22&b%22, C
@@ -2136,32 +2136,38 @@
 c%22))%0A           
+ msg =
  msg.replace(%22&c
@@ -2162,16 +2162,19 @@
 .replace
+All
 (%22&c%22, C
@@ -2233,32 +2233,38 @@
 d%22))%0A           
+ msg =
  msg.replace(%22&d
@@ -2259,16 +2259,19 @@
 .replace
+All
 (%22&d%22, C
@@ -2339,32 +2339,38 @@
 e%22))%0A           
+ msg =
  msg.replace(%22&e
@@ -2365,16 +2365,19 @@
 .replace
+All
 (%22&e%22, C
@@ -2443,24 +2443,30 @@
 %0A           
+ msg =
  msg.replace
@@ -2465,16 +2465,19 @@
 .replace
+All
 (%22&f%22, C

Fix formatting issue