mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Rewrite /pause to use main scheduler, instead of a separate timer.
This commit is contained in:
parent
aeb4ac8fd8
commit
ef53875460
@ -52,7 +52,7 @@ namespace MCGalaxy.Commands {
|
|||||||
static bool CopyBlocks(Player p, Level other, Vec3S32[] m) {
|
static bool CopyBlocks(Player p, Level other, Vec3S32[] m) {
|
||||||
byte[] blocks = other.blocks;
|
byte[] blocks = other.blocks;
|
||||||
if (blocks.Length != p.level.blocks.Length) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
namespace MCGalaxy.Commands
|
namespace MCGalaxy.Commands {
|
||||||
{
|
public sealed class CmdPause : Command {
|
||||||
public sealed class CmdPause : Command
|
|
||||||
{
|
|
||||||
public override string name { get { return "pause"; } }
|
public override string name { get { return "pause"; } }
|
||||||
public override string shortcut { get { return ""; } }
|
public override string shortcut { get { return ""; } }
|
||||||
public override string type { get { return CommandTypes.World; } }
|
public override string type { get { return CommandTypes.World; } }
|
||||||
@ -50,36 +48,29 @@ namespace MCGalaxy.Commands
|
|||||||
bool enabled = lvl.physPause;
|
bool enabled = lvl.physPause;
|
||||||
lvl.PhysicsEnabled = enabled;
|
lvl.PhysicsEnabled = enabled;
|
||||||
lvl.physPause = !lvl.physPause;
|
lvl.physPause = !lvl.physPause;
|
||||||
lvl.physResume = DateTime.UtcNow;
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled.");
|
Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled.");
|
||||||
} else {
|
} 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.");
|
Player.GlobalMessage("Physics on " + lvl.name + " were temporarily disabled.");
|
||||||
StartPauseCheck(lvl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void StartPauseCheck(Level lvl) {
|
static void PauseCallback(SchedulerTask task) {
|
||||||
lvl.physTimer.Elapsed += delegate
|
string lvlName = (string)task.State;
|
||||||
{
|
Level lvl = LevelInfo.FindExact(lvlName);
|
||||||
if (DateTime.UtcNow > lvl.physResume) {
|
if (lvl == null) return;
|
||||||
lvl.physPause = false;
|
|
||||||
lvl.PhysicsEnabled = true;
|
lvl.PhysicsEnabled = true;
|
||||||
|
Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled.");
|
||||||
Player.GlobalMessage("Physics on " + lvl.name + " were re-enabled.");
|
|
||||||
lvl.physTimer.Stop();
|
|
||||||
lvl.physTimer.Dispose();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
lvl.physTimer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/pause [map] [seconds]");
|
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, "%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 [map] is not 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 [seconds] is not given, pauses physics for 30 seconds.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,9 +193,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public Random physRandom = new Random();
|
public Random physRandom = new Random();
|
||||||
public bool physPause;
|
public bool physPause;
|
||||||
public DateTime physResume;
|
|
||||||
public Thread physThread;
|
public Thread physThread;
|
||||||
public Timer physTimer = new Timer(1000);
|
|
||||||
readonly object physThreadLock = new object();
|
readonly object physThreadLock = new object();
|
||||||
bool physThreadStarted = false;
|
bool physThreadStarted = false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user