mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Cleanup tab/space indention, also rewrite /8ball to avoid Thread.Sleep.
This commit is contained in:
parent
621922cece
commit
ad81975b95
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,46 +16,48 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Threading;
|
||||
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.");
|
||||
if (Server.chatmod || p.muted) { Player.SendMessage(p, "Cannot use 8-ball while muted."); return; }
|
||||
if (message == "") { Help(p); return; }
|
||||
|
||||
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;
|
||||
}
|
||||
if (canUse == false) {Player.SendMessage(p, "Must wait 10 seconds from the last time the command was used to use it again!"); return;}
|
||||
if (message == "") { Help(p); return; }
|
||||
canUse = false;
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user