    public static String parseMessage(String pName, String world, String msg, String format) {
        Object prefix = Reader.getRawPrefix(pName, InfoType.USER, world);
        Object suffix = Reader.getRawSuffix(pName, InfoType.USER, world);
        Object group = Reader.getRawGroup(pName, InfoType.USER, world);
        String vI = ConfigType.MCHAT_VAR_INDICATOR.getString();
        if (msg == null)
            msg = "";
        if (prefix == null)
            prefix = "";
        if (suffix == null)
            suffix = "";
        if (group == null)
            group = "";
        String hSClass = "";
        String hClass = "";
        String hHealth = "";
        String hHBar = "";
        String hMana = "";
        String hMBar = "";
        String hParty = "";
        String hMastered = "";
        String hLevel = "";
        String hSLevel = "";
        String hExp = "";
        String hSExp = "";
        String hEBar = "";
        String hSEBar = "";
        String tTown = "";
        String tTownName = "";
        String tTitle = "";
        String tSurname = "";
        String tResidentName = "";
        String tPrefix = "";
        String tNamePrefix = "";
        String tPostfix = "";
        String tNamePostfix = "";
        String tNation = "";
        String tNationName = "";
        String tNationTag = "";
        Double locX = (double) randomNumber(-100, 100);
        Double locY = (double) randomNumber(-100, 100);
        Double locZ = (double) randomNumber(-100, 100);
        String loc = ("X: " + locX + ", " + "Y: " + locY + ", " + "Z: " + locZ);
        String healthbar = "";
        String health = String.valueOf(randomNumber(1, 20));
        String pWorld = "";
        String hungerLevel = String.valueOf(randomNumber(0, 20));
        String hungerBar = API.createBasicBar(randomNumber(0, 20), 20, 10);
        String level = String.valueOf(randomNumber(1, 2));
        String exp = String.valueOf(randomNumber(0, 200))+ "/" + ((randomNumber(1, 2) + 1) * 10);
        String expBar = API.createBasicBar(randomNumber(0, 200), ((randomNumber(1, 2) + 1) * 10), 10);
        String tExp = String.valueOf(randomNumber(0, 300));
        String gMode = String.valueOf(randomNumber(0, 1));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(LocaleType.FORMAT_DATE.getRaw());
        String time = dateFormat.format(now);
        String dName = pName;
        String dType = "";
        if (ConfigType.MCHAT_CHAT_DISTANCE.getDouble() > 0) {
            dType = LocaleType.FORMAT_LOCAL.getVal();
        }
        String sType = "";
        if (MChat.isSpying.get(pName) != null
                && MChat.isSpying.get(pName))
            sType = LocaleType.FORMAT_SPY.getVal();
        if (Bukkit.getServer().getPlayer(pName) != null)  {
            Player player = Bukkit.getServer().getPlayer(pName);
            locX = player.getLocation().getX();
            locY = player.getLocation().getY();
            locZ = player.getLocation().getZ();
            loc = ("X: " + locX + ", " + "Y: " + locY + ", " + "Z: " + locZ);
            healthbar = API.createHealthBar(player);
            health = String.valueOf(player.getHealth());
            pWorld = player.getWorld().getName();
            hungerLevel = String.valueOf(player.getFoodLevel());
            hungerBar = API.createBasicBar(player.getFoodLevel(), 20, 10);
            level = String.valueOf(player.getLevel());
            exp = String.valueOf(player.getExp()) + "/" + ((player.getLevel() + 1) * 10);
            expBar = API.createBasicBar(player.getExp(), ((player.getLevel() + 1) * 10), 10);
            tExp = String.valueOf(player.getTotalExperience());
            gMode = "";
            if (player.getGameMode() != null && player.getGameMode().name() != null)
                gMode = player.getGameMode().name();
            dName = player.getDisplayName();
            if (heroesB)             {
                Hero hero = heroes.getCharacterManager().getHero(player);
                HeroClass heroClass = hero.getHeroClass();
                HeroClass heroSClass = hero.getSecondClass();
                int hL = hero.getLevel();
                int hSL = hero.getLevel(heroSClass);
                double hE = hero.getExperience(heroClass);
                double hSE = hero.getExperience(heroSClass);
                hClass = hero.getHeroClass().getName();
                hHealth = String.valueOf(hero.getHealth());
                hHBar = Messaging.createHealthBar(hero.getHealth(), hero.getMaxHealth());
                hMana = String.valueOf(hero.getMana());
                hLevel = String.valueOf(hL);
                hExp = String.valueOf(hE);
                hEBar = Messaging.createExperienceBar(hero, heroClass);
                Integer hMMana = hero.getMaxMana();
                if (hMMana != null)
                    hMBar = Messaging.createManaBar(hero.getMana(), hero.getMaxMana());
                if (hero.getParty() != null)
                    hParty = hero.getParty().toString();
                if (heroSClass != null) {
                    hSClass = heroSClass.getName();
                    hSLevel = String.valueOf(hSL);
                    hSExp = String.valueOf(hSE);
                    hSEBar = Messaging.createExperienceBar(hero, heroSClass);
                }
                if ((hero.isMaster(heroClass))
                        && (heroSClass == null || hero.isMaster(heroSClass)))
                    hMastered = LocaleType.MESSAGE_HEROES_TRUE.getVal();
                else
                    hMastered = LocaleType.MESSAGE_HEROES_FALSE.getVal();
            }
            if (townyB) {
                try {
                    Resident resident = TownyUniverse.getDataSource().getResident(pName);
                    if (resident.hasTown()) {
                        Town town = resident.getTown();
                        tTown = town.getName();
                        tTownName = TownyFormatter.getFormattedTownName(town);
                        tTitle = resident.getTitle();
                        tSurname = resident.getSurname();
                        tResidentName = resident.getFormattedName();
                        tPrefix = resident.hasTitle() ? resident.getTitle() : TownyFormatter.getNamePrefix(resident);
                        tNamePrefix = TownyFormatter.getNamePrefix(resident);
                        tPostfix = resident.hasSurname() ? resident.getSurname() : TownyFormatter.getNamePostfix(resident);
                        tNamePostfix = TownyFormatter.getNamePostfix(resident);
                        if (resident.hasNation()) {
                            Nation nation = town.getNation();
                            tNation = nation.getName();
                            tNationName = nation.getFormattedName();
                            tNationTag = nation.getTag();
                        }
                    }
                } catch (Exception ignored) {}
            }
        }
        String formatAll = parseVars(format, pName, world);
        msg = msg.replaceAll("%", "%%");
        formatAll = formatAll.replaceAll("%", "%%");
        formatAll = MessageUtil.addColour(formatAll);
        if (ConfigType.MCHAT_CAPS_LOCK_RANGE.getInteger() > 0)
            msg = fixCaps(msg, ConfigType.MCHAT_CAPS_LOCK_RANGE.getInteger());
        if (formatAll == null)
            return msg;
        if (API.checkPermissions(pName, world, "mchat.coloredchat"))
            msg = MessageUtil.addColour(msg);
        if (!API.checkPermissions(pName, world, "mchat.censorbypass"))
            msg = replaceCensoredWords(msg);
        TreeMap<String, Object> fVarMap = new TreeMap<String, Object>();
        TreeMap<String, Object> rVarMap = new TreeMap<String, Object>();
        TreeMap<String, Object> lVarMap = new TreeMap<String, Object>();
        addVar(fVarMap, vI + "mnameformat," + vI + "mnf", LocaleType.FORMAT_NAME.getVal());
        addVar(fVarMap, vI + "healthbar," + vI + "hb", healthbar);
        addVar(rVarMap, vI + "distancetype," + vI + "dtype", dType);
        addVar(rVarMap, vI + "displayname," + vI + "dname," + vI + "dn", dName);
        addVar(rVarMap, vI + "experiencebar," + vI + "expb," + vI + "ebar," + vI + "eb", expBar);
        addVar(rVarMap, vI + "experience," + vI + "exp", exp);
        addVar(rVarMap, vI + "gamemode," + vI + "gm", gMode);
        addVar(rVarMap, vI + "group," + vI + "g", group);
        addVar(rVarMap, vI + "hungerbar," + vI + "hub", hungerBar);
        addVar(rVarMap, vI + "hunger", hungerLevel);
        addVar(rVarMap, vI + "health," + vI + "h", health);
        addVar(rVarMap, vI + "location," + vI + "loc", loc);
        addVar(rVarMap, vI + "level," + vI + "l", level);
        addVar(rVarMap, vI + "mname," + vI + "mn", Reader.getMName(pName));
        addVar(rVarMap, vI + "pname," + vI + "n", pName);
        addVar(rVarMap, vI + "prefix," + vI + "p", prefix);
        addVar(rVarMap, vI + "spying," + vI + "spy", sType);
        addVar(rVarMap, vI + "suffix," + vI + "s", suffix);
        addVar(rVarMap, vI + "totalexp," + vI + "texp," + vI + "te", tExp);
        addVar(rVarMap, vI + "time," + vI + "t", time);
        addVar(rVarMap, vI + "world," + vI + "w", pWorld);
        addVar(rVarMap, vI + "Groupname," + vI + "Gname," + vI + "G", Reader.getGroupName(group.toString()));
        addVar(rVarMap, vI + "HClass," + vI + "HC", hClass);
        addVar(rVarMap, vI + "HExp," + vI + "HEx", hExp);
        addVar(rVarMap, vI + "HEBar," + vI + "HEb", hEBar);
        addVar(rVarMap, vI + "HHBar," + vI + "HHB", hHBar);
        addVar(rVarMap, vI + "HHealth," + vI + "HH", hHealth);
        addVar(rVarMap, vI + "HLevel," + vI + "HL", hLevel);
        addVar(rVarMap, vI + "HMastered," + vI + "HMa", hMastered);
        addVar(rVarMap, vI + "HMana," + vI + "HMn", hMana);
        addVar(rVarMap, vI + "HMBar," + vI + "HMb", hMBar);
        addVar(rVarMap, vI + "HParty," + vI + "HPa", hParty);
        addVar(rVarMap, vI + "HSecClass," + vI + "HSC", hSClass);
        addVar(rVarMap, vI + "HSecExp," + vI + "HSEx", hSExp);
        addVar(rVarMap, vI + "HSecEBar," + vI + "HSEb", hSEBar);
        addVar(rVarMap, vI + "HSecLevel," + vI + "HSL", hSLevel);
        addVar(rVarMap, vI + "town", tTown);
        addVar(rVarMap, vI + "townname", tTownName);
        addVar(rVarMap, vI + "townysurname", tSurname);
        addVar(rVarMap, vI + "townytitle", tTitle);
        addVar(rVarMap, vI + "townyresidentname", tResidentName);
        addVar(rVarMap, vI + "townyprefix", tPrefix);
        addVar(rVarMap, vI + "townynameprefix", tNamePrefix);
        addVar(rVarMap, vI + "townypostfix", tPostfix);
        addVar(rVarMap, vI + "townynamepostfix", tNamePostfix);
        addVar(rVarMap, vI + "townynation", tNation);
        addVar(rVarMap, vI + "townynationname", tNationName);
        addVar(rVarMap, vI + "townynationtag", tNationTag);
        addVar(rVarMap, vI + "Worldname," + vI + "Wname," + vI + "W", Reader.getWorldName(pWorld));
        addVar(lVarMap, vI + "message," + vI + "msg," + vI + "m", msg);
        formatAll = replaceCustVars(pName, formatAll);
        formatAll = replaceVars(formatAll, fVarMap.descendingMap(), true);
        formatAll = replaceVars(formatAll, rVarMap.descendingMap(), true);
        formatAll = replaceVars(formatAll, lVarMap.descendingMap(), false);
        return formatAll;
    }

    public static String parseMessage(String pName, String world, String msg, String format) {
        Object prefix = Reader.getRawPrefix(pName, InfoType.USER, world);
        Object suffix = Reader.getRawSuffix(pName, InfoType.USER, world);
        Object group = Reader.getRawGroup(pName, InfoType.USER, world);
        String vI = ConfigType.MCHAT_VAR_INDICATOR.getString();
        if (msg == null)
            msg = "";
        if (prefix == null)
            prefix = "";
        if (suffix == null)
            suffix = "";
        if (group == null)
            group = "";
        String hSClass = "";
        String hClass = "";
        String hHealth = "";
        String hHBar = "";
        String hMana = "";
        String hMBar = "";
        String hParty = "";
        String hMastered = "";
        String hLevel = "";
        String hSLevel = "";
        String hExp = "";
        String hSExp = "";
        String hEBar = "";
        String hSEBar = "";
        String tTown = "";
        String tTownName = "";
        String tTitle = "";
        String tSurname = "";
        String tResidentName = "";
        String tPrefix = "";
        String tNamePrefix = "";
        String tPostfix = "";
        String tNamePostfix = "";
        String tNation = "";
        String tNationName = "";
        String tNationTag = "";
        Double locX = (double) randomNumber(-100, 100);
        Double locY = (double) randomNumber(-100, 100);
        Double locZ = (double) randomNumber(-100, 100);
        String loc = ("X: " + locX + ", " + "Y: " + locY + ", " + "Z: " + locZ);
        String healthbar = "";
        String health = String.valueOf(randomNumber(1, 20));
        String pWorld = "";
        String hungerLevel = String.valueOf(randomNumber(0, 20));
        String hungerBar = API.createBasicBar(randomNumber(0, 20), 20, 10);
        String level = String.valueOf(randomNumber(1, 2));
        String exp = String.valueOf(randomNumber(0, 200))+ "/" + ((randomNumber(1, 2) + 1) * 10);
        String expBar = API.createBasicBar(randomNumber(0, 200), ((randomNumber(1, 2) + 1) * 10), 10);
        String tExp = String.valueOf(randomNumber(0, 300));
        String gMode = String.valueOf(randomNumber(0, 1));
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(LocaleType.FORMAT_DATE.getRaw());
        String time = dateFormat.format(now);
        String dName = pName;
        String dType = "";
        if (MChat.isShouting.get(pName) != null
                && MChat.isShouting.get(pName)) {
            dType = LocaleType.FORMAT_SHOUT.getVal();
        } else if (ConfigType.MCHAT_CHAT_DISTANCE.getDouble() > 0) {
            dType = LocaleType.FORMAT_LOCAL.getVal();
        }
        String sType = "";
        if (MChat.isSpying.get(pName) != null
                && MChat.isSpying.get(pName))
            sType = LocaleType.FORMAT_SPY.getVal();
        if (Bukkit.getServer().getPlayer(pName) != null)  {
            Player player = Bukkit.getServer().getPlayer(pName);
            locX = player.getLocation().getX();
            locY = player.getLocation().getY();
            locZ = player.getLocation().getZ();
            loc = ("X: " + locX + ", " + "Y: " + locY + ", " + "Z: " + locZ);
            healthbar = API.createHealthBar(player);
            health = String.valueOf(player.getHealth());
            pWorld = player.getWorld().getName();
            hungerLevel = String.valueOf(player.getFoodLevel());
            hungerBar = API.createBasicBar(player.getFoodLevel(), 20, 10);
            level = String.valueOf(player.getLevel());
            exp = String.valueOf(player.getExp()) + "/" + ((player.getLevel() + 1) * 10);
            expBar = API.createBasicBar(player.getExp(), ((player.getLevel() + 1) * 10), 10);
            tExp = String.valueOf(player.getTotalExperience());
            gMode = "";
            if (player.getGameMode() != null && player.getGameMode().name() != null)
                gMode = player.getGameMode().name();
            dName = player.getDisplayName();
            if (heroesB)             {
                Hero hero = heroes.getCharacterManager().getHero(player);
                HeroClass heroClass = hero.getHeroClass();
                HeroClass heroSClass = hero.getSecondClass();
                int hL = hero.getLevel();
                int hSL = hero.getLevel(heroSClass);
                double hE = hero.getExperience(heroClass);
                double hSE = hero.getExperience(heroSClass);
                hClass = hero.getHeroClass().getName();
                hHealth = String.valueOf(hero.getHealth());
                hHBar = Messaging.createHealthBar(hero.getHealth(), hero.getMaxHealth());
                hMana = String.valueOf(hero.getMana());
                hLevel = String.valueOf(hL);
                hExp = String.valueOf(hE);
                hEBar = Messaging.createExperienceBar(hero, heroClass);
                Integer hMMana = hero.getMaxMana();
                if (hMMana != null)
                    hMBar = Messaging.createManaBar(hero.getMana(), hero.getMaxMana());
                if (hero.getParty() != null)
                    hParty = hero.getParty().toString();
                if (heroSClass != null) {
                    hSClass = heroSClass.getName();
                    hSLevel = String.valueOf(hSL);
                    hSExp = String.valueOf(hSE);
                    hSEBar = Messaging.createExperienceBar(hero, heroSClass);
                }
                if ((hero.isMaster(heroClass))
                        && (heroSClass == null || hero.isMaster(heroSClass)))
                    hMastered = LocaleType.MESSAGE_HEROES_TRUE.getVal();
                else
                    hMastered = LocaleType.MESSAGE_HEROES_FALSE.getVal();
            }
            if (townyB) {
                try {
                    Resident resident = TownyUniverse.getDataSource().getResident(pName);
                    if (resident.hasTown()) {
                        Town town = resident.getTown();
                        tTown = town.getName();
                        tTownName = TownyFormatter.getFormattedTownName(town);
                        tTitle = resident.getTitle();
                        tSurname = resident.getSurname();
                        tResidentName = resident.getFormattedName();
                        tPrefix = resident.hasTitle() ? resident.getTitle() : TownyFormatter.getNamePrefix(resident);
                        tNamePrefix = TownyFormatter.getNamePrefix(resident);
                        tPostfix = resident.hasSurname() ? resident.getSurname() : TownyFormatter.getNamePostfix(resident);
                        tNamePostfix = TownyFormatter.getNamePostfix(resident);
                        if (resident.hasNation()) {
                            Nation nation = town.getNation();
                            tNation = nation.getName();
                            tNationName = nation.getFormattedName();
                            tNationTag = nation.getTag();
                        }
                    }
                } catch (Exception ignored) {}
            }
        }
        String formatAll = parseVars(format, pName, world);
        msg = msg.replaceAll("%", "%%");
        formatAll = formatAll.replaceAll("%", "%%");
        formatAll = MessageUtil.addColour(formatAll);
        if (ConfigType.MCHAT_CAPS_LOCK_RANGE.getInteger() > 0)
            msg = fixCaps(msg, ConfigType.MCHAT_CAPS_LOCK_RANGE.getInteger());
        if (formatAll == null)
            return msg;
        if (API.checkPermissions(pName, world, "mchat.coloredchat"))
            msg = MessageUtil.addColour(msg);
        if (!API.checkPermissions(pName, world, "mchat.censorbypass"))
            msg = replaceCensoredWords(msg);
        TreeMap<String, Object> fVarMap = new TreeMap<String, Object>();
        TreeMap<String, Object> rVarMap = new TreeMap<String, Object>();
        TreeMap<String, Object> lVarMap = new TreeMap<String, Object>();
        addVar(fVarMap, vI + "mnameformat," + vI + "mnf", LocaleType.FORMAT_NAME.getVal());
        addVar(fVarMap, vI + "healthbar," + vI + "hb", healthbar);
        addVar(rVarMap, vI + "distancetype," + vI + "dtype", dType);
        addVar(rVarMap, vI + "displayname," + vI + "dname," + vI + "dn", dName);
        addVar(rVarMap, vI + "experiencebar," + vI + "expb," + vI + "ebar," + vI + "eb", expBar);
        addVar(rVarMap, vI + "experience," + vI + "exp", exp);
        addVar(rVarMap, vI + "gamemode," + vI + "gm", gMode);
        addVar(rVarMap, vI + "group," + vI + "g", group);
        addVar(rVarMap, vI + "hungerbar," + vI + "hub", hungerBar);
        addVar(rVarMap, vI + "hunger", hungerLevel);
        addVar(rVarMap, vI + "health," + vI + "h", health);
        addVar(rVarMap, vI + "location," + vI + "loc", loc);
        addVar(rVarMap, vI + "level," + vI + "l", level);
        addVar(rVarMap, vI + "mname," + vI + "mn", Reader.getMName(pName));
        addVar(rVarMap, vI + "pname," + vI + "n", pName);
        addVar(rVarMap, vI + "prefix," + vI + "p", prefix);
        addVar(rVarMap, vI + "spying," + vI + "spy", sType);
        addVar(rVarMap, vI + "suffix," + vI + "s", suffix);
        addVar(rVarMap, vI + "totalexp," + vI + "texp," + vI + "te", tExp);
        addVar(rVarMap, vI + "time," + vI + "t", time);
        addVar(rVarMap, vI + "world," + vI + "w", pWorld);
        addVar(rVarMap, vI + "Groupname," + vI + "Gname," + vI + "G", Reader.getGroupName(group.toString()));
        addVar(rVarMap, vI + "HClass," + vI + "HC", hClass);
        addVar(rVarMap, vI + "HExp," + vI + "HEx", hExp);
        addVar(rVarMap, vI + "HEBar," + vI + "HEb", hEBar);
        addVar(rVarMap, vI + "HHBar," + vI + "HHB", hHBar);
        addVar(rVarMap, vI + "HHealth," + vI + "HH", hHealth);
        addVar(rVarMap, vI + "HLevel," + vI + "HL", hLevel);
        addVar(rVarMap, vI + "HMastered," + vI + "HMa", hMastered);
        addVar(rVarMap, vI + "HMana," + vI + "HMn", hMana);
        addVar(rVarMap, vI + "HMBar," + vI + "HMb", hMBar);
        addVar(rVarMap, vI + "HParty," + vI + "HPa", hParty);
        addVar(rVarMap, vI + "HSecClass," + vI + "HSC", hSClass);
        addVar(rVarMap, vI + "HSecExp," + vI + "HSEx", hSExp);
        addVar(rVarMap, vI + "HSecEBar," + vI + "HSEb", hSEBar);
        addVar(rVarMap, vI + "HSecLevel," + vI + "HSL", hSLevel);
        addVar(rVarMap, vI + "town", tTown);
        addVar(rVarMap, vI + "townname", tTownName);
        addVar(rVarMap, vI + "townysurname", tSurname);
        addVar(rVarMap, vI + "townytitle", tTitle);
        addVar(rVarMap, vI + "townyresidentname", tResidentName);
        addVar(rVarMap, vI + "townyprefix", tPrefix);
        addVar(rVarMap, vI + "townynameprefix", tNamePrefix);
        addVar(rVarMap, vI + "townypostfix", tPostfix);
        addVar(rVarMap, vI + "townynamepostfix", tNamePostfix);
        addVar(rVarMap, vI + "townynation", tNation);
        addVar(rVarMap, vI + "townynationname", tNationName);
        addVar(rVarMap, vI + "townynationtag", tNationTag);
        addVar(rVarMap, vI + "Worldname," + vI + "Wname," + vI + "W", Reader.getWorldName(pWorld));
        addVar(lVarMap, vI + "message," + vI + "msg," + vI + "m", msg);
        formatAll = replaceCustVars(pName, formatAll);
        formatAll = replaceVars(formatAll, fVarMap.descendingMap(), true);
        formatAll = replaceVars(formatAll, rVarMap.descendingMap(), true);
        formatAll = replaceVars(formatAll, lVarMap.descendingMap(), false);
        return formatAll;
    }
