From d97aeb508afe6aadfa1794c230ff8e63d9df79a4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 9 Jun 2016 13:49:04 +1000 Subject: [PATCH] Provide more helpful and consistent messages when using commands from IRC/console that require a specific player/level/etc name (as own player cannot be used). --- Commands/CPE/CmdModel.cs | 10 +++------- Commands/CPE/CmdSkin.cs | 10 +++------- Commands/Command.Helpers.cs | 27 +++++++++++++++++++-------- Commands/Economy/CmdBalance.cs | 4 +--- Commands/Information/CmdBanInfo.cs | 6 ++---- Commands/Information/CmdRankReqs.cs | 4 +--- Commands/Moderation/CmdAllowGuns.cs | 10 +++------- Commands/Moderation/CmdNotes.cs | 8 ++------ Commands/World/CmdBlockDB.cs | 4 +--- Commands/building/CmdUndo.cs | 2 +- Commands/other/CmdColor.cs | 8 +++++--- Player/Group/GroupProperties.cs | 2 +- 12 files changed, 42 insertions(+), 53 deletions(-) diff --git a/Commands/CPE/CmdModel.cs b/Commands/CPE/CmdModel.cs index a8f612a4f..c52f26837 100644 --- a/Commands/CPE/CmdModel.cs +++ b/Commands/CPE/CmdModel.cs @@ -30,12 +30,8 @@ namespace MCGalaxy.Commands.CPE { static char[] trimChars = { ' ' }; public override void Use(Player p, string message) { - if (message == "") { - if (p == null) { - Player.Message(p, "Console must provide a player or bot name."); return; - } - message = p.name; - } + if (CheckSuper(p, message, "player or bot name")) return; + message = p.name; Player who = p; PlayerBot pBot = null; @@ -55,7 +51,7 @@ namespace MCGalaxy.Commands.CPE { } else { isBot = false; who = p; - if (who == null) { Player.Message(p, "Console must provide a player name."); return; } + if (who == null) { SuperRequiresArgs(p, "player name"); return; } model = message; } model = model.ToLower(); diff --git a/Commands/CPE/CmdSkin.cs b/Commands/CPE/CmdSkin.cs index 48c6dc9c9..9b5777ff8 100644 --- a/Commands/CPE/CmdSkin.cs +++ b/Commands/CPE/CmdSkin.cs @@ -30,12 +30,8 @@ namespace MCGalaxy.Commands.CPE { static char[] trimChars = { ' ' }; public override void Use(Player p, string message) { - if (message == "") { - if (p == null) { - Player.Message(p, "Console must provide a player or bot name."); return; - } - message = p.truename; - } + if (CheckSuper(p, message, "player or bot name")) return; + message = p.truename; Player who = p; PlayerBot pBot = null; @@ -55,7 +51,7 @@ namespace MCGalaxy.Commands.CPE { } else { isBot = false; who = p; - if (who == null) { Player.Message(p, "Console must provide a player name."); return; } + if (who == null) { SuperRequiresArgs(p, "player name"); return; } skin = message; } diff --git a/Commands/Command.Helpers.cs b/Commands/Command.Helpers.cs index d021c187e..9ca14bc2d 100644 --- a/Commands/Command.Helpers.cs +++ b/Commands/Command.Helpers.cs @@ -45,7 +45,18 @@ namespace MCGalaxy { } protected void MessageInGameOnly(Player p) { - Player.Message(p, "/" + name + " can only be used in-game."); + Player.Message(p, "/{0} can only be used in-game.", name); + } + + protected bool CheckSuper(Player p, string message, string type) { + if (message != "" || (p != null && p.ircNick == null)) return false; + SuperRequiresArgs(p, type); + return true; + } + + protected void SuperRequiresArgs(Player p, string type) { + string src = p == null ? "console" : "IRC"; + Player.Message(p, "When using /{0} from {2}, you must provide a {1}.", name, type, src); } protected bool CheckExtraPerm(Player p, int num = 1) { @@ -60,9 +71,9 @@ namespace MCGalaxy { protected void MessageNeedMinPerm(Player p, string action, int perm) { Group grp = Group.findPermInt(perm); if (grp == null) - Player.Message(p, "Only ranks with permissions greater than &a" + perm + "%Scan " + action); + Player.Message(p, "Only ranks with permissions greater than &a{0}%Scan {1}", perm, action); else - Player.Message(p, "Only " + grp.ColoredName + "%S+ can " + action); + Player.Message(p, "Only {0}%S+ can {1}", grp.ColoredName, action); } protected void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) { @@ -71,9 +82,9 @@ namespace MCGalaxy { protected void MessageTooHighRank(Player p, string action, Group grp, bool canAffectGroup) { if (canAffectGroup) - Player.Message(p, "Can only " + action + " players ranked " + grp.ColoredName + " %Sor below"); + Player.Message(p, "Can only {0} players ranked {1} %Sor below", action, grp.ColoredName); else - Player.Message(p, "Can only " + action + " players ranked below " + grp.ColoredName); + Player.Message(p, "Can only {0} players ranked below {1}", action, grp.ColoredName); } internal void MessageCannotUse(Player p) { @@ -85,14 +96,14 @@ namespace MCGalaxy { StringBuilder builder = new StringBuilder("Only "); if (perms.allow.Count > 0) { foreach (LevelPermission perm in perms.allow) { - Group grp = Group.findPermInt((int)perm); + Group grp = Group.findPermInt((int)perm); if (grp == null) continue; builder.Append(grp.ColoredName).Append("%S, "); } - if (builder.Length > "Only ".Length) { + if (builder.Length > "Only ".Length) { builder.Remove(builder.Length - 2, 2); builder.Append(", and "); - } + } } Group minGrp = Group.findPermInt((int)perms.lowestRank); diff --git a/Commands/Economy/CmdBalance.cs b/Commands/Economy/CmdBalance.cs index 240e1a391..badd4fa4f 100644 --- a/Commands/Economy/CmdBalance.cs +++ b/Commands/Economy/CmdBalance.cs @@ -30,9 +30,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { Economy.EcoStats ecos; - if (p == null && message == "") { - Player.Message(p, "You must provide a name when using the command from console."); return; - } + if (CheckSuper(p, message, "player name")) return; int matches = 1; Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message, out matches); diff --git a/Commands/Information/CmdBanInfo.cs b/Commands/Information/CmdBanInfo.cs index 3e309ec35..1f685ae27 100644 --- a/Commands/Information/CmdBanInfo.cs +++ b/Commands/Information/CmdBanInfo.cs @@ -25,10 +25,8 @@ namespace MCGalaxy.Commands.Moderation { public CmdBanInfo() { } public override void Use(Player p, string message) { - if (message == "") { - if (p == null) { Player.Message(p, "Console must provide a player name."); return; } - message = p.name; - } + if (CheckSuper(p, message, "player name")) return; + if (message == "") message = p.name; bool banned = Group.IsBanned(message); string msg = message; string ip = PlayerInfo.FindIP(message); diff --git a/Commands/Information/CmdRankReqs.cs b/Commands/Information/CmdRankReqs.cs index 6c37584c7..c0b0a0dc8 100644 --- a/Commands/Information/CmdRankReqs.cs +++ b/Commands/Information/CmdRankReqs.cs @@ -38,9 +38,7 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message == "") { - if (p == null) { - Player.Message(p, "Console must provide a rank name."); return; - } + if (CheckSuper(p, message, "rank name")) return; Group next = null; int index = Group.GroupList.IndexOf(p.group); diff --git a/Commands/Moderation/CmdAllowGuns.cs b/Commands/Moderation/CmdAllowGuns.cs index ad64df022..c675394f2 100644 --- a/Commands/Moderation/CmdAllowGuns.cs +++ b/Commands/Moderation/CmdAllowGuns.cs @@ -30,13 +30,9 @@ namespace MCGalaxy.Commands { public CmdAllowGuns() { } public override void Use(Player p, string message) { - Level lvl = null; - if (message == "") { - if (p == null) { - Player.Message(p, "You must provide a level name when using this command from console."); return; - } - lvl = p.level; - } else { + if (CheckSuper(p, message, "level name")) return; + Level lvl = p.level; + if (message != "") { lvl = LevelInfo.FindOrShowMatches(p, message); if (lvl == null) return; } diff --git a/Commands/Moderation/CmdNotes.cs b/Commands/Moderation/CmdNotes.cs index e08f7b1ed..ded33747b 100644 --- a/Commands/Moderation/CmdNotes.cs +++ b/Commands/Moderation/CmdNotes.cs @@ -31,12 +31,8 @@ namespace MCGalaxy.Commands { if (!Server.LogNotes) { Player.Message(p, "The server does not have notes logging enabled."); return; } - if (message == "") { - if (p == null) { - Player.Message(p, "Console must provide a player name."); return; - } - message = p.name; - } + if (CheckSuper(p, message, "player name")) return; + if (message == "") message = p.name; int matches = 1; Player who = message == "" ? p : PlayerInfo.FindOrShowMatches(p, message, out matches); diff --git a/Commands/World/CmdBlockDB.cs b/Commands/World/CmdBlockDB.cs index 2893e568c..96f6392d4 100644 --- a/Commands/World/CmdBlockDB.cs +++ b/Commands/World/CmdBlockDB.cs @@ -31,9 +31,7 @@ namespace MCGalaxy.Commands.World { public override void Use(Player p, string message) { string[] args = message.Split(' '); - if (args.Length == 1 && p == null) { - Player.Message(p, "You must provide a map name when running the command from console."); return; - } + if (args.Length == 1 && p == null) { SuperRequiresArgs(p, "map name"); return; } args[0] = args[0].ToLower(); Level lvl = p == null ? null : p.level; diff --git a/Commands/building/CmdUndo.cs b/Commands/building/CmdUndo.cs index e33aac2fe..00ebdc6e8 100644 --- a/Commands/building/CmdUndo.cs +++ b/Commands/building/CmdUndo.cs @@ -37,9 +37,9 @@ namespace MCGalaxy.Commands.Building { } public override void Use(Player p, string message) { + if (CheckSuper(p, message, "player name")) return; int ignored = 0; if (message == "") { - if (p == null) { Player.Message(null, "Console doesn't have an undo buffer."); return; } UndoSelf(p); return; } else if (p != null && int.TryParse(message, out ignored)) { message = p.name.ToLower() + " " + message; diff --git a/Commands/other/CmdColor.cs b/Commands/other/CmdColor.cs index d6af7ae35..7043ec8af 100644 --- a/Commands/other/CmdColor.cs +++ b/Commands/other/CmdColor.cs @@ -25,10 +25,12 @@ namespace MCGalaxy.Commands { 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 CommandAlias[] Aliases { - get { return new[] { new CommandAlias("colour") }; } + public override CommandPerm[] AdditionalPerms { + get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can change color of other players") }; } + } + public override CommandAlias[] Aliases { + get { return new[] { new CommandAlias("colour"), new CommandAlias("xcolor") }; } } - public CmdColor() { } public override void Use(Player p, string message) { if (message == "") { Help(p); return; } diff --git a/Player/Group/GroupProperties.cs b/Player/Group/GroupProperties.cs index 51f06c6d0..cc450f3f7 100644 --- a/Player/Group/GroupProperties.cs +++ b/Player/Group/GroupProperties.cs @@ -202,7 +202,7 @@ namespace MCGalaxy { SW.WriteLine("MOTD = " + grp.MOTD); SW.WriteLine("FileName = " + grp.fileName); SW.WriteLine("OSMaps = " + grp.OverseerMaps); - SW.WriteLine("Prefix = " + grp.prefix); + SW.WriteLine("Prefix = " + CP437Writer.ConvertToUnicode(grp.prefix)); SW.WriteLine(); } }