diff --git a/MCGalaxy/Commands/building/CmdReplaceBrush.cs b/MCGalaxy/Commands/building/CmdReplaceBrush.cs index ad4173212..5a1dca3af 100644 --- a/MCGalaxy/Commands/building/CmdReplaceBrush.cs +++ b/MCGalaxy/Commands/building/CmdReplaceBrush.cs @@ -30,40 +30,58 @@ namespace MCGalaxy.Commands.Building { public override void Use(Player p, string message) { if (message == "") { Help(p); return; } if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + string replaceCmd = ReplaceNot ? "replacenot" : "replace"; if (!p.group.CanExecute(replaceCmd) || !p.group.CanExecute("brush")) { Player.Message(p, "You cannot use /brush and/or /" + replaceCmd + ", 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."); - p.MakeSelection(2, message.ToLower(), DoReplace); + p.MakeSelection(2, message, DoReplace); } - bool DoReplace(Player p, Vec3S32[] marks, object state, byte type, byte extType) { - string[] parts = ((string)state).SplitSpaces(3); - if (parts.Length < 2) { Help(p); return false; } + bool ValidateArgs(Player p, string[] args) { + if (args.Length < 2) { Help(p); return false; } 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; - BrushFactory factory = BrushFactory.Find(parts[1]); + BrushFactory factory = BrushFactory.Find(args[1]); 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); return false; } - - string brushMessage = parts.Length > 2 ? parts[2].ToLower() : ""; - BrushArgs args = new BrushArgs(p, brushMessage, type, extType); - Brush brush = factory.Construct(args); + + string brushMessage = args.Length > 2 ? args[2] : ""; + byte held, extHeld; + 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; - DrawOp drawOp = null; - if (ReplaceNot) drawOp = new ReplaceNotDrawOp((byte)block, extBlock); - else drawOp = new ReplaceDrawOp((byte)block, extBlock); - return DrawOp.DoDrawOp(drawOp, brush, p, marks); + DrawOp op = null; + if (ReplaceNot) op = new ReplaceNotDrawOp((byte)block, extBlock); + else op = new ReplaceDrawOp((byte)block, extBlock); + return DrawOp.DoDrawOp(op, brush, p, marks); } protected virtual bool ReplaceNot { get { return false; } } diff --git a/MCGalaxy/Commands/building/ReplaceCmd.cs b/MCGalaxy/Commands/building/ReplaceCmd.cs index e7f4cf605..cd0678af4 100644 --- a/MCGalaxy/Commands/building/ReplaceCmd.cs +++ b/MCGalaxy/Commands/building/ReplaceCmd.cs @@ -29,6 +29,14 @@ namespace MCGalaxy.Commands.Building { protected virtual bool ReplaceNot { get { return false; } } 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."); p.MakeSelection(2, message.ToLower(), DoReplace); }