From 7e098ad8f8f793934307d425f9e702fc0f04e491 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 28 Jan 2018 11:47:46 +1100 Subject: [PATCH] Separate up /zone command a bit. --- .../Moderation/{CmdZone.cs => ZoneCmds.cs} | 113 ++++++++++-------- .../{PermissionCmd.cs => PermissionCmds.cs} | 0 MCGalaxy/MCGalaxy_.csproj | 4 +- 3 files changed, 68 insertions(+), 49 deletions(-) rename MCGalaxy/Commands/Moderation/{CmdZone.cs => ZoneCmds.cs} (69%) rename MCGalaxy/Commands/World/{PermissionCmd.cs => PermissionCmds.cs} (100%) diff --git a/MCGalaxy/Commands/Moderation/CmdZone.cs b/MCGalaxy/Commands/Moderation/ZoneCmds.cs similarity index 69% rename from MCGalaxy/Commands/Moderation/CmdZone.cs rename to MCGalaxy/Commands/Moderation/ZoneCmds.cs index e816f0c90..1ae91c120 100644 --- a/MCGalaxy/Commands/Moderation/CmdZone.cs +++ b/MCGalaxy/Commands/Moderation/ZoneCmds.cs @@ -25,72 +25,37 @@ namespace MCGalaxy.Commands.Moderation { public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - public override CommandPerm[] ExtraPerms { - get { return new[] { - new CommandPerm(LevelPermission.Operator, "+ can delete zones"), - new CommandPerm(LevelPermission.Operator, "+ can delete all zones"), - new CommandPerm(LevelPermission.Operator, "+ can create zones"), - }; } - } public override void Use(Player p, string message) { string[] args = message.SplitSpaces(); - if (message.Length == 0) { - Player.Message(p, "Place a block where you would like to check for zones."); - p.MakeSelection(1, null, CheckZone); - } else if (args[0].CaselessEq("add")) { + if (message.Length == 0) { Help(p); return; } + + if (args[0].CaselessEq("add")) { + if (args.Length == 1) { Help(p); return; } if (!CheckAdd(p, args, "Zone add")) return; Player.Message(p, "Place or break two blocks to determine the edges."); Player.Message(p, "Zone for: &b" + args[1] + "."); p.MakeSelection(2, args[1], AddZone); } else if (args[0].CaselessEq("del")) { - if (!CheckExtraPerm(p, 1)) return; - Player.Message(p, "Place a block where you would like to delete a zone."); p.MakeSelection(1, null, DeleteZone); - } else if (args[0].CaselessEq("list")) { - string modifier = args.Length > 1 ? args[1] : ""; - MultiPageOutput.Output(p, p.level.Zones, FormatZone, "Zone list", "zones", modifier, true); } else { - Help(p); + if (!CheckAdd(p, args, "Zone add")) return; // TODO: broken + + Player.Message(p, "Place or break two blocks to determine the edges."); + Player.Message(p, "Zone for: &b" + args[0] + "."); + p.MakeSelection(2, args[0], AddZone); } } - static string FormatZone(Zone zone) { - return zone.ColoredName - + " &b- (" + zone.MinX + ", " + zone.MinY + ", " + zone.MinZ - + ") to (" + zone.MaxX + ", " + zone.MaxY + ", " + zone.MaxZ + ")"; - } - bool CheckAdd(Player p, string[] args, string cmd) { - if (!CheckExtraPerm(p, 3)) return false; - if (args.Length == 1) { Help(p); return false; } if (!Formatter.ValidName(p, args[1], "player or rank")) return false; string reason = args.Length > 2 ? args[2] : ""; args[1] = FindZoneOwner(p, cmd, args[1], ref reason); return args[1] != null; } - - bool CheckZone(Player p, Vec3S32[] marks, object state, ExtBlock block) { - Vec3S32 P = marks[0]; - Level lvl = p.level; - bool found = false; - - for (int i = 0; i < lvl.Zones.Count; i++) { - Zone z = lvl.Zones[i]; - if (!z.Contains(P.X, P.Y, P.Z)) continue; - found = true; - - AccessResult status = z.Acess.Check(p); - bool allowed = status == AccessResult.Allowed || status == AccessResult.Whitelisted; - Player.Message(p, " Zone {0} %S- {1}{2}", z.ColoredName, allowed ? "&a" : "&c", status ); - } - - if (!found) { Player.Message(p, "No zones affect this block."); } - return true; - } bool DeleteZone(Player p, Vec3S32[] marks, object state, ExtBlock block) { Level lvl = p.level; @@ -101,7 +66,7 @@ namespace MCGalaxy.Commands.Moderation { Zone zn = lvl.Zones[i]; if (P.X < zn.MinX || P.X > zn.MaxX || P.Y < zn.MinY || P.Y > zn.MaxY || P.Z < zn.MinZ || P.Z > zn.MaxZ) continue; - if (!zn.Acess.CheckDetailed(p)) { + if (!zn.Acess.CheckDetailed(p)) { Player.Message(p, "Hence, you cannot delete this zone."); continue; } @@ -141,9 +106,63 @@ namespace MCGalaxy.Commands.Moderation { public override void Help(Player p) { Player.Message(p, "%T/Zone add [name] %H- Creates a zone only [name] can build in"); Player.Message(p, "%T/Zone add [rank] %H- Creates a zone only [rank]+ can build in"); - Player.Message(p, "%T/Zone map [name/rank] %H- /zone add across the entire map"); Player.Message(p, "%T/Zone del %H- Deletes the zone clicked"); - Player.Message(p, "%T/Zone list %H- Lists zones in the map"); + } + } + + public sealed class CmdZoneTest : Command { + public override string name { get { return "ZoneTest"; } } + public override string shortcut { get { return "ZTest"; } } + public override string type { get { return CommandTypes.Moderation; } } + public override bool museumUsable { get { return false; } } + + public override void Use(Player p, string message) { + Player.Message(p, "Place or delete a block where you would like to check for zones."); + p.MakeSelection(1, null, TestZone); + } + + bool TestZone(Player p, Vec3S32[] marks, object state, ExtBlock block) { + Vec3S32 P = marks[0]; + Level lvl = p.level; + bool found = false; + + for (int i = 0; i < lvl.Zones.Count; i++) { + Zone z = lvl.Zones[i]; + if (!z.Contains(P.X, P.Y, P.Z)) continue; + found = true; + + AccessResult status = z.Acess.Check(p); + bool allowed = status == AccessResult.Allowed || status == AccessResult.Whitelisted; + Player.Message(p, " Zone {0} %S- {1}{2}", z.ColoredName, allowed ? "&a" : "&c", status ); + } + + if (!found) { Player.Message(p, "No zones affect this block."); } + return true; + } + + public override void Help(Player p) { + Player.Message(p, "%T/ZoneTest %H- Lists all zones affecting a block"); + } + } + + public sealed class CmdZoneList : Command { + public override string name { get { return "ZoneList"; } } + public override string shortcut { get { return "Zones"; } } + public override string type { get { return CommandTypes.Moderation; } } + public override bool museumUsable { get { return false; } } + + public override void Use(Player p, string message) { + MultiPageOutput.Output(p, p.level.Zones, FormatZone, "ZoneList", "zones", message, true); + } + + static string FormatZone(Zone zone) { + return zone.ColoredName + + " &b- (" + zone.MinX + ", " + zone.MinY + ", " + zone.MinZ + + ") to (" + zone.MaxX + ", " + zone.MaxY + ", " + zone.MaxZ + ")"; + } + + public override void Help(Player p) { + Player.Message(p, "%T/ZoneList %H- Lists all zones in current level"); } } } diff --git a/MCGalaxy/Commands/World/PermissionCmd.cs b/MCGalaxy/Commands/World/PermissionCmds.cs similarity index 100% rename from MCGalaxy/Commands/World/PermissionCmd.cs rename to MCGalaxy/Commands/World/PermissionCmds.cs diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 3ada399c4..7a38bedf7 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -329,7 +329,7 @@ - + @@ -381,7 +381,7 @@ - +