From ad81975b9545996da91a9e0745df28811cc121fc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Jul 2016 21:37:22 +1000 Subject: [PATCH] Cleanup tab/space indention, also rewrite /8ball to avoid Thread.Sleep. --- Commands/Chat/CmdNick.cs | 4 +-- Commands/Fun/Cmd8Ball.cs | 46 ++++++++++++++++++----------------- Commands/building/CmdPaint.cs | 2 +- Commands/other/CmdTp.cs | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Commands/Chat/CmdNick.cs b/Commands/Chat/CmdNick.cs index 1c71bcf81..0f776e374 100644 --- a/Commands/Chat/CmdNick.cs +++ b/Commands/Chat/CmdNick.cs @@ -62,7 +62,7 @@ namespace MCGalaxy.Commands { pBot.DisplayName = pBot.name; Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Sreverted to their original name."); } else { - if (newName.ToLower() == "empty") { newName = ""; } + if (newName.CaselessEq("empty")) newName = ""; if (newName.Length >= 30) { Player.Message(p, "Name must be under 30 letters."); return; } Player.GlobalMessage("Bot " + pBot.ColoredName + "'s %Sname was set to " + newName + "%S."); pBot.DisplayName = newName; @@ -95,7 +95,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "%HIf no [nick] is given, reverts player's nick to their original name."); Player.Message(p, "%T/nick bot [bot] [name]"); Player.Message(p, "%HSets the name shown above that bot in game."); - Player.Message(p, "%HIf bot's [name] is \"empty\", then bots name becomes blank."); + Player.Message(p, "%H If [name] is \"empty\", the bot will not have a name shown."); } } } diff --git a/Commands/Fun/Cmd8Ball.cs b/Commands/Fun/Cmd8Ball.cs index dec598c6f..99057d7a0 100644 --- a/Commands/Fun/Cmd8Ball.cs +++ b/Commands/Fun/Cmd8Ball.cs @@ -15,47 +15,49 @@ or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. */ -using System; -using System.Threading; -using System.Text; +using System; +using System.Text; namespace MCGalaxy.Commands { public sealed class Cmd8Ball : Command { - private static bool canUse = true; public override string name { get { return "8ball"; } } 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.Guest; } } public Cmd8Ball() { } - string[] messages = { "Not likely." , "Very likely." , "Impossible!" , "No." , "Yes." , "Definitely!" , "Do some more thinking." }; + + static string[] messages = { "Not likely." , "Very likely." , "Impossible!" , "No." , "Yes." , "Definitely!" , "Do some more thinking." }; + DateTime nextUse; + static TimeSpan delay = TimeSpan.FromSeconds(2); public override void Use(Player p, string message) { - if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } - if (Server.chatmod || p.muted) { - Player.SendMessage(p, "Cannot use 8-ball while muted."); - return; - } - if (canUse == false) {Player.SendMessage(p, "Must wait 10 seconds from the last time the command was used to use it again!"); return;} + if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + if (Server.chatmod || p.muted) { Player.SendMessage(p, "Cannot use 8-ball while muted."); return; } if (message == "") { Help(p); return; } - canUse = false; + + TimeSpan delta = nextUse - DateTime.UtcNow; + if (delta.TotalSeconds > 0) { + Player.Message(p, "The 8-ball is still recharging, wait another {0} seconds.", + (int)Math.Ceiling(delta.TotalSeconds)); + return; + } + nextUse = DateTime.UtcNow.AddSeconds(10 + 2); StringBuilder builder = new StringBuilder(message.Length); foreach (char c in message) { - if (ValidChar(c)) builder.Append(c); + if (Char.IsLetterOrDigit(c)) builder.Append(c); } string final = builder.ToString(); - Random random = new Random(final.ToLower().GetHashCode()); - Player.GlobalMessage(p.color + p.DisplayName + "%s asked the %b8-Ball: %f" + message); - Thread.Sleep(2000); - Player.GlobalMessage("The %b8-Ball %ssays:%f " + messages[random.Next(messages.Length)]); - Thread.Sleep(10000); - canUse = true; + Player.GlobalMessage(p.ColoredName + "%S asked the &b8-Ball: &f" + message); + Server.MainScheduler.QueueOnce(EightBallCallback, final, delay); } - - bool ValidChar(char c) { - return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); + + static void EightBallCallback(SchedulerTask task) { + string final = (string)task.State; + Random random = new Random(final.ToLower().GetHashCode()); + Player.GlobalMessage("The %b8-Ball %ssays:%f " + messages[random.Next(messages.Length)]); } public override void Help(Player p) { diff --git a/Commands/building/CmdPaint.cs b/Commands/building/CmdPaint.cs index 42e7033b2..9e26d5ba7 100644 --- a/Commands/building/CmdPaint.cs +++ b/Commands/building/CmdPaint.cs @@ -25,7 +25,7 @@ namespace MCGalaxy.Commands.Building { public CmdPaint() { } public override void Use(Player p, string message) { - if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } if (message != "") { Help(p); return; } p.painting = !p.painting; diff --git a/Commands/other/CmdTp.cs b/Commands/other/CmdTp.cs index e32623295..f78fb0d37 100644 --- a/Commands/other/CmdTp.cs +++ b/Commands/other/CmdTp.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands { public override LevelPermission defaultRank { get { return LevelPermission.Guest; } } public override void Use(Player p, string message) { - if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } string[] args = message.Split(' '); if (args.Length > 2) { Help(p); return; }