Sort of get /undo rewrite working, but mainly still broken.

This commit is contained in:
UnknownShadow200 2016-04-10 12:22:57 +10:00
parent 10ee303c41
commit 1993bcf13e
4 changed files with 156 additions and 129 deletions

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Commands
int ignored = 0;
if (message == "") {
if (p == null) { Player.SendMessage(null, "Console doesn't have an undo buffer."); return; }
message = p.name.ToLower() + " 30";
UndoSelf(p); return;
} else if (p != null && int.TryParse(message, out ignored)) {
message = p.name.ToLower() + " " + message;
}
@ -84,6 +84,32 @@ namespace MCGalaxy.Commands
return secs;
}
void UndoSelf(Player p) {
UndoDrawOpEntry[] entries = p.UndoDrawOps.Items;
if (entries.Length == 0) {
Player.SendMessage(p, "You have no draw operations to undo.");
Player.SendMessage(p, "Try using %T/undo <seconds> %Sinstead.");
return;
}
for (int i = entries.Length - 1; i >= 0; i--) {
UndoDrawOpEntry entry = entries[i];
if (entry.DrawOpName == "UndoSelf") continue;
UndoSelfDrawOp op = new UndoSelfDrawOp();
op.who = p;
op.Start = entry.Start; op.End = entry.End;
DrawOp.DoDrawOp(op, null, p, new [] { Vec3U16.MaxVal, Vec3U16.MaxVal } );
entry.UndoDrawOpName = entry.DrawOpName;
entry.DrawOpName = "UndoSelf";
return;
}
Player.SendMessage(p, "Max number of draw operations that can be undone reached.");
Player.SendMessage(p, "Try using %T/undo <seconds> %Sinstead.");
}
void UndoOnlinePlayer(Player p, long seconds, Player who) {
if (p != null && p != who) {
if (who.group.Permission > p.group.Permission) {

View File

@ -188,19 +188,16 @@ namespace MCGalaxy.Drawing.Ops {
entry.DrawOpName = op.Name;
entry.LevelName = p.level.name;
entry.Start = DateTime.UtcNow;
// Use same time method as DoBlockchange writing to undo buffer
int timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
entry.Start = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond);
bool needReveal = op.DetermineDrawOpMethod(p.level, affected);
op.Perform(marks, p, p.level, brush);
entry.End = DateTime.UtcNow;
timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
entry.End = Server.StartTime.AddTicks(timeDelta * TimeSpan.TicksPerSecond);
if (entry.Start > p.UndoBuffer.LastClear) {
UndoDrawOpEntry[] items = p.UndoDrawOps.Items;
if (items.Length == 25)
p.UndoDrawOps.Remove(items[0]);
} else { // UndoBuffer has been cleared during the draw op.
entry.Start = p.UndoBuffer.LastClear;
p.RemoveInvalidUndos();
}
if (op.Name != "UndoSelf")
p.UndoDrawOps.Add(entry);
DoReload(p, needReveal);
return true;

View File

@ -23,6 +23,10 @@ using MCGalaxy.Util;
namespace MCGalaxy.Drawing.Ops {
public class UndoSelfDrawOp : UndoOnlineDrawOp {
public override string Name { get { return "UndoSelf"; } }
}
public class UndoOnlineDrawOp : DrawOp {
public override string Name { get { return "UndoOnline"; } }

View File

@ -151,7 +151,7 @@ namespace MCGalaxy.Util {
}
public sealed class UndoDrawOpEntry {
public string DrawOpName;
public string DrawOpName, UndoDrawOpName;
public string LevelName;
public DateTime Start, End;
}