forked from ClassiCube/MCGalaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color.cs
218 lines (211 loc) · 8.05 KB
/
Color.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace MCGalaxy
{
public static class c
{
public const string black = "&0";
public const string navy = "&1";
public const string green = "&2";
public const string teal = "&3";
public const string maroon = "&4";
public const string purple = "&5";
public const string gold = "&6";
public const string silver = "&7";
public const string gray = "&8";
public const string blue = "&9";
public const string lime = "&a";
public const string aqua = "&b";
public const string red = "&c";
public const string pink = "&d";
public const string yellow = "&e";
public const string white = "&f";
public static string Parse(string str)
{
switch (str.ToLower())
{
case "black": return black;
case "navy": return navy;
case "green": return green;
case "teal": return teal;
case "maroon": return maroon;
case "purple": return purple;
case "gold": return gold;
case "silver": return silver;
case "gray": return gray;
case "blue": return blue;
case "lime": return lime;
case "aqua": return aqua;
case "red": return red;
case "pink": return pink;
case "yellow": return yellow;
case "white": return white;
default: return "";
}
}
public static string Name(string str)
{
switch (str)
{
case black: return "black";
case navy: return "navy";
case green: return "green";
case teal: return "teal";
case maroon: return "maroon";
case purple: return "purple";
case gold: return "gold";
case silver: return "silver";
case gray: return "gray";
case blue: return "blue";
case lime: return "lime";
case aqua: return "aqua";
case red: return "red";
case pink: return "pink";
case yellow: return "yellow";
case white: return "white";
default: return "";
}
}
public static byte MCtoIRC(string str)
{
switch (str)
{
case black: return 1;
case navy: return 2;
case green: return 3;
case teal: return 10;
case maroon: return 5;
case purple: return 6;
case gold: return 7;
case silver: return 15;
case gray: return 14;
case blue: return 12;
case lime: return 9;
case aqua: return 11;
case red: return 4;
case pink: return 13;
case yellow: return 8;
case white: return 0;
default: return 0;
}
}
public static readonly Dictionary<string, string> MinecraftToIRCColors = new Dictionary<string, string> {
{ white, "\u000300" },
{ black, "\u000301" },
{ navy, "\u000302" },
{ green, "\u000303" },
{ red, "\u000304" },
{ maroon, "\u000305" },
{ purple, "\u000306" },
{ gold, "\u000307" },
{ yellow, "\u000308" },
{ lime, "\u000309" },
{ teal, "\u000310" },
{ aqua, "\u000311" },
{ blue, "\u000312" },
{ pink, "\u000313" },
{ gray, "\u000314" },
{ silver, "\u000315" },
};
static readonly Regex IrcTwoColorCode = new Regex("(\x03\\d{1,2}),\\d{1,2}");
public static string IrcToMinecraftColors(string input)
{
if (input == null) throw new ArgumentNullException("input");
input = IrcTwoColorCode.Replace(input, "$1");
StringBuilder sb = new StringBuilder(input);
foreach (var codePair in MinecraftToIRCColors)
{
sb.Replace(codePair.Value, codePair.Key);
}
sb.Replace("\u0003", white); // color reset
sb.Replace("\u000f", white); // reset
return sb.ToString();
}
public static string IRCtoMC(byte str)
{
switch (str)
{
case 0: return white;
case 1: return black;
case 2: return navy;
case 3: return green;
case 4: return red;
case 5: return maroon;
case 6: return purple;
case 7: return gold;
case 8: return yellow;
case 9: return lime;
case 10: return teal;
case 11: return aqua;
case 12: return blue;
case 13: return pink;
case 14: return gray;
case 15: return silver;
default: return "";
}
}
public static string CraftIRCtoMC(byte str)
{
switch (str)
{
case 0: return white;
case 1: return black;
case 2: return navy;
case 3: return green;
case 4: return red;
case 5: return maroon;
case 6: return purple;
case 7: return gold;
case 8: return yellow;
case 9: return lime;
case 10: return teal;
case 11: return aqua;
case 12: return blue;
case 13: return pink;
case 14: return gray;
case 15: return silver;
default: return "";
}
}
/// <summary> Replaces Minecraft color codes with equivalent IRC color codes, in the given StringBuilder.
/// Opposite of IrcToMinecraftColors method. </summary>
/// <param name="sb"> StringBuilder objects, the contents of which will be processed. </param>
/// <exception cref="ArgumentNullException"> sb is null. </exception>
public static void MinecraftToIrcColors(StringBuilder sb)
{
if (sb == null) throw new ArgumentNullException("sb");
foreach (var codePair in MinecraftToIRCColors)
{
sb.Replace(codePair.Key, codePair.Value);
}
}
/// <summary> Replaces Minecraft color codes with equivalent IRC color codes, in the given string.
/// Opposite of IrcToMinecraftColors method. </summary>
/// <param name="input"> String to process. </param>
/// <returns> A processed string. </returns>
/// <exception cref="ArgumentNullException"> input is null. </exception>
public static string MinecraftToIrcColors(string input)
{
if (input == null) throw new ArgumentNullException("input");
StringBuilder sb = new StringBuilder(input);
MinecraftToIrcColors(sb);
return sb.ToString();
}
}
}