mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Made /centre, /zone, /undoarea use Selection code.
This commit is contained in:
parent
154d534f4b
commit
6ae7031e26
@ -29,78 +29,66 @@ namespace MCGalaxy.Commands {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
CatchPos cpos = default(CatchPos);
|
||||
UndoArgs args = default(UndoArgs);
|
||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||
if (message == "") { Player.Message(p, "You need to provide a player name."); return; }
|
||||
|
||||
string[] parts = message.Split(' ');
|
||||
cpos.message = parts[0];
|
||||
cpos.seconds = CmdUndo.GetSeconds(p, null, parts.Length > 1 ? parts[1] : "30");
|
||||
args.message = parts[0];
|
||||
args.seconds = CmdUndo.GetSeconds(p, null, parts.Length > 1 ? parts[1] : "30");
|
||||
|
||||
Player.Message(p, "Place two blocks to determine the edges.");
|
||||
p.ClearBlockchange();
|
||||
p.blockchangeObject = cpos;
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(2, args, DoUndo);
|
||||
}
|
||||
|
||||
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
cpos.x = x; cpos.y = y; cpos.z = z;
|
||||
p.blockchangeObject = cpos;
|
||||
p.Blockchange += PlacedMark2;
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
Player who = PlayerInfo.Find(cpos.message);
|
||||
bool DoUndo(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
UndoArgs args = (UndoArgs)state;
|
||||
Player who = PlayerInfo.Find(args.message);
|
||||
|
||||
if (who != null)
|
||||
UndoOnlinePlayer(p, who, cpos, x, y, z);
|
||||
else
|
||||
UndoOfflinePlayer(p, cpos.message, cpos, x, y, z);
|
||||
if (who != null) UndoOnlinePlayer(p, who, args, marks);
|
||||
else UndoOfflinePlayer(p, args.message, args, marks);
|
||||
return false;
|
||||
}
|
||||
|
||||
void UndoOnlinePlayer(Player p, Player who, CatchPos cpos, ushort x, ushort y, ushort z) {
|
||||
void UndoOnlinePlayer(Player p, Player who, UndoArgs args, Vec3S32[] marks) {
|
||||
if (p != who && who.group.Permission >= p.group.Permission) {
|
||||
MessageTooHighRank(p, "undo", false); return;
|
||||
}
|
||||
|
||||
UndoOnlineDrawOp op = new UndoOnlineDrawOp();
|
||||
op.Start = DateTime.UtcNow.AddTicks(-cpos.seconds * TimeSpan.TicksPerSecond);
|
||||
op.Start = DateTime.UtcNow.AddTicks(-args.seconds * TimeSpan.TicksPerSecond);
|
||||
op.who = who;
|
||||
DrawOp.DoDrawOp(op, null, p, cpos.x, cpos.y, cpos.z, x, y, z);
|
||||
DrawOp.DoDrawOp(op, null, p, marks);
|
||||
|
||||
Level saveLevel = op.saveLevel;
|
||||
Player.SendChatFrom(who, who.ColoredName +
|
||||
"%S's actions for the past &b" + cpos.seconds + " seconds were undone.", false);
|
||||
Server.s.Log(who.name + "'s actions for the past " + cpos.seconds + " seconds were undone.");
|
||||
"%S's actions for the past &b" + args.seconds + " seconds were undone.", false);
|
||||
Server.s.Log(who.name + "'s actions for the past " + args.seconds + " seconds were undone.");
|
||||
if (saveLevel != null) saveLevel.Save(true);
|
||||
}
|
||||
|
||||
void UndoOfflinePlayer(Player p, string whoName, CatchPos cpos, ushort x, ushort y, ushort z) {
|
||||
void UndoOfflinePlayer(Player p, string whoName, UndoArgs args, Vec3S32[] marks) {
|
||||
Group group = Group.findPlayerGroup(whoName);
|
||||
if (group.Permission >= p.group.Permission) {
|
||||
MessageTooHighRank(p, "undo", false); return;
|
||||
}
|
||||
|
||||
UndoOfflineDrawOp op = new UndoOfflineDrawOp();
|
||||
op.Start = DateTime.UtcNow.AddTicks(-cpos.seconds * TimeSpan.TicksPerSecond);
|
||||
op.Start = DateTime.UtcNow.AddTicks(-args.seconds * TimeSpan.TicksPerSecond);
|
||||
op.whoName = whoName;
|
||||
DrawOp.DoDrawOp(op, null, p, cpos.x, cpos.y, cpos.z, x, y, z);
|
||||
DrawOp.DoDrawOp(op, null, p, marks);
|
||||
|
||||
if (op.foundUser) {
|
||||
Player.GlobalMessage(group.color + whoName +
|
||||
"%S's actions for the past &b" + cpos.seconds + " %Sseconds were undone.");
|
||||
Server.s.Log(whoName + "'s actions for the past " + cpos.seconds + " seconds were undone.");
|
||||
"%S's actions for the past &b" + args.seconds + " %Sseconds were undone.");
|
||||
Server.s.Log(whoName + "'s actions for the past " + args.seconds + " seconds were undone.");
|
||||
p.level.Save(true);
|
||||
} else {
|
||||
Player.Message(p, "Could not find player specified.");
|
||||
}
|
||||
}
|
||||
|
||||
struct CatchPos { public ushort x, y, z; public string message; public long seconds; }
|
||||
struct UndoArgs { public string message; public long seconds; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/undoarea [player] [seconds]");
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
CatchPos cpos;
|
||||
string owner = null;
|
||||
if (message == "") {
|
||||
p.ZoneCheck = true;
|
||||
Player.Message(p, "Place a block where you would like to check for zones.");
|
||||
@ -89,48 +89,34 @@ namespace MCGalaxy.Commands {
|
||||
{
|
||||
Player foundPlayer = PlayerInfo.Find(message.Split(' ')[1]);
|
||||
if (foundPlayer == null)
|
||||
cpos.Owner = message.Split(' ')[1].ToString();
|
||||
owner = message.Split(' ')[1].ToString();
|
||||
else
|
||||
cpos.Owner = foundPlayer.name;
|
||||
owner = foundPlayer.name;
|
||||
}
|
||||
else { Help(p); return; }
|
||||
|
||||
if (!ValidName(p, cpos.Owner, "player or rank")) return;
|
||||
|
||||
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
|
||||
if (!ValidName(p, owner, "player or rank")) return;
|
||||
|
||||
Player.Message(p, "Place two blocks to determine the edges.");
|
||||
Player.Message(p, "Zone for: &b" + cpos.Owner + ".");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += Blockchange1;
|
||||
Player.Message(p, "Zone for: &b" + owner + ".");
|
||||
p.MakeSelection(2, owner, DoZone);
|
||||
}
|
||||
|
||||
void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos bp = (CatchPos)p.blockchangeObject;
|
||||
bp.x = x; bp.y = y; bp.z = z; p.blockchangeObject = bp;
|
||||
p.Blockchange += Blockchange2;
|
||||
}
|
||||
|
||||
void Blockchange2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
|
||||
|
||||
bool DoZone(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
Level.Zone Zn;
|
||||
Zn.smallX = Math.Min(cpos.x, x);
|
||||
Zn.smallY = Math.Min(cpos.y, y);
|
||||
Zn.smallZ = Math.Min(cpos.z, z);
|
||||
Zn.bigX = Math.Max(cpos.x, x);
|
||||
Zn.bigY = Math.Max(cpos.y, y);
|
||||
Zn.bigZ = Math.Max(cpos.z, z);
|
||||
Zn.Owner = cpos.Owner;
|
||||
Zn.smallX = (ushort)Math.Min(m[0].X, m[1].X);
|
||||
Zn.smallY = (ushort)Math.Min(m[0].Y, m[1].Y);
|
||||
Zn.smallZ = (ushort)Math.Min(m[0].Z, m[1].Z);
|
||||
Zn.bigX = (ushort)Math.Max(m[0].X, m[1].X);
|
||||
Zn.bigY = (ushort)Math.Max(m[0].Y, m[1].Y);
|
||||
Zn.bigZ = (ushort)Math.Max(m[0].Z, m[1].Z);
|
||||
Zn.Owner = (string)state;
|
||||
|
||||
p.level.ZoneList.Add(Zn);
|
||||
Zones.Create(p.level.name, Zn);
|
||||
Player.Message(p, "Added zone for &b" + cpos.Owner);
|
||||
Player.Message(p, "Added zone for &b" + (string)state);
|
||||
return false;
|
||||
}
|
||||
|
||||
struct CatchPos { public ushort x, y, z; public string Owner; }
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "/zone [add] [name] - Creates a zone only [name] can build in");
|
||||
|
@ -12,21 +12,14 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override void Use(Player p, string message) {
|
||||
Player.Message(p, "Place two blocks to determine the edges.");
|
||||
p.ClearBlockchange();
|
||||
p.Blockchange += PlacedMark1;
|
||||
}
|
||||
|
||||
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
p.blockchangeObject = new Vec3U16(x, y, z);
|
||||
p.Blockchange += PlacedMark2;
|
||||
p.MakeSelection(2, null, DoCentre);
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
Vec3U16 start = (Vec3U16)p.blockchangeObject;
|
||||
int xCen = (start.X + x) / 2, yCen = (start.Y + y) / 2, zCen = (start.Z + z) / 2;
|
||||
bool DoCentre(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
int xCen = (m[0].X + m[1].X) / 2, yCen = (m[0].Y + m[1].Y) / 2, zCen = (m[0].Z + m[1].Z) / 2;
|
||||
p.level.UpdateBlock(p, (ushort)xCen, (ushort)yCen, (ushort)zCen, Block.goldsolid, 0);
|
||||
Player.Message(p, "A gold block was placed at (" + xCen + ", " + yCen + ", " + zCen + ").");
|
||||
Player.Message(p, "A gold block was placed at ({0}, {1}, {2}).", xCen, yCen, zCen);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
DrawOp op = null;
|
||||
Func<BrushArgs, Brush> constructor = null;
|
||||
|
@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
AdvDrawOp op = null;
|
||||
switch (cpos.mode) {
|
||||
|
@ -39,7 +39,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;
|
||||
byte oldType = p.level.GetTile(x, y, z), oldExtType = 0;
|
||||
if (oldType == Block.custom_block)
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
return DrawMode.normal;
|
||||
}
|
||||
|
||||
protected override void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) {
|
||||
protected override void OnUse(Player p, string msg, string[] parts, ref DrawArgs cpos) {
|
||||
if (parts.Length < 2 || cpos.mode == DrawMode.normal) return;
|
||||
string arg = parts[parts.Length - 1];
|
||||
ushort len;
|
||||
@ -53,7 +53,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
|
||||
if (cpos.mode == DrawMode.straight) {
|
||||
|
@ -27,42 +27,24 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
CatchPos cpos = default(CatchPos);
|
||||
if (message.Length > 0 && !int.TryParse(message, out cpos.randomizer)) {
|
||||
int randomizer = 0;
|
||||
if (message.Length > 0 && !int.TryParse(message, out randomizer)) {
|
||||
Help(p); return;
|
||||
}
|
||||
|
||||
Player.Message(p, "Place two blocks to determine the edges.");
|
||||
p.ClearBlockchange();
|
||||
p.blockchangeObject = cpos;
|
||||
p.Blockchange += PlacedMark1;
|
||||
p.MakeSelection(2, randomizer, DoMaze);
|
||||
}
|
||||
|
||||
void PlacedMark1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
cpos.x = x; cpos.y = y; cpos.z = z;
|
||||
p.blockchangeObject = cpos;
|
||||
p.Blockchange += PlacedMark2;
|
||||
}
|
||||
|
||||
void PlacedMark2(Player p, ushort x, ushort y, ushort z, byte type, byte extType) {
|
||||
RevertAndClearState(p, x, y, z);
|
||||
CatchPos cpos = (CatchPos)p.blockchangeObject;
|
||||
MazeDrawOp drawOp = new MazeDrawOp();
|
||||
drawOp.randomizer = cpos.randomizer;
|
||||
|
||||
if (!DrawOp.DoDrawOp(drawOp, null, p, cpos.x, cpos.y, cpos.z, x, y, z))
|
||||
return;
|
||||
if (p.staticCommands)
|
||||
p.Blockchange += PlacedMark1;
|
||||
bool DoMaze(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
MazeDrawOp op = new MazeDrawOp();
|
||||
op.randomizer = (int)state;
|
||||
return DrawOp.DoDrawOp(op, null, p, marks);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/maze");
|
||||
Player.Message(p, "%HGenerates a random maze between two points.");
|
||||
}
|
||||
|
||||
struct CatchPos { public ushort x, y, z; public int randomizer; }
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override string shortcut { get { return "pd"; } }
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
DrawOp drawOp = null;
|
||||
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
|
||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
|
||||
DrawOp op = null;
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
DrawOp op = null;
|
||||
int brushOffset = cpos.mode == DrawMode.normal ? 0 : 1;
|
||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
protected override string PlaceMessage { get { return "Place a block for the centre, then another for the radius."; } }
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] m, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
|
||||
DrawOp drawOp = new TorusDrawOp();
|
||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
protected override bool DoDraw(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||
CatchPos cpos = (CatchPos)state;
|
||||
DrawArgs cpos = (DrawArgs)state;
|
||||
GetRealBlock(type, extType, p, ref cpos);
|
||||
|
||||
Brush brush = GetBrush(p, cpos, 0, null);
|
||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||
message = message.ToLower();
|
||||
string[] parts = message.Split(' ');
|
||||
CatchPos cpos = default(CatchPos);
|
||||
DrawArgs cpos = default(DrawArgs);
|
||||
cpos.message = message;
|
||||
cpos.mode = GetMode(message, parts);
|
||||
OnUse(p, message, parts, ref cpos);
|
||||
@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
protected abstract DrawMode ParseMode(string mode);
|
||||
|
||||
protected virtual void OnUse(Player p, string msg, string[] parts, ref CatchPos cpos) { }
|
||||
protected virtual void OnUse(Player p, string msg, string[] parts, ref DrawArgs cpos) { }
|
||||
|
||||
protected virtual DrawMode GetMode(string message, string[] parts) {
|
||||
return message == "" ? DrawMode.normal : ParseMode(parts[parts.Length - 1]);
|
||||
@ -71,28 +71,28 @@ namespace MCGalaxy.Commands.Building {
|
||||
return type;
|
||||
}
|
||||
|
||||
protected static Brush GetBrush(Player p, CatchPos cpos,
|
||||
protected static Brush GetBrush(Player p, DrawArgs dArgs,
|
||||
int usedFromEnd, Func<BrushArgs, Brush> constructor = null) {
|
||||
int end = cpos.message.Length;
|
||||
int end = dArgs.message.Length;
|
||||
string brushMsg = "";
|
||||
for (int i = 0; i < usedFromEnd; i++) {
|
||||
end = cpos.message.LastIndexOf(' ', end - 1);
|
||||
end = dArgs.message.LastIndexOf(' ', end - 1);
|
||||
if (end == -1) break;
|
||||
}
|
||||
|
||||
if (end >= 0) brushMsg = cpos.message.Substring(0, end);
|
||||
if (end >= 0) brushMsg = dArgs.message.Substring(0, end);
|
||||
if (brushMsg == "") brushMsg = p.DefaultBrushArgs;
|
||||
if (constructor == null) constructor = Brush.Brushes[p.BrushName];
|
||||
BrushArgs args = new BrushArgs(p, brushMsg, cpos.type, cpos.extType);
|
||||
BrushArgs args = new BrushArgs(p, brushMsg, dArgs.type, dArgs.extType);
|
||||
return constructor(args);
|
||||
}
|
||||
|
||||
protected static void GetRealBlock(byte type, byte extType, Player p, ref CatchPos cpos) {
|
||||
protected static void GetRealBlock(byte type, byte extType, Player p, ref DrawArgs cpos) {
|
||||
cpos.type = type < 128 ? p.bindings[type] : type;
|
||||
cpos.extType = extType;
|
||||
}
|
||||
|
||||
protected struct CatchPos {
|
||||
protected struct DrawArgs {
|
||||
public DrawMode mode;
|
||||
public byte type, extType;
|
||||
public object data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user