From 861feef37853e85b115286ca4e850d0c106a7da7 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 25 Dec 2023 19:50:42 +1100 Subject: [PATCH] Simplify messaging for /blockset after recent changes, simplify help for /cmdset and /blockset --- MCGalaxy/Commands/Moderation/CmdBlockSet.cs | 50 +++++++++++++------ MCGalaxy/Commands/Moderation/CmdCmdSet.cs | 51 ++++++++++++-------- MCGalaxy/Commands/Moderation/ItemPermsCmd.cs | 20 ++++---- 3 files changed, 77 insertions(+), 44 deletions(-) diff --git a/MCGalaxy/Commands/Moderation/CmdBlockSet.cs b/MCGalaxy/Commands/Moderation/CmdBlockSet.cs index eeca56a4e..8d1fc1844 100644 --- a/MCGalaxy/Commands/Moderation/CmdBlockSet.cs +++ b/MCGalaxy/Commands/Moderation/CmdBlockSet.cs @@ -18,19 +18,22 @@ using MCGalaxy.Blocks; using BlockID = System.UInt16; -namespace MCGalaxy.Commands.Moderation { - public sealed class CmdBlockSet : ItemPermsCmd { +namespace MCGalaxy.Commands.Moderation +{ + public sealed class CmdBlockSet : ItemPermsCmd + { public override string name { get { return "BlockSet"; } } public override void Use(Player p, string message, CommandData data) { bool canPlace = true; const string PLACE_PREFIX = "place "; bool canDelete = true; const string DELETE_PREFIX = "delete "; + string placeMsg = null, deleteMsg = null; if (message.CaselessStarts(PLACE_PREFIX)) { canDelete = false; message = message.Substring(PLACE_PREFIX.Length); } else if (message.CaselessStarts(DELETE_PREFIX)) { - canPlace = true; + canPlace = false; message = message.Substring(DELETE_PREFIX.Length); } @@ -43,35 +46,54 @@ namespace MCGalaxy.Commands.Moderation { // TODO avoid showing message twice if (canPlace) { BlockPerms perms = BlockPerms.GetPlace(block); - SetPerms(p, args, data, perms, "block", "use", "usable"); + placeMsg = SetPerms(p, args, data, perms, "block", "use", "usable"); } if (canDelete) { BlockPerms perms = BlockPerms.GetDelete(block); - SetPerms(p, args, data, perms, "block", "delete", "deletable"); + deleteMsg = SetPerms(p, args, data, perms, "block", "delete", "deletable"); } + + if (placeMsg == null && deleteMsg == null) return; + UpdatePerms(block, p, placeMsg, deleteMsg); } - protected override void UpdatePerms(ItemPerms perms, Player p, string msg) { - BlockID block = ((BlockPerms)perms).ID; + void UpdatePerms(BlockID block, Player p, string placeMsg, string deleteMsg) { BlockPerms.Save(); BlockPerms.ApplyChanges(); if (!Block.IsPhysicsType(block)) { BlockPerms.ResendAllBlockPermissions(); - } - + } string name = Block.GetName(p, block); - Announce(p, name + msg); + + if (placeMsg != null && deleteMsg != null) { + Announce(p, name + placeMsg.Replace("usable", "usable and deletable")); + } else if (placeMsg != null) { + Announce(p, name + placeMsg); + } else { + Announce(p, name + deleteMsg); + } } public override void Help(Player p) { p.Message("&T/BlockSet [block] [rank]"); - p.Message("&HSets lowest rank that can modify/use [block] to [rank]"); + p.Message("&HSets lowest rank that can use and delete [block] to [rank]"); + p.Message("&T/BlockSet place [block] [rank]"); + p.Message("&HSets lowest rank that can use/modify [block] to [rank]"); + p.Message("&T/BlockSet delete [block] [rank]"); + p.Message("&HSets lowest rank that can delete [block] to [rank]"); + p.Message("&H- For more advanced permissions, see &T/Help blockset advanced"); + p.Message("&H- To see available ranks, type &T/ViewRanks"); + } + + public override void Help(Player p, string message) { + if (!message.CaselessEq("advanced")) { base.Help(p, message); return; } + p.Message("&T/BlockSet [block] +[rank]"); - p.Message("&HAllows a specific rank to modify/use [block]"); + p.Message("&HAllows a specific rank to use and delete [block]"); p.Message("&T/BlockSet [block] -[rank]"); - p.Message("&HPrevents a specific rank from modifying/using [block]"); - p.Message("&HTo see available ranks, type &T/ViewRanks"); + p.Message("&HPrevents a specific rank from using or deleting [block]"); + // TODO place and delete messages } } } diff --git a/MCGalaxy/Commands/Moderation/CmdCmdSet.cs b/MCGalaxy/Commands/Moderation/CmdCmdSet.cs index 22ed183d0..5b4996115 100644 --- a/MCGalaxy/Commands/Moderation/CmdCmdSet.cs +++ b/MCGalaxy/Commands/Moderation/CmdCmdSet.cs @@ -15,15 +15,17 @@ or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. */ -namespace MCGalaxy.Commands.Moderation { - public sealed class CmdCmdSet : ItemPermsCmd { +namespace MCGalaxy.Commands.Moderation +{ + public sealed class CmdCmdSet : ItemPermsCmd + { public override string name { get { return "CmdSet"; } } public override void Use(Player p, string message, CommandData data) { string[] args = message.SplitSpaces(3); if (args.Length < 2) { Help(p); return; } - string cmdName = args[0], cmdArgs = ""; + string cmdName = args[0], cmdArgs = "", msg; Command.Search(ref cmdName, ref cmdArgs); Command cmd = Command.Find(cmdName); @@ -35,8 +37,11 @@ namespace MCGalaxy.Commands.Moderation { } if (args.Length == 2) { - SetPerms(p, args, data, cmd.Permissions, "command", "use", "usable"); + msg = SetPerms(p, args, data, cmd.Permissions, "command", "use", "usable"); + if (msg != null) + UpdateCommandPerms(cmd.Permissions, p, msg); } else { + int num = 0; if (!CommandParser.GetInt(p, args[2], "Extra permission number", ref num)) return; @@ -44,33 +49,41 @@ namespace MCGalaxy.Commands.Moderation { if (perms == null) { p.Message("This command has no extra permission by that number."); return; } - SetPerms(p, args, data, perms, "extra permission", "use", "usable"); + + msg = SetPerms(p, args, data, perms, "extra permission", "use", "usable"); + if (msg != null) + UpdateExtraPerms(perms, p, msg); } } - protected override void UpdatePerms(ItemPerms perms, Player p, string msg) { - if (perms is CommandPerms) { - CommandPerms.Save(); - CommandPerms.ApplyChanges(); - Announce(p, perms.ItemName + msg); - } else { - CommandExtraPerms.Save(); - CommandExtraPerms ex = (CommandExtraPerms)perms; - //Announce(p, cmd.name + "&S's extra permission " + idx + " was set to " + grp.ColoredName); - Announce(p, ex.CmdName + " extra permission #" + ex.Num + msg); - } + void UpdateCommandPerms(ItemPerms perms, Player p, string msg) { + CommandPerms.Save(); + CommandPerms.ApplyChanges(); + Announce(p, perms.ItemName + msg); + } + + void UpdateExtraPerms(CommandExtraPerms perms, Player p, string msg) { + CommandExtraPerms.Save(); + //Announce(p, cmd.name + "&S's extra permission " + idx + " was set to " + grp.ColoredName); + Announce(p, perms.CmdName + " extra permission #" + perms.Num + msg); } public override void Help(Player p) { p.Message("&T/CmdSet [cmd] [rank]"); p.Message("&HSets lowest rank that can use [cmd] to [rank]"); + p.Message("&T/CmdSet [cmd] [rank] [extra permission number]"); + p.Message("&HSet the lowest rank that has that extra permission for [cmd]"); + p.Message("&H- For more advanced permissions, see &T/Help cmdset advanced"); + p.Message("&H- To see available ranks, type &T/ViewRanks"); + } + + public override void Help(Player p, string message) { + if (!message.CaselessEq("advanced")) { base.Help(p, message); return; } + p.Message("&T/CmdSet [cmd] +[rank]"); p.Message("&HAllows a specific rank to use [cmd]"); p.Message("&T/CmdSet [cmd] -[rank]"); p.Message("&HPrevents a specific rank from using [cmd]"); - p.Message("&T/CmdSet [cmd] [rank] [extra permission number]"); - p.Message("&HSet the lowest rank that has that extra permission for [cmd]"); - p.Message("&HTo see available ranks, type &T/ViewRanks"); } } } diff --git a/MCGalaxy/Commands/Moderation/ItemPermsCmd.cs b/MCGalaxy/Commands/Moderation/ItemPermsCmd.cs index 6683df49f..5abc29409 100644 --- a/MCGalaxy/Commands/Moderation/ItemPermsCmd.cs +++ b/MCGalaxy/Commands/Moderation/ItemPermsCmd.cs @@ -24,40 +24,38 @@ namespace MCGalaxy.Commands.Moderation public override string type { get { return CommandTypes.Moderation; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - protected void SetPerms(Player p, string[] args, CommandData data, ItemPerms perms, string type, + protected string SetPerms(Player p, string[] args, CommandData data, ItemPerms perms, string type, string actionNoun, string actionAdjective) { string grpName = args[1]; if (!perms.UsableBy(data.Rank)) { - p.Message("You rank cannot {1} this {0}.", type, actionNoun); return; + p.Message("You rank cannot {1} this {0}.", type, actionNoun); return null; } if (grpName[0] == '+') { Group grp = GetGroup(p, data, grpName.Substring(1)); - if (grp == null) return; + if (grp == null) return null; perms.Allow(grp.Permission); - UpdatePerms(perms, p, " &Sis now " + actionAdjective + " by " + grp.ColoredName); + return " &Sis now " + actionAdjective + " by " + grp.ColoredName; } else if (grpName[0] == '-') { Group grp = GetGroup(p, data, grpName.Substring(1)); - if (grp == null) return; + if (grp == null) return null; if (data.Rank == grp.Permission) { - p.Message("&WCannot deny permissions for your own rank"); return; + p.Message("&WCannot deny permissions for your own rank"); return null; } perms.Disallow(grp.Permission); - UpdatePerms(perms, p, " &Sis no longer " + actionAdjective + " by " + grp.ColoredName); + return " &Sis no longer " + actionAdjective + " by " + grp.ColoredName; } else { Group grp = GetGroup(p, data, grpName); - if (grp == null) return; + if (grp == null) return null; perms.MinRank = grp.Permission; - UpdatePerms(perms, p, " &Sis now " + actionAdjective + " by " + grp.ColoredName + "&S+"); + return " &Sis now " + actionAdjective + " by " + grp.ColoredName + "&S+"; } } - protected abstract void UpdatePerms(ItemPerms perms, Player p, string msg); - protected static Group GetGroup(Player p, CommandData data, string grpName) { Group grp = Matcher.FindRanks(p, grpName); if (grp == null) return null;