internal static void LoadExtColors() { if (!File.Exists("text/customcolors.txt")) { return; } string[] lines = File.ReadAllLines("text/customcolors.txt"); CustomColor col = default(CustomColor); for (int i = 0; i < lines.Length; i++) { string[] parts = lines[i].Split(' '); if (parts.Length != 7) { continue; } col.Code = parts[0][0]; col.Fallback = parts[1][0]; col.Name = parts[2]; if (!Byte.TryParse(parts[3], out col.R) || !Byte.TryParse(parts[4], out col.G) || !Byte.TryParse(parts[5], out col.B) || !Byte.TryParse(parts[6], out col.A)) { continue; } ExtColors[col.Code] = col; } }
public static string MinecraftToIrcColors(string input) { if (input == null) { throw new ArgumentNullException("input"); } input = EscapeColors(input); StringBuilder sb = new StringBuilder(input); for (int i = 0; i < 128; i++) { CustomColor col = ExtColors[i]; if (col.Undefined) { continue; } sb.Replace("&" + col.Code, "&" + col.Fallback); } foreach (var kvp in ircColors) { sb.Replace(kvp.Key, kvp.Value); } return(sb.ToString()); }
public static void RemoveExtColor(char code) { CustomColor col = default(CustomColor); col.Code = code; SetExtCol(col); }
public static CustomColor ParseHex(string hex) { if (hex.Length > 0 && hex[0] == '#') { hex = hex.Remove(0, 1); } if (hex.Length != 3 && hex.Length != 6) { throw new ArgumentException("hex must be either 3 or 6 chars long"); } CustomColor c = default(CustomColor); int R, G, B; if (hex.Length == 6) { R = (Hex(hex[0]) << 4) | Hex(hex[1]); G = (Hex(hex[2]) << 4) | Hex(hex[3]); B = (Hex(hex[4]) << 4) | Hex(hex[5]); } else { R = Hex(hex[0]); R |= (R << 4); G = Hex(hex[1]); G |= (G << 4); B = Hex(hex[2]); B |= (B << 4); } c.R = (byte)R; c.G = (byte)G; c.B = (byte)B; c.A = 255; return(c); }
internal static void SendSetTextColor(Player p, CustomColor col) { byte[] buffer = new byte[6]; buffer[0] = Opcode.CpeSetTextColor; buffer[1] = col.R; buffer[2] = col.G; buffer[3] = col.B; buffer[4] = col.A; buffer[5] = (byte)col.Code; p.SendRaw(buffer); }
static void SetExtCol(CustomColor col) { ExtColors[col.Code] = col; Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (!p.HasCpeExt(CpeExt.TextColors)) { continue; } SendSetTextColor(p, col); } SaveExtColors(); }
public void SendEnvColor(byte type, string hex) { if (String.IsNullOrEmpty(hex)) { Send(Packet.EnvColor(type, -1, -1, -1)); return; } try { CustomColor c = Colors.ParseHex(hex); Send(Packet.EnvColor(type, c.R, c.G, c.B)); } catch (ArgumentException) { Send(Packet.EnvColor(type, -1, -1, -1)); } }
static string GetExtColor(string name) { for (int i = 0; i < ExtColors.Length; i++) { CustomColor col = ExtColors[i]; if (col.Undefined) { continue; } if (col.Name.CaselessEq(name)) { return("&" + col.Code); } } return(""); }
void ParseColors(StringBuilder sb) { for (int i = 0; i < 128; i++) { if (Colors.IsStandardColor((char)i)) { if (i >= 'A' && i <= 'F') // WoM does not work with uppercase color codes. { sb.Replace("&" + (char)i, "&" + (char)(i + ' ')); } continue; } CustomColor col = Colors.ExtColors[i]; if (col.Undefined) { sb.Replace("&" + (char)i, ""); continue; } if (!hasTextColors) { sb.Replace("&" + (char)i, "&" + col.Fallback); continue; } } }
public static void AddExtColor(CustomColor col) { SetExtCol(col); }