mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-19 04:07:10 -04:00
Improve DrawOp documentation and prefer explicit GetBlockIfAllowed instead
This commit is contained in:
parent
fd0ca4a12a
commit
a66a22c644
@ -202,6 +202,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
/// <summary> Attempts to parse the given argument as either a block name or a block ID. </summary>
|
/// <summary> Attempts to parse the given argument as either a block name or a block ID. </summary>
|
||||||
/// <remarks> Also ensures the player is allowed to place the given block. </remarks>
|
/// <remarks> Also ensures the player is allowed to place the given block. </remarks>
|
||||||
|
[Obsolete("Use GetBlockIfAllowed with explicit action argument instead")]
|
||||||
public static bool GetBlockIfAllowed(Player p, string input, out BlockID block, bool allowSkip = false) {
|
public static bool GetBlockIfAllowed(Player p, string input, out BlockID block, bool allowSkip = false) {
|
||||||
return GetBlockIfAllowed(p, input, "draw with", out block, allowSkip);
|
return GetBlockIfAllowed(p, input, "draw with", out block, allowSkip);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CheckResetPerms(Player p, CommandData data) {
|
bool CheckResetPerms(Player p, CommandData data) {
|
||||||
// check server owner name for backwards compatibility
|
// check server owner name for permissions backwards compatibility
|
||||||
return Server.Config.OwnerName.CaselessEq(p.name) || CheckExtraPerm(p, data, 1);
|
return Server.Config.OwnerName.CaselessEq(p.name) || CheckExtraPerm(p, data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,13 +26,14 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||||
|
|
||||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||||
|
Player p = dArgs.Player;
|
||||||
if (dArgs.Message.Length == 0) {
|
if (dArgs.Message.Length == 0) {
|
||||||
dArgs.Player.Message("Block name is required."); return null;
|
p.Message("Block name is required."); return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockID target;
|
BlockID target;
|
||||||
string[] parts = dArgs.Message.SplitSpaces(2);
|
string[] parts = dArgs.Message.SplitSpaces(2);
|
||||||
if (!CommandParser.GetBlockIfAllowed(dArgs.Player, parts[0], out target)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[0], "draw with", out target)) return null;
|
||||||
|
|
||||||
OutlineDrawOp op = new OutlineDrawOp();
|
OutlineDrawOp op = new OutlineDrawOp();
|
||||||
// e.g. testing air 'above' grass - therefore op.Above needs to be false for 'up mode'
|
// e.g. testing air 'above' grass - therefore op.Above needs to be false for 'up mode'
|
||||||
|
@ -40,7 +40,7 @@ namespace MCGalaxy.Commands.Building {
|
|||||||
|
|
||||||
|
|
||||||
BlockID target;
|
BlockID target;
|
||||||
if (!CommandParser.GetBlockIfAllowed(p, args[0], out target)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, args[0], "draw with", out target)) return null;
|
||||||
|
|
||||||
BrushFactory factory = BrushFactory.Find(args[1]);
|
BrushFactory factory = BrushFactory.Find(args[1]);
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
|
@ -46,7 +46,7 @@ namespace MCGalaxy.Drawing.Brushes
|
|||||||
|
|
||||||
int sepIndex = parts[i].IndexOf('/');
|
int sepIndex = parts[i].IndexOf('/');
|
||||||
string arg = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
|
string arg = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
|
||||||
if (!CommandParser.GetBlockIfAllowed(p, arg, out blocks[j], true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, arg, "draw with", out blocks[j], true)) return null;
|
||||||
|
|
||||||
if (sepIndex >= 0) {
|
if (sepIndex >= 0) {
|
||||||
arg = parts[i].Substring(sepIndex + 1);
|
arg = parts[i].Substring(sepIndex + 1);
|
||||||
|
@ -56,23 +56,25 @@ namespace MCGalaxy.Drawing.Brushes
|
|||||||
for (int i = 0; i < blocks.Length; i++)
|
for (int i = 0; i < blocks.Length; i++)
|
||||||
blocks[i] = Block.Invalid;
|
blocks[i] = Block.Invalid;
|
||||||
|
|
||||||
for (int i = 0; start < max; start++, i++ ) {
|
for (int i = 0; start < max; start++, i++)
|
||||||
|
{
|
||||||
BlockID block;
|
BlockID block;
|
||||||
if (!CommandParser.GetBlockIfAllowed(p, parts[start], out block)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[start], "draw with", out block)) return null;
|
||||||
|
|
||||||
blocks[i] = block;
|
blocks[i] = block;
|
||||||
}
|
}
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool GetTargetBlock(BrushArgs args, string[] parts, out BlockID target) {
|
static bool GetTargetBlock(BrushArgs args, string[] parts, out BlockID target) {
|
||||||
|
Player p = args.Player;
|
||||||
target = 0;
|
target = 0;
|
||||||
|
|
||||||
if (parts.Length == 1) {
|
if (parts.Length == 1) {
|
||||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return false;
|
if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return false;
|
||||||
|
|
||||||
target = args.Block; return true;
|
target = args.Block; return true;
|
||||||
}
|
}
|
||||||
return CommandParser.GetBlockIfAllowed(args.Player, parts[parts.Length - 1], out target);
|
return CommandParser.GetBlockIfAllowed(p, parts[parts.Length - 1], "draw with", out target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,20 +33,21 @@ namespace MCGalaxy.Drawing.Brushes
|
|||||||
};
|
};
|
||||||
|
|
||||||
public override Brush Construct(BrushArgs args) {
|
public override Brush Construct(BrushArgs args) {
|
||||||
|
Player p = args.Player;
|
||||||
if (args.Message.Length == 0) {
|
if (args.Message.Length == 0) {
|
||||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return null;
|
||||||
return new SolidBrush(args.Block);
|
return new SolidBrush(args.Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockID block;
|
BlockID block;
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, args.Message, out block)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, args.Message, "draw with", out block)) return null;
|
||||||
return new SolidBrush(block);
|
return new SolidBrush(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Validate(BrushArgs args) {
|
public override bool Validate(BrushArgs args) {
|
||||||
if (args.Message.Length == 0) return true;
|
if (args.Message.Length == 0) return true;
|
||||||
BlockID block;
|
BlockID block;
|
||||||
return CommandParser.GetBlockIfAllowed(args.Player, args.Message, out block);
|
return CommandParser.GetBlockIfAllowed(args.Player, args.Message, "draw with", out block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,26 +64,27 @@ namespace MCGalaxy.Drawing.Brushes
|
|||||||
};
|
};
|
||||||
|
|
||||||
public override Brush Construct(BrushArgs args) {
|
public override Brush Construct(BrushArgs args) {
|
||||||
|
Player p = args.Player;
|
||||||
if (args.Message.Length == 0) {
|
if (args.Message.Length == 0) {
|
||||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return null;
|
||||||
return new CheckeredBrush(args.Block, Block.Invalid);
|
return new CheckeredBrush(args.Block, Block.Invalid);
|
||||||
}
|
}
|
||||||
string[] parts = args.Message.SplitSpaces();
|
string[] parts = args.Message.SplitSpaces();
|
||||||
|
|
||||||
BlockID block1;
|
BlockID block1;
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, parts[0], out block1, true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[0], "draw with", out block1, true)) return null;
|
||||||
if (parts.Length == 1)
|
if (parts.Length == 1)
|
||||||
return new CheckeredBrush(block1, Block.Invalid);
|
return new CheckeredBrush(block1, Block.Invalid);
|
||||||
|
|
||||||
if (parts.Length == 2) {
|
if (parts.Length == 2) {
|
||||||
BlockID block2;
|
BlockID block2;
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, parts[1], out block2, true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[1], "draw with", out block2, true)) return null;
|
||||||
return new CheckeredBrush(block1, block2);
|
return new CheckeredBrush(block1, block2);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockID[] blocks = new BlockID[parts.Length];
|
BlockID[] blocks = new BlockID[parts.Length];
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, parts[i], out blocks[i], true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[i], "draw with", out blocks[i], true)) return null;
|
||||||
}
|
}
|
||||||
return new CheckeredPaletteBrush(blocks);
|
return new CheckeredPaletteBrush(blocks);
|
||||||
}
|
}
|
||||||
@ -138,19 +140,20 @@ namespace MCGalaxy.Drawing.Brushes
|
|||||||
};
|
};
|
||||||
|
|
||||||
public override Brush Construct(BrushArgs args) {
|
public override Brush Construct(BrushArgs args) {
|
||||||
|
Player p = args.Player;
|
||||||
if (args.Message.Length == 0) {
|
if (args.Message.Length == 0) {
|
||||||
if (!CommandParser.IsBlockAllowed(args.Player, "draw with", args.Block)) return null;
|
if (!CommandParser.IsBlockAllowed(p, "draw with", args.Block)) return null;
|
||||||
return new StripedBrush(args.Block, Block.Air);
|
return new StripedBrush(args.Block, Block.Air);
|
||||||
}
|
}
|
||||||
string[] parts = args.Message.SplitSpaces();
|
string[] parts = args.Message.SplitSpaces();
|
||||||
|
|
||||||
BlockID block1;
|
BlockID block1;
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, parts[0], out block1, true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[0], "draw with", out block1, true)) return null;
|
||||||
if (parts.Length == 1)
|
if (parts.Length == 1)
|
||||||
return new StripedBrush(block1, Block.Air);
|
return new StripedBrush(block1, Block.Air);
|
||||||
|
|
||||||
BlockID block2;
|
BlockID block2;
|
||||||
if (!CommandParser.GetBlockIfAllowed(args.Player, parts[1], out block2, true)) return null;
|
if (!CommandParser.GetBlockIfAllowed(p, parts[1], "draw with", out block2, true)) return null;
|
||||||
return new StripedBrush(block1, block2);
|
return new StripedBrush(block1, block2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,26 +40,26 @@ namespace MCGalaxy.Drawing.Ops
|
|||||||
//public long TotalAffected; // blocks affected by the draw operation
|
//public long TotalAffected; // blocks affected by the draw operation
|
||||||
public long TotalModified; // blocks actually modified (e.g. some may not be due to permissions)
|
public long TotalModified; // blocks actually modified (e.g. some may not be due to permissions)
|
||||||
|
|
||||||
/// <summary> Minimum coordinates of the bounds of this drawing command. </summary>
|
/// <summary> Minimum coordinates of the bounds of this draw operation </summary>
|
||||||
public Vec3S32 Min;
|
public Vec3S32 Min;
|
||||||
|
|
||||||
/// <summary> Maximum coordinates of the bounds of this drawing command. </summary>
|
/// <summary> Maximum coordinates of the bounds of this draw operation </summary>
|
||||||
public Vec3S32 Max;
|
public Vec3S32 Max;
|
||||||
|
|
||||||
/// <summary> Coordinates of the first point selected by the user. </summary>
|
/// <summary> Coordinates of the first point selected by the player </summary>
|
||||||
public Vec3S32 Origin;
|
public Vec3S32 Origin;
|
||||||
|
|
||||||
/// <summary> Coordinates of the current block being processed by the drawing command. </summary>
|
/// <summary> Coordinates of the current block being processed by this draw operation </summary>
|
||||||
/// <remarks> Note: You should treat this as coordinates, it is a DrawOpBlock struct for performance reasons. </remarks>
|
/// <remarks> Note: You should treat this as coordinates, it is a DrawOpBlock struct for performance reasons. </remarks>
|
||||||
public DrawOpBlock Coords;
|
public DrawOpBlock Coords;
|
||||||
|
|
||||||
/// <summary> Player that is executing the draw operation. </summary>
|
/// <summary> Player that is executing this draw operation </summary>
|
||||||
public Player Player;
|
public Player Player;
|
||||||
|
|
||||||
/// <summary> Level the draw operation is being performed upon. </summary>
|
/// <summary> Level that this draw operation is being performed on </summary>
|
||||||
public Level Level;
|
public Level Level;
|
||||||
|
|
||||||
/// <summary> BlockDB change flags for blocks affected by this draw operation. </summary>
|
/// <summary> BlockDB change flags for blocks affected by this draw operation </summary>
|
||||||
public ushort Flags = BlockDBFlags.Drawn;
|
public ushort Flags = BlockDBFlags.Drawn;
|
||||||
|
|
||||||
/// <summary> Lock held on the associated level's BlockDB. Can be null. </summary>
|
/// <summary> Lock held on the associated level's BlockDB. Can be null. </summary>
|
||||||
@ -78,8 +78,8 @@ namespace MCGalaxy.Drawing.Ops
|
|||||||
/// <summary> Whether the output of this draw operation is affected by the player's current Transform. </summary>
|
/// <summary> Whether the output of this draw operation is affected by the player's current Transform. </summary>
|
||||||
public bool AffectedByTransform = true;
|
public bool AffectedByTransform = true;
|
||||||
|
|
||||||
/// <summary> Estimates the total number of blocks that the drawing commands affects. <br/>
|
/// <summary> Estimates the total number of blocks that this draw operation may affect. </summary>
|
||||||
/// Note that this estimate assumes that all possibly affected blocks will be changed by the drawing command. </summary>
|
/// <remarks> This estimate assumes that all potentially affected blocks will be changed by the draw operation </remarks>
|
||||||
public abstract long BlocksAffected(Level lvl, Vec3S32[] marks);
|
public abstract long BlocksAffected(Level lvl, Vec3S32[] marks);
|
||||||
|
|
||||||
public abstract void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output);
|
public abstract void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user