mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 14:17:29 -04:00
Core: Do more checks when replace commands are executed, rather than after both marks were placed.
This commit is contained in:
parent
10374e595c
commit
2b9a272a51
@ -30,40 +30,58 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (message == "") { Help(p); return; }
|
if (message == "") { Help(p); return; }
|
||||||
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
if (Player.IsSuper(p)) { MessageInGameOnly(p); return; }
|
||||||
|
|
||||||
string replaceCmd = ReplaceNot ? "replacenot" : "replace";
|
string replaceCmd = ReplaceNot ? "replacenot" : "replace";
|
||||||
if (!p.group.CanExecute(replaceCmd) || !p.group.CanExecute("brush")) {
|
if (!p.group.CanExecute(replaceCmd) || !p.group.CanExecute("brush")) {
|
||||||
Player.Message(p, "You cannot use /brush and/or /" + replaceCmd +
|
Player.Message(p, "You cannot use /brush and/or /" + replaceCmd +
|
||||||
", so therefore cannot use this command."); return;
|
", so therefore cannot use this command."); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = message.ToLower();
|
||||||
|
string[] parts = message.SplitSpaces(3);
|
||||||
|
if (!ValidateArgs(p, parts)) return;
|
||||||
|
|
||||||
Player.Message(p, "Place two blocks to determine the edges.");
|
Player.Message(p, "Place two blocks to determine the edges.");
|
||||||
p.MakeSelection(2, message.ToLower(), DoReplace);
|
p.MakeSelection(2, message, DoReplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
bool ValidateArgs(Player p, string[] args) {
|
||||||
string[] parts = ((string)state).SplitSpaces(3);
|
if (args.Length < 2) { Help(p); return false; }
|
||||||
if (parts.Length < 2) { Help(p); return false; }
|
|
||||||
|
|
||||||
byte extBlock = 0;
|
byte extBlock = 0;
|
||||||
int block = DrawCmd.GetBlockIfAllowed(p, parts[0], out extBlock);
|
int block = DrawCmd.GetBlockIfAllowed(p, args[0], out extBlock);
|
||||||
if (block == -1) return false;
|
if (block == -1) return false;
|
||||||
|
|
||||||
BrushFactory factory = BrushFactory.Find(parts[1]);
|
BrushFactory factory = BrushFactory.Find(args[1]);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
Player.Message(p, "No brush found with name \"{0}\".", parts[1]);
|
Player.Message(p, "No brush found with name \"{0}\".", args[1]);
|
||||||
Player.Message(p, "Available brushes: " + BrushFactory.Available);
|
Player.Message(p, "Available brushes: " + BrushFactory.Available);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string brushMessage = parts.Length > 2 ? parts[2].ToLower() : "";
|
string brushMessage = args.Length > 2 ? args[2] : "";
|
||||||
BrushArgs args = new BrushArgs(p, brushMessage, type, extType);
|
byte held, extHeld;
|
||||||
Brush brush = factory.Construct(args);
|
held = p.GetActualHeldBlock(out extHeld);
|
||||||
|
BrushArgs bArgs = new BrushArgs(p, brushMessage, held, extHeld);
|
||||||
|
return factory.Validate(bArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) {
|
||||||
|
string[] args = ((string)state).SplitSpaces(3);
|
||||||
|
byte extBlock = 0;
|
||||||
|
int block = DrawCmd.GetBlockIfAllowed(p, args[0], out extBlock);
|
||||||
|
if (block == -1) return false;
|
||||||
|
|
||||||
|
BrushFactory factory = BrushFactory.Find(args[1]);
|
||||||
|
string brushMessage = args.Length > 2 ? args[2] : "";
|
||||||
|
BrushArgs bArgs = new BrushArgs(p, brushMessage, type, extType);
|
||||||
|
Brush brush = factory.Construct(bArgs);
|
||||||
if (brush == null) return false;
|
if (brush == null) return false;
|
||||||
|
|
||||||
DrawOp drawOp = null;
|
DrawOp op = null;
|
||||||
if (ReplaceNot) drawOp = new ReplaceNotDrawOp((byte)block, extBlock);
|
if (ReplaceNot) op = new ReplaceNotDrawOp((byte)block, extBlock);
|
||||||
else drawOp = new ReplaceDrawOp((byte)block, extBlock);
|
else op = new ReplaceDrawOp((byte)block, extBlock);
|
||||||
return DrawOp.DoDrawOp(drawOp, brush, p, marks);
|
return DrawOp.DoDrawOp(op, brush, p, marks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool ReplaceNot { get { return false; } }
|
protected virtual bool ReplaceNot { get { return false; } }
|
||||||
|
@ -29,6 +29,14 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
protected virtual bool ReplaceNot { get { return false; } }
|
protected virtual bool ReplaceNot { get { return false; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
|
string brushMsg = message.ToLower();
|
||||||
|
byte block, extBlock;
|
||||||
|
block = p.GetActualHeldBlock(out extBlock);
|
||||||
|
|
||||||
|
BrushArgs args = new BrushArgs(p, brushMsg, block, extBlock);
|
||||||
|
string name = ReplaceNot ? "replacenot" : "replace";
|
||||||
|
if (!BrushFactory.Find(name).Validate(args)) return;
|
||||||
|
|
||||||
Player.Message(p, "Place two blocks to determine the edges.");
|
Player.Message(p, "Place two blocks to determine the edges.");
|
||||||
p.MakeSelection(2, message.ToLower(), DoReplace);
|
p.MakeSelection(2, message.ToLower(), DoReplace);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user