mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Minimise usage of inequliaty comparison against empty string
This commit is contained in:
parent
189332357a
commit
f45b9bffb0
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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]);
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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]);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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()))
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)",
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -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) {
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -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";
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user