From e26d0c707dd7d3a47d4d411ee415be186be95e89 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 30 Jun 2016 22:07:18 +1000 Subject: [PATCH] Modularise more chat commands. --- Commands/CPE/CmdEnvironment.cs | 10 ++--- Commands/CPE/CmdModel.cs | 18 ++++---- Commands/CPE/CmdSkin.cs | 4 +- Commands/Chat/CmdColor.cs | 16 ++++--- Commands/Chat/CmdNick.cs | 76 +++++++++++++++++----------------- Commands/Chat/CmdTColor.cs | 11 +++-- Commands/Chat/CmdTitle.cs | 27 ++++++------ Levels/LevelEnv.cs | 2 +- Server/Server.cs | 5 --- 9 files changed, 88 insertions(+), 81 deletions(-) diff --git a/Commands/CPE/CmdEnvironment.cs b/Commands/CPE/CmdEnvironment.cs index d0e741a59..fc2611795 100644 --- a/Commands/CPE/CmdEnvironment.cs +++ b/Commands/CPE/CmdEnvironment.cs @@ -59,19 +59,19 @@ namespace MCGalaxy.Commands { Level lvl = p.level; switch (variable) { case "fog": - LevelEnv.SetColour(p, value, 2, "fog", ref lvl.FogColor); break; + LevelEnv.SetColor(p, value, 2, "fog", ref lvl.FogColor); break; case "cloud": case "clouds": - LevelEnv.SetColour(p, value, 1, "cloud", ref lvl.CloudColor); break; + LevelEnv.SetColor(p, value, 1, "cloud", ref lvl.CloudColor); break; case "sky": - LevelEnv.SetColour(p, value, 0, "sky", ref lvl.SkyColor); break; + LevelEnv.SetColor(p, value, 0, "sky", ref lvl.SkyColor); break; case "dark": case "shadow": - LevelEnv.SetColour(p, value, 3, "shadow", ref lvl.ShadowColor); break; + LevelEnv.SetColor(p, value, 3, "shadow", ref lvl.ShadowColor); break; case "sun": case "light": case "sunlight": - LevelEnv.SetColour(p, value, 4, "sunlight", ref lvl.LightColor); break; + LevelEnv.SetColor(p, value, 4, "sunlight", ref lvl.LightColor); break; case "weather": LevelEnv.SetWeather(p, p.level, value); break; case "cloudsheight": diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs index 48dc77d4a..ee461f489 100644 --- a/Commands/CPE/CmdModel.cs +++ b/Commands/CPE/CmdModel.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.CPE { public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the model of other players") }; } + get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the model of others") }; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("xmodel", "-own") }; } @@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.CPE { if (message == "") message = p.name; Player who = p; - PlayerBot pBot = null; + PlayerBot bot = null; bool isBot = message.CaselessStarts("bot "); string[] args = message.SplitSpaces(isBot ? 3 : 2); string model = null; @@ -51,8 +51,8 @@ namespace MCGalaxy.Commands.CPE { } if (isBot && args.Length > 2) { - pBot = PlayerBot.FindMatches(p, args[1]); - if (pBot == null) return; + bot = PlayerBot.FindMatches(p, args[1]); + if (bot == null) return; model = args[2]; } else if (args.Length > 1) { isBot = false; @@ -66,13 +66,13 @@ namespace MCGalaxy.Commands.CPE { model = message; } model = model.ToLower(); - if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the model of other players."); return; } + if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the model of others."); return; } if (isBot) { - pBot.model = model; - Entities.UpdateModel(pBot.id, model, pBot.level, null); - Player.GlobalMessage("Bot " + pBot.name + "'s %Smodel was changed to a &c" + model); - BotsFile.UpdateBot(pBot); + bot.model = model; + Entities.UpdateModel(bot.id, model, bot.level, null); + Player.GlobalMessage("Bot " + bot.name + "'s %Smodel was changed to a &c" + model); + BotsFile.UpdateBot(bot); } else { who.model = model; Entities.UpdateModel(who.id, model, who.level, who); diff --git a/Commands/CPE/CmdSkin.cs b/Commands/CPE/CmdSkin.cs index 30779bf3a..520f23518 100644 --- a/Commands/CPE/CmdSkin.cs +++ b/Commands/CPE/CmdSkin.cs @@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.CPE { public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the skin of other players") }; } + get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the skin of others") }; } } public override void Use(Player p, string message) { @@ -58,7 +58,7 @@ namespace MCGalaxy.Commands.CPE { } if (!ValidName(p, skin, "skin")) return; - if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the skin of other players."); return; } + if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the skin of others."); return; } if (skin[0] == '+') skin = "http://skins.minecraft.net/MinecraftSkins/" + skin.Substring(1) + ".png"; diff --git a/Commands/Chat/CmdColor.cs b/Commands/Chat/CmdColor.cs index 145f04765..2c54ffcf3 100644 --- a/Commands/Chat/CmdColor.cs +++ b/Commands/Chat/CmdColor.cs @@ -16,16 +16,16 @@ permissions and limitations under the Licenses. */ using MCGalaxy.SQL; + namespace MCGalaxy.Commands { - public class CmdColor : Command { - + public class CmdColor : Command { public override string name { get { return "color"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Chat; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the color of other players") }; } + get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the color of others") }; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("colour"), new CommandAlias("xcolor", "-own") }; } @@ -40,12 +40,16 @@ namespace MCGalaxy.Commands { } Player who = PlayerInfo.FindMatches(p, args[0]); + bool isBot = message.CaselessStarts("bot "); if (who == null) return; if (p != null && who.group.Permission > p.group.Permission) { MessageTooHighRank(p, "change the color of", true); return; } - if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the color of other players."); return; } - + if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the color of others."); return; } + SetColor(who, args); + } + + static void SetColor(Player p, Player who, string[] args) { ParameterisedQuery query = ParameterisedQuery.Create(); if (args.Length == 1) { Player.SendChatFrom(who, who.ColoredName + " %Shad their color removed.", false); @@ -56,7 +60,7 @@ namespace MCGalaxy.Commands { } else { string color = Colors.Parse(args[1]); if (color == "") { Player.Message(p, "There is no color \"" + args[1] + "\"."); return; } - else if (color == who.color) { Player.Message(p, p.DisplayName + " already has that color."); return; } + else if (color == who.color) { Player.Message(p, who.DisplayName + " already has that color."); return; } Player.SendChatFrom(who, who.ColoredName + " %Shad their color changed to " + color + Colors.Name(color) + "%S.", false); who.color = color; diff --git a/Commands/Chat/CmdNick.cs b/Commands/Chat/CmdNick.cs index dcb3423e3..b2bdec3fc 100644 --- a/Commands/Chat/CmdNick.cs +++ b/Commands/Chat/CmdNick.cs @@ -18,14 +18,13 @@ using System; using MCGalaxy; -namespace MCGalaxy.Commands { - public class CmdNick : Command { - - public override string name { get { return "nick"; } } - public override string shortcut { get { return "nickname"; } } - public override string type { get { return CommandTypes.Other; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } +namespace MCGalaxy.Commands { + public class CmdNick : Command { + public override string name { get { return "nick"; } } + public override string shortcut { get { return "nickname"; } } + public override string type { get { return CommandTypes.Other; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override CommandPerm[] AdditionalPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the nick of other players") }; } } @@ -33,41 +32,44 @@ namespace MCGalaxy.Commands { get { return new[] { new CommandAlias("xnick", "-own") }; } } - public override void Use(Player p, string message) { - if (message == "") { Help(p); return; } - string[] args = message.SplitSpaces(2); + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + string[] args = message.SplitSpaces(2); if (args[0].CaselessEq("-own")) { if (Player.IsSuper(p)) { SuperRequiresArgs(p, "player name"); return; } args[0] = p.name; } - - Player who = PlayerInfo.FindMatches(p, args[0]); - if (who == null) return; - if (p != null && who.group.Permission > p.group.Permission) { + + Player who = PlayerInfo.FindMatches(p, args[0]); + if (who == null) return; + if (p != null && who.group.Permission > p.group.Permission) { MessageTooHighRank(p, "change the nick of", true); return; - } - if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the nick of other players."); return; } - - string newName = args.Length > 1 ? args[1] : ""; - if (newName == "") { - who.DisplayName = who.truename; - Player.SendChatFrom(who, who.FullName + "%S reverted their nick to their original name.", false); - } else { - if (newName.Length >= 30) { Player.Message(p, "Nick must be under 30 letters."); return; } - Player.SendChatFrom(who, who.FullName + "%S changed their nick to " + who.color + newName + "%S.", false); - who.DisplayName = newName; - } - - Entities.GlobalDespawn(who, false); - Entities.GlobalSpawn(who, false); + } + if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the nick of others."); return; } + SetNick(p, who, args); + } + + static void SetNick(Player p, Player who, string[] args) { + string newName = args.Length > 1 ? args[1] : ""; + if (newName == "") { + who.DisplayName = who.truename; + Player.SendChatFrom(who, who.FullName + "%S reverted their nick to their original name.", false); + } else { + if (newName.Length >= 30) { Player.Message(p, "Nick must be under 30 letters."); return; } + Player.SendChatFrom(who, who.FullName + "%S changed their nick to " + who.color + newName + "%S.", false); + who.DisplayName = newName; + } + + Entities.GlobalDespawn(who, false); + Entities.GlobalSpawn(who, false); PlayerDB.Save(who); - } - - public override void Help(Player p) { - Player.Message(p, "%T/nick [nick]"); + } + + public override void Help(Player p) { + Player.Message(p, "%T/nick [nick]"); Player.Message(p, "%HSets the nick of "); - Player.Message(p, "%HIf no [nick] is given, reverts player's nick to their original name."); - } - } + Player.Message(p, "%HIf no [nick] is given, reverts player's nick to their original name."); + } + } } diff --git a/Commands/Chat/CmdTColor.cs b/Commands/Chat/CmdTColor.cs index bb4d65f8f..6e36f43e9 100644 --- a/Commands/Chat/CmdTColor.cs +++ b/Commands/Chat/CmdTColor.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands { public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the title color of other players") }; } + get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change the title color of others") }; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("tcolour"), new CommandAlias("xtcolor", "-own") }; } @@ -44,8 +44,11 @@ namespace MCGalaxy.Commands { if (p != null && who.group.Permission > p.group.Permission) { MessageTooHighRank(p, "change the title color of", true); return; } - if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title color of other players."); return; } - + if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title color of others."); return; } + SetTColor(p, who, args); + } + + static void SetTColor(Player p, player who, string[] args) { ParameterisedQuery query = ParameterisedQuery.Create(); if (args.Length == 1) { Player.SendChatFrom(who, who.ColoredName + " %Shad their title color removed.", false); @@ -64,7 +67,7 @@ namespace MCGalaxy.Commands { query.AddParam("@Name", who.name); Database.executeQuery(query, "UPDATE Players SET title_color = @Color WHERE Name = @Name"); } - who.SetPrefix(); + who.SetPrefix(); } public override void Help(Player p) { diff --git a/Commands/Chat/CmdTitle.cs b/Commands/Chat/CmdTitle.cs index 203777ab3..f5eb094c3 100644 --- a/Commands/Chat/CmdTitle.cs +++ b/Commands/Chat/CmdTitle.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the title of other players") }; } + get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can change the title of others") }; } } public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("xtitle", "-own") }; } @@ -45,26 +45,29 @@ namespace MCGalaxy.Commands { if (p != null && who.group.Permission > p.group.Permission) { MessageTooHighRank(p, "change the title of", true); return; } - if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title of other players."); return; } - - string newTitle = args.Length > 1 ? args[1] : ""; + if (who != p && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the title of others."); return; } + SetTitle(p, who, args); + } + + static void SetTitle(Player p, Player who, string[] args) { + string title = args.Length > 1 ? args[1] : ""; ParameterisedQuery query = ParameterisedQuery.Create(); - if (newTitle != "") - newTitle = newTitle.Replace("[", "").Replace("]", ""); - if (newTitle.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; } + if (title != "") + title = title.Replace("[", "").Replace("]", ""); + if (title.Length >= 20) { Player.Message(p, "Title must be under 20 letters."); return; } - if (newTitle == "") { + if (title == "") { Player.SendChatFrom(who, who.FullName + " %Shad their title removed.", false); query.AddParam("@Name", who.name); Database.executeQuery(query, "UPDATE Players SET Title = '' WHERE Name = @Name"); } else { - Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + newTitle + "%b]", false); - query.AddParam("@Title", newTitle); + Player.SendChatFrom(who, who.FullName + " %Swas given the title of &b[" + title + "%b]", false); + query.AddParam("@Title", title); query.AddParam("@Name", who.name); Database.executeQuery(query, "UPDATE Players SET Title = @Title WHERE Name = @Name"); } - who.title = newTitle; - who.SetPrefix(); + who.title = title; + who.SetPrefix(); } public override void Help(Player p) { diff --git a/Levels/LevelEnv.cs b/Levels/LevelEnv.cs index 07006edd6..b1d2b1a0c 100644 --- a/Levels/LevelEnv.cs +++ b/Levels/LevelEnv.cs @@ -81,7 +81,7 @@ namespace MCGalaxy { SendCurrentMapAppearance(p.level, prop, target); } - public static void SetColour(Player p, string value, byte envType, string envTypeName, ref string target) { + public static void SetColor(Player p, string value, byte envType, string envTypeName, ref string target) { if (IsResetString(value)) { Player.Message(p, "Reset {0} color for {1}%S to normal", envTypeName, p.level.name); target = null; diff --git a/Server/Server.cs b/Server/Server.cs index dfa0353a2..73b15d319 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -859,10 +859,5 @@ namespace MCGalaxy } return Group.standard.color; } - - public static bool canusegc = true; //badpokerface - public static int gcmultiwarns = 0, gcspamcount = 0, gccapscount = 0, gcfloodcount = 0; - public static DateTime gclastmsgtime = DateTime.MinValue; - public static string gclastmsg = ""; } } \ No newline at end of file