diff --git a/Commands/Moderation/CmdRestoreSelection.cs b/Commands/Moderation/CmdRestoreSelection.cs index 6269f1af8..b8d4b0f49 100644 --- a/Commands/Moderation/CmdRestoreSelection.cs +++ b/Commands/Moderation/CmdRestoreSelection.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Commands { static bool CopyBlocks(Player p, Level other, Vec3S32[] m) { byte[] blocks = other.blocks; if (blocks.Length != p.level.blocks.Length) { - p.Sessage("Cannot restore selection of different size maps."); + Player.Message(p, "Cannot restore selection of different size maps."); return false; } diff --git a/Commands/World/CmdPause.cs b/Commands/World/CmdPause.cs index 857c88fce..b1f7278af 100644 --- a/Commands/World/CmdPause.cs +++ b/Commands/World/CmdPause.cs @@ -16,10 +16,8 @@ permissions and limitations under the Licenses. */ using System; -namespace MCGalaxy.Commands -{ - public sealed class CmdPause : Command - { +namespace MCGalaxy.Commands { + public sealed class CmdPause : Command { public override string name { get { return "pause"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.World; } } @@ -50,36 +48,29 @@ namespace MCGalaxy.Commands bool enabled = lvl.physPause; lvl.PhysicsEnabled = enabled; lvl.physPause = !lvl.physPause; - lvl.physResume = DateTime.UtcNow; if (enabled) { Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled."); } else { - lvl.physResume = lvl.physResume.AddSeconds(seconds); + Server.MainScheduler.QueueOnce(PauseCallback, lvl.name, + TimeSpan.FromSeconds(seconds)); Player.GlobalMessage("Physics on " + lvl.name + " were temporarily disabled."); - StartPauseCheck(lvl); } } - static void StartPauseCheck(Level lvl) { - lvl.physTimer.Elapsed += delegate - { - if (DateTime.UtcNow > lvl.physResume) { - lvl.physPause = false; - lvl.PhysicsEnabled = true; - - Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled."); - lvl.physTimer.Stop(); - lvl.physTimer.Dispose(); - } - }; - lvl.physTimer.Start(); + static void PauseCallback(SchedulerTask task) { + string lvlName = (string)task.State; + Level lvl = LevelInfo.FindExact(lvlName); + if (lvl == null) return; + + lvl.PhysicsEnabled = true; + Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled."); } public override void Help(Player p) { Player.Message(p, "%T/pause [map] [seconds]"); Player.Message(p, "%HPauses physics on the given map for the specified number of seconds."); - Player.Message(p, "%H If no map name is given, pauses physics on the current map."); - Player.Message(p, "%H If no or non-numerical seconds are given, pauses physics for 30 seconds."); + Player.Message(p, "%H If [map] is not given, pauses physics on the current map."); + Player.Message(p, "%H If [seconds] is not given, pauses physics for 30 seconds."); } } } diff --git a/Levels/Level.Fields.cs b/Levels/Level.Fields.cs index 471e4742f..b2eb5f30d 100644 --- a/Levels/Level.Fields.cs +++ b/Levels/Level.Fields.cs @@ -193,9 +193,7 @@ namespace MCGalaxy { public Random physRandom = new Random(); public bool physPause; - public DateTime physResume; public Thread physThread; - public Timer physTimer = new Timer(1000); readonly object physThreadLock = new object(); bool physThreadStarted = false;