mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 21:51:19 -04:00
And now with 3.452894% less pointless memory allocations.
This commit is contained in:
parent
d5f2d003e8
commit
d2c6f6a6fe
@ -45,13 +45,14 @@ namespace MCGalaxy
|
||||
|
||||
public bool Remove(Command cmd) { return commands.Remove(cmd); }
|
||||
public bool Contains(Command cmd) { return commands.Contains(cmd); }
|
||||
public bool Contains(string name)
|
||||
{
|
||||
name = name.ToLower();
|
||||
return commands.Any(cmd => cmd.name == name.ToLower());
|
||||
public bool Contains(string name) {
|
||||
foreach (Command cmd in commands) {
|
||||
if (cmd.name.CaselessEq(name)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Command Find(string name)
|
||||
{
|
||||
|
||||
public Command Find(string name) {
|
||||
name = name.ToLower();
|
||||
return commands.FirstOrDefault(cmd => cmd.name == name || cmd.shortcut == name);
|
||||
}
|
||||
|
@ -261,19 +261,21 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
for (int i = 0; i < sb.Length; i++) {
|
||||
char c = sb[i];
|
||||
if (c != '&' || i == sb.Length - 1) continue;
|
||||
|
||||
CustomColor col = Colors.ExtColors[i];
|
||||
if (col.Undefined) {
|
||||
sb.Replace("&" + (char)i, ""); continue;
|
||||
}
|
||||
if (!hasTextColors) {
|
||||
sb.Replace("&" + (char)i, "&" + col.Fallback); continue;
|
||||
char code = sb[i + 1];
|
||||
if (Colors.IsStandardColor(code)) {
|
||||
if (code >= 'A' && code <= 'F')
|
||||
sb[i + 1] += ' '; // WoM does not work with uppercase color codes.
|
||||
} else {
|
||||
CustomColor col = Colors.ExtColors[i];
|
||||
if (col.Undefined) {
|
||||
sb.Remove(i, 2); i--; // now need to check char at i again
|
||||
} else if (!hasTextColors) {
|
||||
sb[i + 1] = col.Fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -639,40 +639,28 @@ namespace MCGalaxy {
|
||||
|
||||
void CheckLoginJailed() {
|
||||
//very very sloppy, yes I know.. but works for the time
|
||||
bool gotoJail = false;
|
||||
string gotoJailMap = "", gotoJailName = "";
|
||||
try {
|
||||
if (File.Exists("ranks/jailed.txt"))
|
||||
{
|
||||
using (StreamReader read = new StreamReader("ranks/jailed.txt"))
|
||||
{
|
||||
string line;
|
||||
while ((line = read.ReadLine()) != null)
|
||||
{
|
||||
string[] parts = line.Split();
|
||||
if (parts[0].ToLower() == this.name.ToLower())
|
||||
{
|
||||
gotoJail = true;
|
||||
gotoJailName = parts[0];
|
||||
gotoJailMap = parts[1];
|
||||
break;
|
||||
}
|
||||
if (!File.Exists("ranks/jailed.txt")) {
|
||||
File.Create("ranks/jailed.txt").Close(); return;
|
||||
}
|
||||
|
||||
using (StreamReader read = new StreamReader("ranks/jailed.txt")) {
|
||||
string line;
|
||||
while ((line = read.ReadLine()) != null) {
|
||||
string[] parts = line.Split();
|
||||
if (!parts[0].CaselessEq(name)) continue;
|
||||
|
||||
try {
|
||||
Command.all.Find("goto").Use(this, parts[1]);
|
||||
Command.all.Find("jail").Use(null, parts[0]);
|
||||
} catch (Exception e) {
|
||||
Kick(e.ToString());
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
File.Create("ranks/jailed.txt").Close();
|
||||
}
|
||||
} catch {
|
||||
gotoJail = false;
|
||||
}
|
||||
|
||||
if (gotoJail) {
|
||||
try {
|
||||
Command.all.Find("goto").Use(this, gotoJailMap);
|
||||
Command.all.Find("jail").Use(null, gotoJailName);
|
||||
} catch (Exception e) {
|
||||
Kick(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user