From e1eb6295bb33b9e8e4cfe56af227aa4885cf97cf Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 6 Jul 2017 19:11:02 +1000 Subject: [PATCH] Simplify help /cd, remove /cd tutorial, add /delay for usage in MBs --- MCGalaxy/Commands/Fun/CmdCountdown.cs | 20 +++------- MCGalaxy/Commands/other/CmdDelay.cs | 55 +++++++++++++++++++++++++++ MCGalaxy/MCGalaxy_.csproj | 1 + MCGalaxy/Player/Player.Fields.cs | 2 +- 4 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 MCGalaxy/Commands/other/CmdDelay.cs diff --git a/MCGalaxy/Commands/Fun/CmdCountdown.cs b/MCGalaxy/Commands/Fun/CmdCountdown.cs index 230835b9d..4faa42c06 100644 --- a/MCGalaxy/Commands/Fun/CmdCountdown.cs +++ b/MCGalaxy/Commands/Fun/CmdCountdown.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.Fun { public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Operator, "+ can send the countdown rules to everybody"), - new CommandPerm(LevelPermission.Operator, "+ can setup countdown (generate/start/restart/enable/disable/cancel)"), + new CommandPerm(LevelPermission.Operator, "+ can setup and manage countdown"), }; } } @@ -78,8 +78,6 @@ namespace MCGalaxy.Commands.Fun { case "reset": HandleReset(p, game, arg1); return; - case "tutorial": - HandleTutorial(p); return; default: Help(p); break; } @@ -276,30 +274,22 @@ namespace MCGalaxy.Commands.Fun { } - void HandleTutorial(Player p) { - Player.Message(p, "First, generate the map using /cd generate"); - Player.Message(p, "Next, type /cd enable to enable countdown"); - Player.Message(p, "Next, type /cd join to join countdown, and tell other players to join"); - Player.Message(p, "When some people have joined, type /cd start [speed] to start it"); - Player.Message(p, "[speed] can be 'ultimate', 'extreme', 'fast', 'normal' or 'slow'"); - } - public override void Help(Player p) { Player.Message(p, "%T/cd joins/leave %H- joins/leaves the game"); Player.Message(p, "%T/cd players %H- lists players currently playing"); Player.Message(p, "%T/cd rules %H- view the rules of countdown"); if (CheckExtraPerm(p, 1)) { - Player.Message(p, "%T/cd rules [player] %H- sends rules of countdown to that player."); + Player.Message(p, "%T/cd rules [player] %H- sends rules to that player."); } if (!CheckExtraPerm(p, 2)) return; Player.Message(p, "%T/cd generate [width] [height] [length] %H- generates the countdown map (default is 32x32x32)"); Player.Message(p, "%T/cd enable/disable %H- enables/disables countdown"); Player.Message(p, "%T/cd start %H- starts a round of countdown"); - Player.Message(p, "%H speed can be: slow/normal/fast/extreme/ultimate, mode can be: normal/freeze"); + Player.Message(p, "%H speed can be: slow, normal, fast, extreme or ultimate"); + Player.Message(p, "%H mode can be: normal or freeze"); Player.Message(p, "%T/cd end %H- force ends current round of countdown"); - Player.Message(p, "%T/cd reset %H- resets countdown map. Note %T/cd start %Hautomatically does this."); - Player.Message(p, "%T/cd tutorial %H- a tutorial on how to setup countdown"); + Player.Message(p, "%T/cd reset %H- resets the map. Note %T/cd start %Hauto does this."); } } } diff --git a/MCGalaxy/Commands/other/CmdDelay.cs b/MCGalaxy/Commands/other/CmdDelay.cs new file mode 100644 index 000000000..84ce81fb0 --- /dev/null +++ b/MCGalaxy/Commands/other/CmdDelay.cs @@ -0,0 +1,55 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.osedu.org/licenses/ECL-2.0 + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using System.Threading; + +namespace MCGalaxy.Commands.World { + public sealed class CmdDelay : Command { + public override string name { get { return "delay"; } } + public override string type { get { return CommandTypes.Other; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } + public override bool SuperUseable { get { return false; } } + + public override void Use(Player p, string message) { + TimeSpan duration = TimeSpan.Zero; + if (!CommandParser.GetTimespan(p, message, ref duration, "wait for", 's')) return; + + if (duration.TotalSeconds > 60) { + Player.Message(p, "Can only wait for a minute at most."); return; + } + + if (Interlocked.CompareExchange(ref p.UsingDelay, 1, 0) == 1) { + Player.Message(p, "You are already using /delay."); return; + } + + try { + Thread.Sleep((int)duration.TotalMilliseconds); + } finally { + Interlocked.Exchange(ref p.UsingDelay, 0); + } + } + + public override void Help(Player p) { + Player.Message(p, "%T/delay [timespan]"); + Player.Message(p, "%HWaits for a certain amount of time."); + Player.Message(p, "%HThis is mainly designed for use in %T/mb%H, to run a command after a certain delay."); + Player.Message(p, "%H e.g. %T/mb air /delay 10 |/help me"); + } + } +} diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 43a520553..3e41c4069 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -335,6 +335,7 @@ + diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 0fffca15d..a43499367 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -219,7 +219,7 @@ namespace MCGalaxy { public Level level = Server.mainLevel; public bool Loading = true; //True if player is loading a map. - internal int UsingGoto = 0, GeneratingMap = 0, LoadingMuseum = 0; + internal int UsingGoto = 0, GeneratingMap = 0, LoadingMuseum = 0, UsingDelay = 0; public Vec3U16 lastClick = Vec3U16.Zero; public Position beforeTeleportPos = default(Position); public string lastTeleportMap = "";