Minimise usage of inequliaty comparison against empty string

This commit is contained in:
UnknownShadow200 2017-08-02 12:37:28 +10:00
parent 189332357a
commit f45b9bffb0
38 changed files with 46 additions and 48 deletions

View File

@ -82,7 +82,7 @@ namespace MCGalaxy {
foreach (string line in lines) {
if (line.StartsWith("#") || line.Trim().Length == 0) continue;
string word = Reduce(line.ToLower());
string word = Reduce(line);
filters.Add(word);
}
}

View File

@ -119,8 +119,9 @@ namespace MCGalaxy.Commands.Bots{
using (StreamWriter w = new StreamWriter("bots/" + ai, true)) {
for (int i = allLines.Length - 1; i > 0; i--) {
if (allLines[i][0] != '#' && allLines[i] != "")
if (allLines[i].Length > 0 && allLines[i][0] != '#') {
w.WriteLine(allLines[i]);
}
}
}
} catch {

View File

@ -140,7 +140,7 @@ namespace MCGalaxy.Commands.CPE {
static bool CheckName(Player p, string arg) {
if (Colors.Parse(arg) != "") {
if (Colors.Parse(arg).Length > 0) {
Player.Message(p, "There is already an existing color with the name \"{0}\".", arg);
return false;
}
@ -150,7 +150,7 @@ namespace MCGalaxy.Commands.CPE {
static char ParseColor(Player p, string arg) {
if (arg.Length != 1) {
string colCode = Colors.Parse(arg);
if (colCode != "") return colCode[1];
if (colCode.Length > 0) return colCode[1];
Player.Message(p, "There is no color \"" + arg + "\".");
} else {

View File

@ -203,8 +203,7 @@ namespace MCGalaxy.Commands.CPE {
string[] files = Directory.GetFiles("presets", "*.env");
string all = files.Join(f => Path.GetFileNameWithoutExtension(f));
if (all != "")
Player.Message(p, "Custom preset types: " + all);
if (all.Length > 0) Player.Message(p, "Custom preset types: " + all);
}
public override void Help(Player p) {

View File

@ -23,7 +23,7 @@ namespace MCGalaxy.Commands.Chatting {
}
public override void Use(Player p, string message) {
if (message != "") { ChatModes.MessageAdmins(p, message); return; }
if (message.Length > 0) { ChatModes.MessageAdmins(p, message); return; }
p.adminchat = !p.adminchat;
if (p.adminchat) Player.Message(p, "All messages will now be sent to Admins only");

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.Commands.Chatting {
Toggle(p, ref p.ignoreDrawOutput, "{0} ignoring draw command output"); return;
} else if (action == "list") {
string names = p.listignored.Join();
if (names != "") {
if (names.Length > 0) {
Player.Message(p, "&cCurrently ignoring the following players:");
Player.Message(p, names);
}

View File

@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Chatting {
}
public override void Use(Player p, string message) {
if (message != "") { ChatModes.MessageOps(p, message); return; }
if (message.Length > 0) { ChatModes.MessageOps(p, message); return; }
p.opchat = !p.opchat;
if (p.opchat) Player.Message(p, "All messages will now be sent to OPs only");

View File

@ -40,7 +40,7 @@ namespace MCGalaxy {
}
protected bool CheckSuper(Player p, string message, string type) {
if (message != "" || !Player.IsSuper(p)) return false;
if (message.Length > 0 || !Player.IsSuper(p)) return false;
SuperRequiresArgs(name, p, type);
return true;
}

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Commands.Eco {
if (args.Length == 2) {
plName = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
if (plName == null) return;
} else if (message != "" && !message.CaselessEq("all")) {
} else if (message.Length > 0 && !message.CaselessEq("all")) {
if (!int.TryParse(args[0], out ignored)) {
modifier = "";
plName = PlayerInfo.FindMatchesPreferOnline(p, args[0]);

View File

@ -103,7 +103,7 @@ namespace MCGalaxy.Commands.Info {
msg += Block.Name(i) + ", ";
}
if (msg != "") {
if (msg.Length > 0) {
Player.Message(p, "Blocks which look like \"{0}\":", block);
Player.Message(p, msg.Remove(msg.Length - 2));
} else {

View File

@ -164,7 +164,7 @@ namespace MCGalaxy.Commands.Info {
Player.Message(p, category + " commands you may use:");
type = "Commands " + category;
if (sort != "") type += " " + sort;
if (sort != "") type += " " + sort;
MultiPageOutput.Output(p, cmds,
(cmd) => CmdHelp.GetColor(cmd) + cmd.name,
type, "commands", modifier, false);

View File

@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.Info {
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
Player.Message(p, "&9{1} devs: %S{0}", Server.Devs.Join(), Server.SoftwareName);
Player.Message(p, "&2{1} mods: %S{0}", Server.Mods.Join(), Server.SoftwareName);
}

View File

@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.Info {
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
if (ServerConfig.UseIRC) {
Player.Message(p, "IRC is &aEnabled%S.");

View File

@ -86,7 +86,7 @@ namespace MCGalaxy.Commands.Info {
bool ParseCommand(Player p, string message) {
string[] args = message.SplitSpaces(2);
Alias alias = Alias.Find(args[0].ToLower());
Alias alias = Alias.Find(args[0]);
if (alias != null) args[0] = alias.Target;
Command cmd = Command.all.Find(args[0]);

View File

@ -154,7 +154,7 @@ namespace MCGalaxy.Commands.Info {
// Early out when accounts have + and map doesn't.
if (plus && lvlName.IndexOf('+') == -1) return null;
while (lvlName != "" && Char.IsNumber(lvlName[lvlName.Length - 1])) {
while (lvlName.Length > 0 && Char.IsNumber(lvlName[lvlName.Length - 1])) {
// If the server does not have account with +, we have to account for the
// that say Player123's second level is Player1232, and the realm owner is Player123
string pName = plus ? null : PlayerInfo.FindName(lvlName);

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Info {
oprulesFile.EnsureExists();
Player who = p;
if (message != "") {
if (message.Length > 0) {
who = PlayerInfo.FindMatches(p, message);
if (who == null) return;
if (p != null && p.Rank < who.Rank) {

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Info {
if (p == null) { Help(p); return; }
name = p.name;
if (message != "") start = message.ToLower();
if (message.Length > 0) start = message.ToLower();
} else {
name = PlayerInfo.FindMatchesPreferOnline(p, args[0]);
if (args.Length > 1 && ValidTimespan(args[1].ToLower()))

View File

@ -28,9 +28,9 @@ namespace MCGalaxy.Commands.Info {
public override LevelPermission defaultRank { get { return LevelPermission.Guest; } }
public override void Use(Player p, string message) {
if (message != "") {
if (message.Length > 0) {
Group grp = Matcher.FindRanks(p, message);
if(grp == null) return;
if (grp == null) return;
string title = ":" + grp.Color + GetPlural(grp.Name) + ":";
Section rankSec = MakeSection(grp, title);

View File

@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Info {
if (message.CaselessEq("disagree")) { Disagree(p); return; }
Player who = p;
if (message != "") {
if (message.Length > 0) {
if (!CheckExtraPerm(p)) { MessageNeedExtra(p, 1); return; }
who = PlayerInfo.FindMatches(p, message);
if (who == null) return;

View File

@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.Info {
static PerformanceCounter cpuPCounter = null;
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
Player.Message(p, "Server's name: &b{0}%S", ServerConfig.Name);
Player.Message(p, "&a{0} %Splayers total. (&a{1} %Sonline, &8{2} banned%S)",

View File

@ -23,7 +23,7 @@ namespace MCGalaxy.Commands.Maintenance {
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
MCGalaxy.Gui.App.ExitProgram(true);
}

View File

@ -23,7 +23,7 @@ namespace MCGalaxy.Commands.Moderation {
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
if (Server.chatmod) {
Chat.MessageGlobal("Chat moderation has been disabled. Everyone can now speak.");

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Moderation {
}
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
List<Player> candidates = GetPatrolCandidates(p);
if (candidates.Count == 0) {

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.World {
public override void Use(Player p, string message) {
int seconds = 30;
Level lvl = p != null ? p.level : Server.mainLevel;
if (message != "") {
if (message.Length > 0) {
string[] parts = message.SplitSpaces();
if (parts.Length == 1) {
if (!int.TryParse(parts[0], out seconds)) {

View File

@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.World {
public override bool SuperUseable { get { return false; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
Player.Message(p, "Spawn location set to your current position.");
p.level.spawnx = (ushort)p.Pos.BlockX;

View File

@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.World {
public override bool SuperUseable { get { return false; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
bool cpSpawn = p.useCheckpointSpawn;
Position pos;

View File

@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.Building {
public override bool SuperUseable { get { return false; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
p.deleteMode = !p.deleteMode;
Player.Message(p, "Delete mode: &a" + p.deleteMode);

View File

@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
ushort dist = 20;
if (message != "" && !CommandParser.GetUShort(p, message, "Distance", ref dist)) return;
if (message.Length > 0 && !CommandParser.GetUShort(p, message, "Distance", ref dist)) return;
Player.Message(p, "Destroy the block you wish to drill.");
p.MakeSelection(1, "Selecting location for %SDrill", dist, DoDrill);

View File

@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.Building {
// convert player pos to block coords
Vec3U16 P = ClampPos(p.Pos, p.level);
if (message != "" && !ParseCoords(message, p, ref P)) return;
if (message.Length > 0 && !ParseCoords(message, p, ref P)) return;
P = Vec3U16.Clamp(P.X, P.Y, P.Z, p.level);
if (p.HasBlockchange) {

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
if (message.IndexOf(' ') != -1) { Help(p); return; }
ExtBlock skip = ExtBlock.Air;
if (message != "" && !CommandParser.GetBlock(p, message, out skip)) return;
if (message.Length > 0 && !CommandParser.GetBlock(p, message, out skip)) return;
Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, "Selecting region for %SMeasure", skip, DoMeasure);

View File

@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.Building {
public override bool SuperUseable { get { return false; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
p.painting = !p.painting;
string type = p.painting ? "&aON" : "&cOFF";

View File

@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building {
public override bool SuperUseable { get { return false; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
PerformRedo(p);
}

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
PhysicsArgs extraInfo = default(PhysicsArgs);
message = message.ToLower();
if (message != "" && !ParseArgs(p, message, ref extraInfo)) return;
if (message.Length > 0 && !ParseArgs(p, message, ref extraInfo)) return;
Player.Message(p, "Place or break two blocks to determine the edges.");
p.MakeSelection(2, "Selecting region for %SRestart physics", extraInfo, DoRestart);

View File

@ -63,7 +63,7 @@ namespace MCGalaxy.Commands.Misc {
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }
if (message.Length > 0) { Help(p); return; }
int code = p.random.Next(int.MinValue, int.MaxValue);
p.Leave("Server crash! Error code 0x" + Convert.ToString(code, 16).ToUpper());
}
@ -82,7 +82,7 @@ namespace MCGalaxy.Commands.Misc {
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message) {
if (message != "") {
if (message.Length > 0) {
Player.Message(p, "&cIncorrect syntax. Abuse detected.");
Thread.Sleep(3000);
}

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Config {
string color = Colors.Parse(value);
if (color.Length == 0) {
color = Colors.Name(value);
if (color != "") return value;
if (color.Length > 0) return value;
Logger.Log(LogType.Warning, "Config key \"{0}\" is not a valid color, using default of {1}", Name, DefaultValue);
return DefaultValue;

View File

@ -67,11 +67,13 @@ namespace MCGalaxy.Eco {
pl.Name = key.ToLower();
pl.Awards = new List<string>();
if (value.IndexOf(',') != -1)
foreach (string award in value.Split(','))
if (value.IndexOf(',') != -1) {
foreach (string award in value.Split(',')) {
pl.Awards.Add(award);
else if (value != "")
}
} else {
pl.Awards.Add(value);
}
PlayerAwards.Add(pl);
}

View File

@ -70,7 +70,7 @@ namespace MCGalaxy.Games {
case "maps":
foreach (string name in value.Split(',')) {
string map = name.Trim();
if (map != "" && !maps.Contains(map))
if (map.Length > 0 && !maps.CaselessContains(map))
maps.Add(map);
}
break;

View File

@ -40,17 +40,13 @@ namespace MCGalaxy.Gui {
static void ShutdownThread(bool restarting, string msg) {
saveAll(restarting, msg);
if (restarting) StartProcess();
ExitProcess();
Environment.Exit(0);
}
static void StartProcess() {
if (usingConsole) Process.Start(parent);
else Process.Start(Application.ExecutablePath);
}
static void ExitProcess() {
Environment.Exit(0);
}
public static void saveAll(bool restarting, string msg) {
try {