Skip to content

Commit

Permalink
Allow info/remove/edit ing multiple blocks using lb/gb
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Feb 19, 2020
1 parent 1d7006e commit 3e60ac1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 26 deletions.
82 changes: 57 additions & 25 deletions MCGalaxy/Commands/CPE/CustomBlockCommand.cs
Expand Up @@ -196,13 +196,9 @@ internal static class CustomBlockCommand {

AddBlock(p, dstDef, global, cmd, props);
return true;
}
}

static void InfoHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length == 1) { Help(p, cmd); return; }
BlockID block;
if (!CheckBlock(p, parts[1], out block)) return;

static void DoInfo(Player p, BlockID block, bool global, string cmd) {
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block];
if (def == null) { MessageNoBlock(p, block, global, cmd); return; }
Expand Down Expand Up @@ -244,6 +240,16 @@ internal static class CustomBlockCommand {
}
}

static void InfoHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length == 1) { Help(p, cmd); return; }
BlockID min, max;
if (!CheckBlocks(p, parts[1], out min, out max)) return;

for (int i = min; i <= max; i++) {
DoInfo(p, (BlockID)i, global, cmd);
}
}

static void ListHandler(Player p, string[] parts, bool global, string cmd) {
string modifier = parts.Length > 1 ? parts[1] : "";
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
Expand All @@ -265,11 +271,7 @@ internal static class CustomBlockCommand {
return "Custom block %T" + def.RawID + " %Shas name %T" + def.Name;
}

static void RemoveHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length <= 1) { Help(p, cmd); return; }
BlockID block;
if (!CheckBlock(p, parts[1], out block)) return;

static void DoRemove(Player p, BlockID block, bool global, string cmd) {
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block];
if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; }
Expand All @@ -285,6 +287,16 @@ internal static class CustomBlockCommand {
BlockDefinition.Add(globalDef, defs, p.level);
}

static void RemoveHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length <= 1) { Help(p, cmd); return; }
BlockID min, max;
if (!CheckBlocks(p, parts[1], out min, out max)) return;

for (int i = min; i <= max; i++) {
DoRemove(p, (BlockID)i, global, cmd);
}
}

static void DefineBlockStep(Player p, string value, bool global, string cmd) {
string opt = value.ToLower();
int step = GetStep(p, global);
Expand Down Expand Up @@ -376,20 +388,7 @@ internal static class CustomBlockCommand {
SendStepHelp(p, global);
}

static void EditHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length <= 3) {
if (parts.Length == 1) {
p.Message("Valid properties: " + helpSections.Keys.Join());
} else if (parts.Length == 3) {
Help(p, cmd, "edit " + parts[2]);
} else {
Help(p, cmd);
}
return;
}

BlockID block;
if (!CheckBlock(p, parts[1], out block)) return;
static void DoEdit(Player p, BlockID block, string[] parts, bool global, string cmd) {
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block], globalDef = BlockDefinition.GlobalDefs[block];

Expand Down Expand Up @@ -527,6 +526,26 @@ internal static class CustomBlockCommand {
}
}

static void EditHandler(Player p, string[] parts, bool global, string cmd) {
if (parts.Length <= 3) {
if (parts.Length == 1) {
p.Message("Valid properties: " + helpSections.Keys.Join());
} else if (parts.Length == 3) {
Help(p, cmd, "edit " + parts[2]);
} else {
Help(p, cmd);
}
return;
}

BlockID min, max;
if (!CheckBlocks(p, parts[1], out min, out max)) return;

for (int i = min; i <= max; i++) {
DoEdit(p, (BlockID)i, parts, global, cmd);
}
}


static bool AddBlock(Player p, BlockDefinition def, bool global, string cmd, BlockProps props) {
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
Expand Down Expand Up @@ -640,6 +659,19 @@ internal static class CustomBlockCommand {
block = Block.FromRaw(raw);
return success;
}

static bool CheckBlocks(Player p, string arg, out BlockID min, out BlockID max) {
bool success;
// Either "[id]" or "[min]-[max]"
if (arg.IndexOf('-') == -1) {
success = CheckBlock(p, arg, out min);
max = min;
} else {
string[] bits = arg.Split(new char[] { '-' }, 2);
success = CheckBlock(p, bits[0], out min) & CheckBlock(p, bits[1], out max);
}
return success;
}

static void ResetProps(bool global, BlockID block, Player p) {
BlockProps[] scope = global ? Block.Props : p.level.Props;
Expand Down
1 change: 0 additions & 1 deletion MCGalaxy/Player/PlayerInfo.cs
Expand Up @@ -47,7 +47,6 @@ public static class PlayerInfo {

public static int NonHiddenUniqueIPCount() {
Player[] players = Online.Items;
List<string> IPs = new List<string>();
Dictionary<string, bool> uniqueIPs = new Dictionary<string, bool>();
foreach (Player p in players) {
if (!p.hidden) {
Expand Down

0 comments on commit 3e60ac1

Please sign in to comment.