From 8c309a065695a52192be35cb90fe5b76cef11d5e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 6 Sep 2017 13:42:33 +1000 Subject: [PATCH] Any command can restrict from usage in MBs, fixes #490. --- MCGalaxy/Blocks/Extended/MessageBlock.cs | 3 ++- MCGalaxy/Commands/Command.cs | 5 ++++- MCGalaxy/Commands/Maintenance/CmdBlockDB.cs | 3 ++- MCGalaxy/Commands/Scripting/CmdCmdCreate.cs | 3 ++- MCGalaxy/Commands/Scripting/CmdCmdLoad.cs | 3 ++- MCGalaxy/Commands/Scripting/CmdCmdUnload.cs | 3 ++- MCGalaxy/Commands/Scripting/CmdCompile.cs | 3 ++- MCGalaxy/Commands/Scripting/CmdCompload.cs | 1 + MCGalaxy/Commands/Scripting/CmdScripting.cs | 1 + MCGalaxy/Commands/World/CmdCopyLVL.cs | 1 + MCGalaxy/Commands/World/CmdDeleteLvl.cs | 1 + MCGalaxy/Commands/World/CmdRenameLvl.cs | 3 ++- MCGalaxy/Commands/World/CmdResizeLvl.cs | 3 ++- MCGalaxy/Commands/World/CmdRestore.cs | 3 ++- MCGalaxy/Commands/building/CmdCmdBind.cs | 5 +++-- 15 files changed, 29 insertions(+), 12 deletions(-) diff --git a/MCGalaxy/Blocks/Extended/MessageBlock.cs b/MCGalaxy/Blocks/Extended/MessageBlock.cs index a1851b237..40a2beabc 100644 --- a/MCGalaxy/Blocks/Extended/MessageBlock.cs +++ b/MCGalaxy/Blocks/Extended/MessageBlock.cs @@ -75,7 +75,8 @@ namespace MCGalaxy.Blocks.Extended { Command.Search(ref alias, ref cmdArgs); foreach (Command cmd in Command.all.commands) { - if (p.group.CanExecute(cmd) && (allCmds || !cmd.type.Contains("mod"))) continue; + bool mbUseable = !cmd.MessageBlockRestricted && !cmd.type.Contains("mod"); + if (p.group.CanExecute(cmd) && (allCmds || mbUseable)) continue; if (IsCommand(message, cmd.name) || IsCommand(alias, cmd.name)) { Player.Message(p, "You cannot use %T/{0} %Sin a messageblock.", cmd.name); return false; diff --git a/MCGalaxy/Commands/Command.cs b/MCGalaxy/Commands/Command.cs index e36e58b62..79cbe9cfa 100644 --- a/MCGalaxy/Commands/Command.cs +++ b/MCGalaxy/Commands/Command.cs @@ -47,7 +47,10 @@ namespace MCGalaxy { /// Aliases for this command. public virtual CommandAlias[] Aliases { get { return null; } } /// Whether this command can be used by 'super' players. (Console and IRC controllers). - public virtual bool SuperUseable { get { return true; } } + public virtual bool SuperUseable { get { return true; } } + /// Whether this command is restricted in usage in message blocks. + /// Restricted commands require the player to have the extra permission for /mb to be able to be placed in message blocks. + public virtual bool MessageBlockRestricted { get { return false; } } public static CommandList all = new CommandList(); public static CommandList core = new CommandList(); diff --git a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs index af8d1b771..1902d3835 100644 --- a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs +++ b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs @@ -27,7 +27,8 @@ namespace MCGalaxy.Commands.Maintenance { get { return new [] { new CommandAlias("ClearBlockChanges", "clear"), new CommandAlias("cbc", "clear") }; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { string[] args = message.SplitSpaces(); if (args.Length == 1 && Player.IsSuper(p)) { SuperRequiresArgs(p, "map name"); return; } diff --git a/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs b/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs index c4dc9e661..466999bdd 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdCreate.cs @@ -25,7 +25,8 @@ namespace MCGalaxy.Commands.Scripting { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); diff --git a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs index a48097c49..a05828f5a 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdLoad.cs @@ -24,7 +24,8 @@ namespace MCGalaxy.Commands.Scripting { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (!Formatter.ValidName(p, message, "command")) return; if (Command.all.Contains(message)) { diff --git a/MCGalaxy/Commands/Scripting/CmdCmdUnload.cs b/MCGalaxy/Commands/Scripting/CmdCmdUnload.cs index 1943069be..708e26829 100644 --- a/MCGalaxy/Commands/Scripting/CmdCmdUnload.cs +++ b/MCGalaxy/Commands/Scripting/CmdCmdUnload.cs @@ -21,7 +21,8 @@ namespace MCGalaxy.Commands.Scripting { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } string cmdName = message.SplitSpaces()[0]; diff --git a/MCGalaxy/Commands/Scripting/CmdCompile.cs b/MCGalaxy/Commands/Scripting/CmdCompile.cs index 41fc022e7..d2f303ac5 100644 --- a/MCGalaxy/Commands/Scripting/CmdCompile.cs +++ b/MCGalaxy/Commands/Scripting/CmdCompile.cs @@ -25,7 +25,8 @@ namespace MCGalaxy.Commands.Scripting { public override string type { get { return CommandTypes.Other; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); diff --git a/MCGalaxy/Commands/Scripting/CmdCompload.cs b/MCGalaxy/Commands/Scripting/CmdCompload.cs index 31b4840d7..d4f2bec1a 100644 --- a/MCGalaxy/Commands/Scripting/CmdCompload.cs +++ b/MCGalaxy/Commands/Scripting/CmdCompload.cs @@ -22,6 +22,7 @@ namespace MCGalaxy.Commands.Scripting { public override string type { get { return CommandTypes.Other; } } public override LevelPermission defaultRank { get { return LevelPermission.Nobody; } } public override bool museumUsable { get { return true; } } + public override bool MessageBlockRestricted { get { return true; } } public override void Use(Player p, string message) { string[] args = message.SplitSpaces(); diff --git a/MCGalaxy/Commands/Scripting/CmdScripting.cs b/MCGalaxy/Commands/Scripting/CmdScripting.cs index 86ede3a9a..5340a1a18 100644 --- a/MCGalaxy/Commands/Scripting/CmdScripting.cs +++ b/MCGalaxy/Commands/Scripting/CmdScripting.cs @@ -28,6 +28,7 @@ namespace MCGalaxy.Commands.Scripting { get { return new[] { new CommandAlias("PCreate", "pcreate"), new CommandAlias("PLoad", "pload"), new CommandAlias("PUnload", "punload") }; } } + public override bool MessageBlockRestricted { get { return true; } } public override void Use(Player p, string message) { string[] parts = message.SplitSpaces(2); diff --git a/MCGalaxy/Commands/World/CmdCopyLVL.cs b/MCGalaxy/Commands/World/CmdCopyLVL.cs index 019579eff..822b1156b 100644 --- a/MCGalaxy/Commands/World/CmdCopyLVL.cs +++ b/MCGalaxy/Commands/World/CmdCopyLVL.cs @@ -29,6 +29,7 @@ namespace MCGalaxy.Commands.World { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("WCopy"), new CommandAlias("WorldCopy") }; } } + public override bool MessageBlockRestricted { get { return true; } } public override void Use(Player p, string message) { if (message.Length == 0) { Help(p); return; } diff --git a/MCGalaxy/Commands/World/CmdDeleteLvl.cs b/MCGalaxy/Commands/World/CmdDeleteLvl.cs index 460e5038a..145e589ee 100644 --- a/MCGalaxy/Commands/World/CmdDeleteLvl.cs +++ b/MCGalaxy/Commands/World/CmdDeleteLvl.cs @@ -28,6 +28,7 @@ namespace MCGalaxy.Commands.World { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("WDelete"), new CommandAlias("WorldDelete"), new CommandAlias("WRemove") }; } } + public override bool MessageBlockRestricted { get { return true; } } public override void Use(Player p, string message) { if (message.Length == 0 || message.SplitSpaces().Length > 1) { Help(p); return; } diff --git a/MCGalaxy/Commands/World/CmdRenameLvl.cs b/MCGalaxy/Commands/World/CmdRenameLvl.cs index c8206a33c..323e8fc09 100644 --- a/MCGalaxy/Commands/World/CmdRenameLvl.cs +++ b/MCGalaxy/Commands/World/CmdRenameLvl.cs @@ -27,7 +27,8 @@ namespace MCGalaxy.Commands.World { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("WRename"), new CommandAlias("WorldRename") }; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { string[] args = message.SplitSpaces(); if (args.Length != 2) { Help(p); return; } diff --git a/MCGalaxy/Commands/World/CmdResizeLvl.cs b/MCGalaxy/Commands/World/CmdResizeLvl.cs index 07590b204..77b734105 100644 --- a/MCGalaxy/Commands/World/CmdResizeLvl.cs +++ b/MCGalaxy/Commands/World/CmdResizeLvl.cs @@ -28,7 +28,8 @@ namespace MCGalaxy.Commands.World { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("WResize"), new CommandAlias("WorldResize") }; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { string[] args = message.SplitSpaces(); if (args.Length < 4) { Help(p); return; } diff --git a/MCGalaxy/Commands/World/CmdRestore.cs b/MCGalaxy/Commands/World/CmdRestore.cs index 695dd8d7a..54db5cc02 100644 --- a/MCGalaxy/Commands/World/CmdRestore.cs +++ b/MCGalaxy/Commands/World/CmdRestore.cs @@ -25,7 +25,8 @@ namespace MCGalaxy.Commands.World { public override string type { get { return CommandTypes.World; } } public override bool museumUsable { get { return false; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (message.Length == 0) { OutputBackups(p); return; } diff --git a/MCGalaxy/Commands/building/CmdCmdBind.cs b/MCGalaxy/Commands/building/CmdCmdBind.cs index 642b6089b..7cb240f71 100644 --- a/MCGalaxy/Commands/building/CmdCmdBind.cs +++ b/MCGalaxy/Commands/building/CmdCmdBind.cs @@ -21,11 +21,12 @@ namespace MCGalaxy.Commands.Building { public sealed class CmdCmdBind : Command { public override string name { get { return "CmdBind"; } } public override string shortcut { get { return "cb"; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Building; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Builder; } } public override bool SuperUseable { get { return false; } } - + public override bool MessageBlockRestricted { get { return true; } } + public override void Use(Player p, string message) { if (message.Length == 0) { bool anyBinds = false;