mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 07:11:04 -04:00
Add /replacebrush and /replacenotbrush.
This commit is contained in:
parent
bcaf2e43d3
commit
3bb6f9aa45
@ -221,7 +221,9 @@ namespace MCGalaxy
|
|||||||
all.Add(new CmdRepeat());
|
all.Add(new CmdRepeat());
|
||||||
all.Add(new CmdReplace());
|
all.Add(new CmdReplace());
|
||||||
all.Add(new CmdReplaceAll());
|
all.Add(new CmdReplaceAll());
|
||||||
|
all.Add(new CmdReplaceBrush());
|
||||||
all.Add(new CmdReplaceNot());
|
all.Add(new CmdReplaceNot());
|
||||||
|
all.Add(new CmdReplaceNotBrush());
|
||||||
all.Add(new CmdReport());
|
all.Add(new CmdReport());
|
||||||
all.Add(new CmdResetBot());
|
all.Add(new CmdResetBot());
|
||||||
all.Add(new CmdResetPass());
|
all.Add(new CmdResetPass());
|
||||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string src = args[0], dst = args[1];
|
string src = args[0], dst = args[1];
|
||||||
if (!p.group.CanExecute(Command.all.Find("newlvl"))) {
|
if (!p.group.CanExecute("newlvl")) {
|
||||||
Player.SendMessage(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
|
Player.SendMessage(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
|
||||||
}
|
}
|
||||||
if (!Player.ValidName(src)) { Player.SendMessage(p, "\"" + src + "\" is not a valid level name."); return; }
|
if (!Player.ValidName(src)) { Player.SendMessage(p, "\"" + src + "\" is not a valid level name."); return; }
|
||||||
|
@ -105,7 +105,7 @@ namespace MCGalaxy.Commands {
|
|||||||
if (!p.ignorePermission && p.group.Permission < lvl.permissionvisit) {
|
if (!p.ignorePermission && p.group.Permission < lvl.permissionvisit) {
|
||||||
Player.SendMessage(p, "You're not allowed to go to " + lvl.name + "."); return false;
|
Player.SendMessage(p, "You're not allowed to go to " + lvl.name + "."); return false;
|
||||||
}
|
}
|
||||||
if (!p.ignorePermission && p.group.Permission > lvl.pervisitmax && !p.group.CanExecute(Command.all.Find("pervisitmax"))) {
|
if (!p.ignorePermission && p.group.Permission > lvl.pervisitmax && !p.group.CanExecute("pervisitmax")) {
|
||||||
Player.SendMessage(p, "Your rank must be " + lvl.pervisitmax + " or lower to go there!"); return false;
|
Player.SendMessage(p, "Your rank must be " + lvl.pervisitmax + " or lower to go there!"); return false;
|
||||||
}
|
}
|
||||||
if (File.Exists("text/lockdown/map/" + message.ToLower())) {
|
if (File.Exists("text/lockdown/map/" + message.ToLower())) {
|
||||||
|
@ -17,38 +17,98 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using MCGalaxy;
|
using MCGalaxy;
|
||||||
|
using MCGalaxy.Drawing;
|
||||||
using MCGalaxy.Drawing.Brushes;
|
using MCGalaxy.Drawing.Brushes;
|
||||||
|
using MCGalaxy.Drawing.Ops;
|
||||||
namespace MCGalaxy.Commands {
|
|
||||||
|
|
||||||
public sealed class CmdReplaceBrush : Command {
|
|
||||||
public override string name { get { return "replacebrush"; } }
|
|
||||||
public override string shortcut { get { return "rb"; } }
|
|
||||||
public override string type { get { return CommandTypes.Building; } }
|
|
||||||
public override bool museumUsable { get { return false; } }
|
|
||||||
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
|
||||||
static char[] trimChars = {' '};
|
|
||||||
|
|
||||||
public override void Use(Player p, string message) {
|
namespace MCGalaxy.Commands {
|
||||||
// TODO: make sure can use or brush first.
|
|
||||||
if (message == "") { Help(p); return; }
|
public class CmdReplaceBrush : Command {
|
||||||
if (p == null) { MessageInGameOnly(p); return; }
|
public override string name { get { return "replacebrush"; } }
|
||||||
string[] args = message.Split(trimChars, 3);
|
public override string shortcut { get { return "rb"; } }
|
||||||
if (args.Length < 2) { Help(p); return }
|
public override string type { get { return CommandTypes.Building; } }
|
||||||
|
public override bool museumUsable { get { return false; } }
|
||||||
byte extType = 0;
|
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
|
||||||
byte type = DrawCmd.GetBlock(p, args[0], out extType);
|
static char[] trimChars = {' '};
|
||||||
string brush = CmdBrush.FindBrush(args[1]);
|
|
||||||
if (brush == null) {
|
public override void Use(Player p, string message) {
|
||||||
Player.SendMessage(p, "No brush found with name \"" + message + "\".");
|
if (message == "") { Help(p); return; }
|
||||||
Player.SendMessage(p, "Available brushes: " + CmdBrush.AvailableBrushes);
|
if (p == null) { MessageInGameOnly(p); return; }
|
||||||
return;
|
string replaceCmd = ReplaceNot ? "replacenot" : "replace";
|
||||||
}
|
if (!p.group.CanExecute(replaceCmd) || !p.group.CanExecute("brush")) {
|
||||||
}
|
Player.SendMessage(p, "You cannot use /brush and/or /" + replaceCmd +
|
||||||
|
", so therefore cannot use this command."); return;
|
||||||
public override void Help(Player p) {
|
}
|
||||||
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
|
|
||||||
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
|
CatchPos cpos = default(CatchPos);
|
||||||
}
|
cpos.message = message.ToLower();
|
||||||
}
|
p.blockchangeObject = cpos;
|
||||||
|
|
||||||
|
Player.SendMessage(p, "Place two blocks to determine the edges.");
|
||||||
|
p.ClearBlockchange();
|
||||||
|
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 += new Player.BlockchangeEventHandler(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;
|
||||||
|
type = type < 128 ? p.bindings[type] : type;
|
||||||
|
|
||||||
|
string[] parts = cpos.message.Split(trimChars, 3);
|
||||||
|
if (parts.Length < 2) { Help(p); return; }
|
||||||
|
|
||||||
|
byte extTile = 0;
|
||||||
|
byte tile = DrawCmd.GetBlock(p, parts[0], out extTile);
|
||||||
|
if (tile == Block.Zero) return;
|
||||||
|
string brushName = CmdBrush.FindBrush(parts[1]);
|
||||||
|
if (brushName == null) {
|
||||||
|
Player.SendMessage(p, "No brush found with name \"" + parts[1] + "\".");
|
||||||
|
Player.SendMessage(p, "Available brushes: " + CmdBrush.AvailableBrushes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string brushMessage = parts.Length > 2 ? parts[2].ToLower() : "";
|
||||||
|
BrushArgs args = new BrushArgs(p, brushMessage, type, extType);
|
||||||
|
Brush brush = Brush.Brushes[brushName](args);
|
||||||
|
if (brush == null) return;
|
||||||
|
|
||||||
|
DrawOp drawOp = null;
|
||||||
|
if (ReplaceNot) drawOp = new ReplaceNotDrawOp(tile, extTile);
|
||||||
|
else drawOp = new ReplaceDrawOp(tile, extTile);
|
||||||
|
|
||||||
|
if (!DrawOp.DoDrawOp(drawOp, brush, p, cpos.x, cpos.y, cpos.z, x, y, z))
|
||||||
|
return;
|
||||||
|
if (p.staticCommands)
|
||||||
|
p.Blockchange += new Player.BlockchangeEventHandler(Blockchange1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual bool ReplaceNot { get { return false; } }
|
||||||
|
|
||||||
|
struct CatchPos { public ushort x, y, z; public string message; }
|
||||||
|
|
||||||
|
public override void Help(Player p) {
|
||||||
|
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
|
||||||
|
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CmdReplaceNotBrush : CmdReplaceBrush {
|
||||||
|
public override string name { get { return "replacenotbrush"; } }
|
||||||
|
public override string shortcut { get { return "r b"; } }
|
||||||
|
|
||||||
|
protected override bool ReplaceNot { get { return true; } }
|
||||||
|
|
||||||
|
public override void Help(Player p) {
|
||||||
|
Player.SendMessage(p, "/replace [block] [block2].. [new] - replace block with new inside a selected cuboid");
|
||||||
|
Player.SendMessage(p, "If more than one [block] is specified, they will all be replaced.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ namespace MCGalaxy.Commands
|
|||||||
if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) {
|
if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) {
|
||||||
Player.SendMessage(p, "Reserved for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return;
|
Player.SendMessage(p, "Reserved for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 2)).name + "+"); return;
|
||||||
}
|
}
|
||||||
if (p != null && !p.group.CanExecute(Command.all.Find("physics"))) {
|
if (p != null && !p.group.CanExecute("physics")) {
|
||||||
Player.SendMessage(p, "You can only undo physics if you can use /physics."); return;
|
Player.SendMessage(p, "You can only undo physics if you can use /physics."); return;
|
||||||
}
|
}
|
||||||
Command.all.Find("physics").Use(p, "0");
|
Command.all.Find("physics").Use(p, "0");
|
||||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (p == null) { MessageInGameOnly(p); return; }
|
if (p == null) { MessageInGameOnly(p); return; }
|
||||||
if (!p.group.CanExecute(Command.all.Find("write"))) {
|
if (!p.group.CanExecute("write")) {
|
||||||
Player.SendMessage(p, "You must be able to use /write to use /writetext."); return;
|
Player.SendMessage(p, "You must be able to use /write to use /writetext."); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,13 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public struct FillPos { public ushort X, Y, Z; }
|
public struct FillPos { public ushort X, Y, Z; }
|
||||||
|
|
||||||
public struct ExtBlock { public byte Type, ExtType; }
|
public struct ExtBlock {
|
||||||
|
public byte Type, ExtType;
|
||||||
|
|
||||||
|
public ExtBlock(byte type, byte extType) {
|
||||||
|
Type = type; ExtType = extType;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MCGalaxy.Drawing.Ops {
|
namespace MCGalaxy.Drawing.Ops {
|
||||||
|
@ -22,8 +22,11 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public class ReplaceDrawOp : DrawOp {
|
public class ReplaceDrawOp : DrawOp {
|
||||||
|
|
||||||
public ExtBlock[] ToReplace;
|
public ExtBlock Include;
|
||||||
public ExtBlock Target;
|
|
||||||
|
public ReplaceDrawOp(byte type, byte extType) {
|
||||||
|
Include = new ExtBlock(type, extType);
|
||||||
|
}
|
||||||
|
|
||||||
public override string Name { get { return "Replace"; } }
|
public override string Name { get { return "Replace"; } }
|
||||||
|
|
||||||
@ -33,8 +36,6 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
|
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
|
||||||
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
|
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
|
||||||
ExtBlock[] toReplace = ToReplace;
|
|
||||||
ExtBlock target = Target;
|
|
||||||
for (ushort y = y1; y <= y2; y++)
|
for (ushort y = y1; y <= y2; y++)
|
||||||
for (ushort z = z1; z <= z2; z++)
|
for (ushort z = z1; z <= z2; z++)
|
||||||
for (ushort x = x1; x <= x2; x++)
|
for (ushort x = x1; x <= x2; x++)
|
||||||
@ -42,20 +43,19 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
||||||
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
||||||
|
|
||||||
for (int i = 0; i < toReplace.Length; i++) {
|
if (tile == Include.Type && (tile != Block.custom_block || extTile == Include.ExtType))
|
||||||
ExtBlock block = toReplace[i];
|
PlaceBlock(p, lvl, x, y, z, brush);
|
||||||
if (tile == block.Type && (tile != Block.custom_block || extTile == block.ExtType)) {
|
|
||||||
PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReplaceNotDrawOp : DrawOp {
|
public class ReplaceNotDrawOp : DrawOp {
|
||||||
|
|
||||||
public ExtBlock[] ToReplace;
|
public ExtBlock Exclude;
|
||||||
public ExtBlock Target;
|
|
||||||
|
public ReplaceNotDrawOp(byte type, byte extType) {
|
||||||
|
Exclude = new ExtBlock(type, extType);
|
||||||
|
}
|
||||||
|
|
||||||
public override string Name { get { return "ReplaceNot"; } }
|
public override string Name { get { return "ReplaceNot"; } }
|
||||||
|
|
||||||
@ -65,8 +65,6 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
|
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
|
||||||
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
|
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
|
||||||
ExtBlock[] toReplace = ToReplace;
|
|
||||||
ExtBlock target = Target;
|
|
||||||
for (ushort y = y1; y <= y2; y++)
|
for (ushort y = y1; y <= y2; y++)
|
||||||
for (ushort z = z1; z <= z2; z++)
|
for (ushort z = z1; z <= z2; z++)
|
||||||
for (ushort x = x1; x <= x2; x++)
|
for (ushort x = x1; x <= x2; x++)
|
||||||
@ -74,16 +72,10 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
byte tile = lvl.GetTile(x, y, z), extTile = 0;
|
||||||
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
if (tile == Block.custom_block) extTile = lvl.GetExtTile(x, y, z);
|
||||||
|
|
||||||
bool place = true;
|
if (tile != Exclude.Type || (tile == Block.custom_block && extTile != Exclude.ExtType)) {
|
||||||
for (int i = 0; i < toReplace.Length; i++) {
|
PlaceBlock(p, lvl, x, y, z, brush);
|
||||||
ExtBlock block = toReplace[i];
|
|
||||||
if (tile == block.Type || (tile == Block.custom_block && extTile == block.ExtType)) {
|
|
||||||
place = false; break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (place)
|
|
||||||
PlaceBlock(p, lvl, x, y, z, target.Type, target.ExtType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -273,8 +273,7 @@ namespace MCGalaxy {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.group.Permission > perbuildmax && (!inZone || !AllowBuild) &&
|
if (p.group.Permission > perbuildmax && (!inZone || !AllowBuild) && !p.group.CanExecute("perbuildmax")) {
|
||||||
!p.group.CanExecute(Command.all.Find("perbuildmax"))) {
|
|
||||||
if (p.ZoneSpam.AddSeconds(2) <= DateTime.UtcNow) {
|
if (p.ZoneSpam.AddSeconds(2) <= DateTime.UtcNow) {
|
||||||
Player.SendMessage(p, "Your rank must be " + perbuildmax + " or lower to build here!");
|
Player.SendMessage(p, "Your rank must be " + perbuildmax + " or lower to build here!");
|
||||||
p.ZoneSpam = DateTime.UtcNow;
|
p.ZoneSpam = DateTime.UtcNow;
|
||||||
|
@ -127,6 +127,7 @@
|
|||||||
<Compile Include="Commands\Building\CmdPortal.cs" />
|
<Compile Include="Commands\Building\CmdPortal.cs" />
|
||||||
<Compile Include="Commands\Building\CmdPyramid.cs" />
|
<Compile Include="Commands\Building\CmdPyramid.cs" />
|
||||||
<Compile Include="Commands\Building\CmdRedo.cs" />
|
<Compile Include="Commands\Building\CmdRedo.cs" />
|
||||||
|
<Compile Include="Commands\building\CmdReplaceBrush.cs" />
|
||||||
<Compile Include="Commands\building\ReplaceCmd.cs" />
|
<Compile Include="Commands\building\ReplaceCmd.cs" />
|
||||||
<Compile Include="Commands\Building\CmdRestartPhysics.cs" />
|
<Compile Include="Commands\Building\CmdRestartPhysics.cs" />
|
||||||
<Compile Include="Commands\Building\CmdSpheroid.cs" />
|
<Compile Include="Commands\Building\CmdSpheroid.cs" />
|
||||||
|
@ -99,9 +99,12 @@ namespace MCGalaxy
|
|||||||
GrpCommands.AddCommands(out _commands, Permission);
|
GrpCommands.AddCommands(out _commands, Permission);
|
||||||
commands = _commands;
|
commands = _commands;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Check to see if this group can excute cmd
|
public bool CanExecute(string cmdName) {
|
||||||
/// </summary>
|
return commands.Contains(Command.all.Find(cmdName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check to see if this group can excute cmd </summary>
|
||||||
/// <param name="cmd">The command object to check</param>
|
/// <param name="cmd">The command object to check</param>
|
||||||
/// <returns>True if this group can use it, false if they cant</returns>
|
/// <returns>True if this group can use it, false if they cant</returns>
|
||||||
public bool CanExecute(Command cmd) { return commands.Contains(cmd); }
|
public bool CanExecute(Command cmd) { return commands.Contains(cmd); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user