From 2349a81f79e7146f681e189e380dbffd2e6ad473 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 3 Apr 2016 18:32:20 +1000 Subject: [PATCH] Simplify the checking for 'can use additional perm X' across all commands. --- Commands/Chat/CmdChatRoom.cs | 44 ++++++++---------------- Commands/Command.cs | 7 +++- Commands/Economy/CmdEconomy.cs | 6 ++-- Commands/Fun/CmdCountdown.cs | 8 ++--- Commands/Fun/CmdTntWars.cs | 12 +++---- Commands/Information/CmdFaq.cs | 3 +- Commands/Information/CmdNews.cs | 4 +-- Commands/Information/CmdRules.cs | 6 ++-- Commands/Information/CmdWhois.cs | 17 +++++---- Commands/Information/CmdWhowas.cs | 57 +++++++++++++++---------------- Commands/Moderation/CmdReveal.cs | 4 +-- Commands/Moderation/CmdZone.cs | 12 +++---- Commands/World/CmdMap.cs | 5 +-- Commands/building/CmdUndo.cs | 13 ++----- Commands/other/CmdBotSet.cs | 4 +-- Commands/other/CmdChangeLog.cs | 11 ++---- Commands/other/CmdReport.cs | 18 +++------- Commands/other/CmdTnt.cs | 18 +++++----- Commands/other/CmdWarp.cs | 24 +++++-------- 19 files changed, 111 insertions(+), 162 deletions(-) diff --git a/Commands/Chat/CmdChatRoom.cs b/Commands/Chat/CmdChatRoom.cs index d0f5719cd..b734ca305 100644 --- a/Commands/Chat/CmdChatRoom.cs +++ b/Commands/Chat/CmdChatRoom.cs @@ -105,10 +105,7 @@ namespace MCGalaxy.Commands { } void HandleCreate(Player p, string[] parts) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) { - Player.SendMessage(p, "You aren't a high enough rank to create a chatroon."); - return; - } + if (!CheckAdditionalPerm(p, 1)) { MessageNeedPerms(p, "can create a chatroom.", 1); return; } if (parts.Length <= 1) { Player.SendMessage(p, "You need to provide a new chatroom name."); return; @@ -129,8 +126,8 @@ namespace MCGalaxy.Commands { return; } string room = parts[1]; - bool canDeleteForce = (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 3); - bool canDelete = (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2); + bool canDeleteForce = CheckAdditionalPerm(p, 3); + bool canDelete = CheckAdditionalPerm(p, 2); if (!canDelete && !canDeleteForce) { Player.SendMessage(p, "You aren't a high enough rank to delete a chatroon."); return; @@ -173,11 +170,7 @@ namespace MCGalaxy.Commands { } void HandleSpy(Player p, string[] parts) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 4)) { - Player.SendMessage(p, "You aren't a high enough rank to spy " + - "on a chatroon."); - return; - } + if (!CheckAdditionalPerm(p, 4)) { MessageNeedPerms(p, "can spy on a chatroom.", 4); return; } if (parts.Length <= 1) { Player.SendMessage(p, "You need to provide a chatroom name to spy on."); return; @@ -201,11 +194,7 @@ namespace MCGalaxy.Commands { } void HandleForceJoin(Player p, string[] parts) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 5)) { - Player.SendMessage(p, "You aren't a high enough rank to force " + - "players to join a chatroon."); - return; - } + if (!CheckAdditionalPerm(p, 5)) { MessageNeedPerms(p, "can force players to join a chatroom.", 5); return; } if (parts.Length <= 2) { Player.SendMessage(p, "You need to provide a player name, then a chatroom name."); return; @@ -235,10 +224,7 @@ namespace MCGalaxy.Commands { } void HandleKick(Player p, string[] parts) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 6)) { - Player.SendMessage(p, "You aren't a high enough rank to kick someone from a chatroon."); - return; - } + if (!CheckAdditionalPerm(p, 6)) { MessageNeedPerms(p, "can kick players from a chatroom.", 6); return; } if (parts.Length <= 1) { Player.SendMessage(p, "You need to provide a player name."); return; @@ -261,7 +247,7 @@ namespace MCGalaxy.Commands { void HandleAll(Player p, string[] parts, string message) { int length = parts.Length > 1 ? parts[0].Length + 1 : parts[0].Length; message = message.Substring( length ); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 7)) { + if (CheckAdditionalPerm(p, 7)) { Chat.GlobalChatRoom(p, message, true); return; } @@ -296,21 +282,21 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, "/chatroom join [room] - joins a room"); Player.SendMessage(p, "/chatroom leave [room] - leaves a room"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p, 1)) Player.SendMessage(p, "/chatroom create [room] - creates a new room"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 3)) + if (CheckAdditionalPerm(p, 3)) Player.SendMessage(p, "/chatroom delete [room] - deletes a room"); - else if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) - Player.SendMessage(p, "/chatroom delete [room] - deletes a room if all people have left"); + else if (CheckAdditionalPerm(p, 2)) + Player.SendMessage(p, "/chatroom delete [room] - deletes a room only if all people have left"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 4)) + if (CheckAdditionalPerm(p, 4)) Player.SendMessage(p, "/chatroom spy [room] - spy on a chatroom"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 5)) + if (CheckAdditionalPerm(p, 5)) Player.SendMessage(p, "/chatroom forcejoin [player] [room] - forces a player to join a room"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 6)) + if (CheckAdditionalPerm(p, 6)) Player.SendMessage(p, "/chatroom kick [player] - kicks the player from their current room"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 7)) + if (CheckAdditionalPerm(p, 7)) Player.SendMessage(p, "/chatroom all [message] - sends a global message to all rooms"); else Player.SendMessage(p, "/chatroom all [message] - sends a global message to all rooms " + diff --git a/Commands/Command.cs b/Commands/Command.cs index 87c0f6a2f..9f2c60334 100644 --- a/Commands/Command.cs +++ b/Commands/Command.cs @@ -58,7 +58,12 @@ namespace MCGalaxy Player.SendMessage(p, "/" + name + " can only be used in-game."); } - protected void MessageNeedPerms(Player p, int perm, string action) { + protected bool CheckAdditionalPerm(Player p, int num = 1) { + return p == null || (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, num); + } + + protected void MessageNeedPerms(Player p, string action, int num = 1) { + int perm = CommandOtherPerms.GetPerm(this, num) Group grp = Group.findPermInt(perm); if (grp == null) Player.SendMessage(p, "Onlys rank with a permission level greater than &a" + perm + "%Scan " + action); diff --git a/Commands/Economy/CmdEconomy.cs b/Commands/Economy/CmdEconomy.cs index 92c276def..4358f315e 100644 --- a/Commands/Economy/CmdEconomy.cs +++ b/Commands/Economy/CmdEconomy.cs @@ -42,9 +42,7 @@ namespace MCGalaxy.Commands { } void HandleSetup(Player p, string message, string[] args) { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "setup the economy."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can setup the economy."); return; } switch (args[0].ToLower()) { case "apply": @@ -84,7 +82,7 @@ namespace MCGalaxy.Commands { public override void Help(Player p) { Player.SendMessage(p, "%cMost commands have been removed from /economy, " + "use the appropriate command from %T/help economy %cinstead."); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this)) { + if (CheckAdditionalPerm(p)) { Player.SendMessage(p, "%f/eco %e- to setup economy"); Player.SendMessage(p, "%f/eco help %e- get more specific help for setting up the economy"); } diff --git a/Commands/Fun/CmdCountdown.cs b/Commands/Fun/CmdCountdown.cs index 29447ab08..be736e345 100644 --- a/Commands/Fun/CmdCountdown.cs +++ b/Commands/Fun/CmdCountdown.cs @@ -65,7 +65,7 @@ namespace MCGalaxy.Commands { break; } - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) { + if (CheckAdditionalPerm(p, 2)) { switch (cmd) { case "download": case "generate": @@ -176,7 +176,7 @@ namespace MCGalaxy.Commands { } void HandleRules(Player p, string target) { - bool hasPerm = (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1); + bool hasPerm = CheckAdditionalPerm(p, 1); if (target == "" || !hasPerm) { Player.SendMessage(p, "The aim of the game is to stay alive the longest."); Player.SendMessage(p, "Don't fall in the lava!!"); @@ -359,12 +359,12 @@ namespace MCGalaxy.Commands { p.SendMessage("/cd goto - goto the countdown map"); p.SendMessage("/cd players - view players currently playing"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p, 1)) p.SendMessage("/cd rules - the rules of countdown. with send: all to send to all, map to send to map and have a player's name to send to a player"); else p.SendMessage("/cd rules - view the rules of countdown"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) { + if (CheckAdditionalPerm(p, 2)) { p.SendMessage("/cd generate [width] [height] [length] - generates the countdown map (default size is 32x32x32)"); p.SendMessage("/cd enable - enable the game"); p.SendMessage("/cd disable - disable the game"); diff --git a/Commands/Fun/CmdTntWars.cs b/Commands/Fun/CmdTntWars.cs index de2a33ccf..751d75871 100644 --- a/Commands/Fun/CmdTntWars.cs +++ b/Commands/Fun/CmdTntWars.cs @@ -248,7 +248,7 @@ namespace MCGalaxy.Commands case "all": case "a": case "everyone": - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p)) { Player[] players = PlayerInfo.Online.Items; foreach (Player who in players) @@ -269,7 +269,7 @@ namespace MCGalaxy.Commands case "lvl": case "map": case "m": - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if ((CheckAdditionalPerm(p)) { foreach (Player who in p.level.players) { @@ -289,7 +289,7 @@ namespace MCGalaxy.Commands case "pls": case "pl": case "p": - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if CheckAdditionalPerm(p)) { TntWarsGame gm = TntWarsGame.GetTntWarsGame(p); if (gm == null) @@ -315,7 +315,7 @@ namespace MCGalaxy.Commands break; default: - if (text[1] != null && (int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (text[1] != null && CheckAdditionalPerm(p)) { Player who = PlayerInfo.FindOrShowMatches(p, text[1]); if (who != null) @@ -465,7 +465,7 @@ namespace MCGalaxy.Commands case "setup": case "s": - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p)) { bool justcreated = false; TntWarsGame it = TntWarsGame.FindFromGameNumber(p.CurrentTntGameNumber); @@ -1813,7 +1813,7 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "/tw scores - view the top score/team scores/your scores"); Player.SendMessage(p, "/tw players {p} - view the current players in your game"); Player.SendMessage(p, "/tw health {hp} - view your currrent amount of health left"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p)) { Player.SendMessage(p, "/tw rules > - send the rules to yourself, all, your map, all players in your game or to one person!"); Player.SendMessage(p, "/tw setup {s} - setup the game (do '/tntwars setup help' for more info!"); diff --git a/Commands/Information/CmdFaq.cs b/Commands/Information/CmdFaq.cs index 4f3678b16..167907c0d 100644 --- a/Commands/Information/CmdFaq.cs +++ b/Commands/Information/CmdFaq.cs @@ -38,8 +38,7 @@ namespace MCGalaxy.Commands { Player who = p; if (message != "") { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "Your rank cannot send the FAQ to other players."); return; } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can send the FAQ to a player."); return; } who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; } diff --git a/Commands/Information/CmdNews.cs b/Commands/Information/CmdNews.cs index 6a3904d32..493581d1a 100644 --- a/Commands/Information/CmdNews.cs +++ b/Commands/Information/CmdNews.cs @@ -46,9 +46,7 @@ namespace MCGalaxy.Commands string[] args = message.Split(' '); if (args[0] == "all") { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "to send the server news to all players."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can send the server news to all players."); return; } foreach (string line in lines) Player.GlobalMessage(line); return; diff --git a/Commands/Information/CmdRules.cs b/Commands/Information/CmdRules.cs index c4c96d96a..e8ea712b8 100644 --- a/Commands/Information/CmdRules.cs +++ b/Commands/Information/CmdRules.cs @@ -39,9 +39,7 @@ namespace MCGalaxy.Commands Player who = p; if (message != "") { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "You can't send /rules to another player."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can send the rules to a player."); return; } who = PlayerInfo.FindOrShowMatches(p, message); if (who == null) return; } @@ -62,7 +60,7 @@ namespace MCGalaxy.Commands } public override void Help(Player p) { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this)) { + if (CheckAdditionalPerm(p)) { Player.SendMessage(p, "/rules [player]- Displays server rules to a player."); Player.SendMessage(p, "If no [player] is given, the rules will be sent to you."); } else { diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index b379f7197..5e7713f53 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -26,7 +26,7 @@ namespace MCGalaxy.Commands public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "The lowest rank which can see the target player's ip and if they are whitelisted") }; } + get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "The lowest rank which can see the target player's ip and if they are whitelisted") }; } } public override void Use(Player p, string message) { @@ -60,14 +60,13 @@ namespace MCGalaxy.Commands if (who.isDev) Player.SendMessage(p, "> > Player is a &9Developer"); else if (who.isMod) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator"); - if (p == null || (int)p.group.Permission >= CommandOtherPerms.GetPerm(this)) { - string givenIP; - if (Server.bannedIP.Contains(who.ip)) givenIP = "&8" + who.ip + ", which is banned"; - else givenIP = who.ip; - Player.SendMessage(p, "> > the IP of " + givenIP); - if (Server.useWhitelist&& Server.whiteList.Contains(who.name)) - Player.SendMessage(p, "> > Player is &fWhitelisted"); - } + if (!CheckAdditionalPerm(p)) return; + string givenIP; + if (Server.bannedIP.Contains(who.ip)) givenIP = "&8" + who.ip + ", which is banned"; + else givenIP = who.ip; + Player.SendMessage(p, "> > the IP of " + givenIP); + if (Server.useWhitelist&& Server.whiteList.Contains(who.name)) + Player.SendMessage(p, "> > Player is &fWhitelisted"); } public override void Help(Player p) { diff --git a/Commands/Information/CmdWhowas.cs b/Commands/Information/CmdWhowas.cs index aa41904eb..e21a0fd05 100644 --- a/Commands/Information/CmdWhowas.cs +++ b/Commands/Information/CmdWhowas.cs @@ -1,20 +1,20 @@ /* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ using System; using System.Data; using MCGalaxy.SQL; @@ -28,8 +28,8 @@ namespace MCGalaxy.Commands public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } public override CommandPerm[] AdditionalPerms { - get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "The lowest rank which can see the target player's ip and if they are whitelisted") }; } - } + get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "The lowest rank which can see the target player's ip and if they are whitelisted") }; } + } public override void Use(Player p, string message) { if (message == "") { Help(p); return; } @@ -50,10 +50,10 @@ namespace MCGalaxy.Commands string color = target.color == "" ? group.color : target.color; string prefix = target.title == "" ? "" : "[" + target.titleColor + target.title + color + "] "; Player.SendMessage(p, color + prefix + target.name + " %Shas :"); - Player.SendMessage(p, "> > the rank of " + group.color + plGroup); + Player.SendMessage(p, "> > the rank of " + group.color + plGroup); if (Economy.Enabled) Player.SendMessage(p, "> > &a" + target.money + " %S" + Server.moneys); - + Player.SendMessage(p, "> > &cdied &a" + target.deaths + " %Stimes"); Player.SendMessage(p, "> > &bmodified &a" + target.blocks + " &eblocks."); Player.SendMessage(p, "> > was last seen on &a" + target.lastLogin); @@ -69,22 +69,21 @@ namespace MCGalaxy.Commands if (Server.Devs.ContainsInsensitive(message)) Player.SendMessage(p, "> > Player is a &9Developer"); else if (Server.Mods.ContainsInsensitive(message)) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator"); - if (p == null || (int)p.group.Permission >= CommandOtherPerms.GetPerm(this)) { - if (Server.bannedIP.Contains(target.ip)) - target.ip = "&8" + target.ip + ", which is banned"; - Player.SendMessage(p, "> > the IP of " + target.ip); - if (Server.useWhitelist&& Server.whiteList.Contains(message)) - Player.SendMessage(p, "> > Player is &fWhitelisted"); - } + if (!CheckAdditionalPerm(p)) return; + if (Server.bannedIP.Contains(target.ip)) + target.ip = "&8" + target.ip + ", which is banned"; + Player.SendMessage(p, "> > the IP of " + target.ip); + if (Server.useWhitelist&& Server.whiteList.Contains(message)) + Player.SendMessage(p, "> > Player is &fWhitelisted"); } string TotalTime(string time) { - TimeSpan value = time.ParseDBTime(); + TimeSpan value = time.ParseDBTime(); return "time spent on server: " + value.Days + " Days, " + value.Hours + " Hours, " + value.Minutes + " Minutes, " + value.Seconds + " Seconds."; } public override void Help(Player p) { Player.SendMessage(p, "/whowas - Displays information about someone who left."); - } + } } } diff --git a/Commands/Moderation/CmdReveal.cs b/Commands/Moderation/CmdReveal.cs index 3325c9e32..2115170dc 100644 --- a/Commands/Moderation/CmdReveal.cs +++ b/Commands/Moderation/CmdReveal.cs @@ -44,9 +44,7 @@ namespace MCGalaxy.Commands { if (parts[0] == "all") { if (lvl == null) { Player.SendMessage(p, "Level not found."); return; } - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "reload all players in a map."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can reload all players in a map."); return; } Player[] players = PlayerInfo.Online.Items; foreach (Player who in players) { diff --git a/Commands/Moderation/CmdZone.cs b/Commands/Moderation/CmdZone.cs index af4876d06..34b4e49d2 100644 --- a/Commands/Moderation/CmdZone.cs +++ b/Commands/Moderation/CmdZone.cs @@ -45,9 +45,9 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Place a block where you would like to check for zones."); return; } - else if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 1)) + else if (!CheckAdditionalPerm(p, 1)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 1), "to delete zones."); return; + MessageNeedPerms(p, "can delete zones.", 1); return; } if (message.IndexOf(' ') == -1) @@ -77,9 +77,9 @@ namespace MCGalaxy.Commands if (message.ToLower() == "del all") { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) + if (!CheckAdditionalPerm(p, 2)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 2), "to delete all zones."); return; + MessageNeedPerms(p, "can delete all zones.", 2); return; } else { @@ -100,9 +100,9 @@ namespace MCGalaxy.Commands } - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this, 3)) + if (!CheckAdditionalPerm(p, 3)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 3), "to create zones."); return; + MessageNeedPerms(p, "can create zones.", 3); return; } if (Group.Find(message.Split(' ')[1]) != null) diff --git a/Commands/World/CmdMap.cs b/Commands/World/CmdMap.cs index 37a87e8b4..eec7182f8 100644 --- a/Commands/World/CmdMap.cs +++ b/Commands/World/CmdMap.cs @@ -72,10 +72,7 @@ namespace MCGalaxy.Commands if (lvl == null || message.Split(' ')[0].ToLower() == "ps" || message.Split(' ')[0].ToLower() == "rp") lvl = p.level; else message = message.Substring(message.IndexOf(' ') + 1); } - - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 1), "to set map options."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can set map options."); return; } string foundStart; if (message.IndexOf(' ') == -1) foundStart = message.ToLower(); diff --git a/Commands/building/CmdUndo.cs b/Commands/building/CmdUndo.cs index dac1580fe..945d2ec81 100644 --- a/Commands/building/CmdUndo.cs +++ b/Commands/building/CmdUndo.cs @@ -89,9 +89,7 @@ namespace MCGalaxy.Commands if (who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot undo a user of higher or equal rank"); return; } - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "to undo other players."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can undo other players."); return; } } UndoOnlineDrawOp op = new UndoOnlineDrawOp(); @@ -110,10 +108,7 @@ namespace MCGalaxy.Commands } void UndoOfflinePlayer(Player p, long seconds, string whoName) { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "to undo other players."); return; - } - + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can undo other players."); return; } UndoOfflineDrawOp op = new UndoOfflineDrawOp(); op.Start = DateTime.UtcNow.AddTicks(-seconds * TimeSpan.TicksPerSecond); op.whoName = whoName; @@ -129,9 +124,7 @@ namespace MCGalaxy.Commands } void UndoLevelPhysics(Player p, long seconds) { - if (p != null && (int)p.group.Permission < CommandOtherPerms.GetPerm(this, 2)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 2), "to undo physics."); return; - } + if (!CheckAdditionalPerm(p, 2)) { MessageNeedPerms(p, "can undo physics.", 2); return; } if (p != null && !p.group.CanExecute("physics")) { Player.SendMessage(p, "You can only undo physics if you can use /physics."); return; } diff --git a/Commands/other/CmdBotSet.cs b/Commands/other/CmdBotSet.cs index 23b84d9d1..0f18ba954 100644 --- a/Commands/other/CmdBotSet.cs +++ b/Commands/other/CmdBotSet.cs @@ -69,9 +69,7 @@ namespace MCGalaxy.Commands } else if (foundPath == "kill") { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "to toggle bot killer instinct."); return; - } + if (CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can toggle a bot's killer instinct."); return; } Pb.kill = !Pb.kill; if (p != null) Chat.GlobalChatLevel(p, Pb.color + Pb.name + Server.DefaultColor + "'s kill instinct: " + Pb.kill, false); Server.s.Log(Pb.name + "'s kill instinct: " + Pb.kill); diff --git a/Commands/other/CmdChangeLog.cs b/Commands/other/CmdChangeLog.cs index c18220f17..f4a362cdd 100644 --- a/Commands/other/CmdChangeLog.cs +++ b/Commands/other/CmdChangeLog.cs @@ -61,15 +61,11 @@ namespace MCGalaxy.Commands if (split[0] == "all") { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) - { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this), "to send the changelog to all players."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can send the changelog to all players."); return; } for (int k = 0; k < strArray.Length; k++) { Player.GlobalMessage(strArray[k]); - } - + } return; } else @@ -84,8 +80,7 @@ namespace MCGalaxy.Commands Player.SendMessage(player, strArray[l]); } - Player.SendMessage(p, "The Changelog was successfully sent to " + player.name + "."); - + Player.SendMessage(p, "The Changelog was successfully sent to " + player.name + "."); return; } } diff --git a/Commands/other/CmdReport.cs b/Commands/other/CmdReport.cs index 089b51a0b..30f94dac4 100644 --- a/Commands/other/CmdReport.cs +++ b/Commands/other/CmdReport.cs @@ -57,9 +57,7 @@ namespace MCGalaxy.Commands { } void HandleList(Player p, string[] args) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "%cYour rank cannot see the list of reports."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can see the list of reports."); return; } bool foundone = false; FileInfo[] fi = new DirectoryInfo("extra/reported").GetFiles("*.txt"); @@ -82,9 +80,7 @@ namespace MCGalaxy.Commands { if (args.Length != 2) { Player.SendMessage(p, "You need to provide a player's name."); return; } - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "%cYour rank cannot view the details of a report."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can view the details of a report."); return; } if (!Player.ValidName(args[1])) { Player.SendMessage(p, "\"" + args[1] + "\" is not a valid player name."); return; } @@ -100,9 +96,7 @@ namespace MCGalaxy.Commands { if (args.Length != 2) { Player.SendMessage(p, "You need to provide a player's name."); return; } - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "%cYour rank cannot delete a report."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can delete reports."); return; } if (!Player.ValidName(args[1])) { Player.SendMessage(p, "\"" + args[1] + "\" is not a valid player name."); return; } @@ -122,9 +116,7 @@ namespace MCGalaxy.Commands { } void HandleClear(Player p, string[] args) { - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) { - Player.SendMessage(p, "%cYour rank cannot clear the reports list."); return; - } + if (!CheckAdditionalPerm(p)) { MessageNeedPerms(p, "can clear the list of reports."); return; } FileInfo[] fi = new DirectoryInfo("extra/reported").GetFiles("*.txt"); foreach (FileInfo file in fi) { @@ -160,7 +152,7 @@ namespace MCGalaxy.Commands { public override void Help(Player p) { Player.SendMessage(p, "%T/report [Player] [Reason] %H- Reports that player for the given reason."); - if ((int)p.group.Permission < CommandOtherPerms.GetPerm(this)) return; + if (!CheckAdditionalPerm(p)) return; Player.SendMessage(p, "%T/report list %H- Outputs the list of reported players."); Player.SendMessage(p, "%T/report check [Player] %H- View the report for the given player."); Player.SendMessage(p, "%T/report delete [Player] %H- Deletes the report for the given player."); diff --git a/Commands/other/CmdTnt.cs b/Commands/other/CmdTnt.cs index 31fb3c846..47629c271 100644 --- a/Commands/other/CmdTnt.cs +++ b/Commands/other/CmdTnt.cs @@ -52,35 +52,35 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "Tnt usage is not allowed at the moment!"); return; } - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) { + if (CheckAdditionalPerm(p, 1)) { p.modeType = Block.bigtnt; Player.SendMessage(p, "TNT (Big) mode is now &aON%S."); } else { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 1), "to use big TNT mode."); return; + MessageNeedPerms(p, "can use big TNT mode.", 1); return; } } else if (message.ToLower() == "nuke") { if (!p.allowTnt) { Player.SendMessage(p, "Tnt usage is not allowed at the moment!"); return; } - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 3)) { + if (CheckAdditionalPerm(p, 3)) { p.modeType = Block.nuketnt; Player.SendMessage(p, "TNT (Nuke) mode is now &aON%S."); } else { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 3), "to use nuke TNT mode."); return; + MessageNeedPerms(p, "can use nuke TNT mode.", 3); return; } } else if (message.ToLower() == "allow") { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) { + if (CheckAdditionalPerm(p, 2)) { p.allowTnt = true; Player.SendMessage(p, "&cTnt usage has now been enabled!"); } else { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 2), "to allow TNT usage."); return; + MessageNeedPerms(p, "can allow TNT usage.", 2); return; } return; } else if (message.ToLower() == "disallow") { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) { + if (CheckAdditionalPerm(p, 2)) { p.allowTnt = false; Player.SendMessage(p, "&cTnt usage has now been disabled!"); } else { - MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 2), "to disallow TNT usage."); return; + MessageNeedPerms(p, "can disallow TNT usage.", 2); return; } return; } else { @@ -92,7 +92,7 @@ namespace MCGalaxy.Commands public override void Help(Player p) { Player.SendMessage(p, "/tnt [small/big/nuke] - Creates exploding TNT (with Physics 3)."); Player.SendMessage(p, "Big and Nuke TNT is reserved for " + Group.findPermInt(CommandOtherPerms.GetPerm(this, 3)).name + "+"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) { + if (CheckAdditionalPerm(p, 2)) { Player.SendMessage(p, "/tnt allow - Allows the use of tnt server-wide."); Player.SendMessage(p, "/tnt disallow - Disallows the use of tnt server-wide."); } diff --git a/Commands/other/CmdWarp.cs b/Commands/other/CmdWarp.cs index dee1d36e9..5e4ff7d62 100644 --- a/Commands/other/CmdWarp.cs +++ b/Commands/other/CmdWarp.cs @@ -64,7 +64,7 @@ namespace MCGalaxy.Commands if (par0 == "create" || par0 == "add" || par0 == "c" || par0 == "a") { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) + if (CheckAdditionalPerm(p, 1)) { if (par1 == null) { Player.SendMessage(p, "You didn't specify a name for the warp!"); return; } if (Warp.WarpExists(par1)) { Player.SendMessage(p, "Warp has already been created!!"); return; } @@ -85,12 +85,12 @@ namespace MCGalaxy.Commands } } } - else { MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 1), "to create warps."); return; } + else { MessageNeedPerms(p, "can create warps.", 1); return; } } if (par0 == "delete" || par0 == "remove" || par0 == "d" || par0 == "r") { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) + if (CheckAdditionalPerm(p, 2)) { if (par1 == null) { Player.SendMessage(p, "You didn't specify a warp to delete!"); return; } if (!Warp.WarpExists(par1)) { Player.SendMessage(p, "Warp doesn't exist!!"); return; } @@ -110,12 +110,12 @@ namespace MCGalaxy.Commands } } } - else { MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 2), "to delete warps"); return; } + else { MessageNeedPerms(p, "can delete warps.", 2); return; } } if (par0 == "move" || par0 == "change" || par0 == "edit" || par0 == "m" || par0 == "e") { - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 3)) + if (CheckAdditionalPerm(p, 3)) { if (par1 == null) { Player.SendMessage(p, "You didn't specify a warp to be moved!"); return; } if (!Warp.WarpExists(par1)) { Player.SendMessage(p, "Warp doesn't exist!!"); return; } @@ -136,7 +136,7 @@ namespace MCGalaxy.Commands } } } - else { MessageNeedPerms(p, CommandOtherPerms.GetPerm(this, 3), "to move warps."); return; } + else { MessageNeedPerms(p, "can move warps.", 3); return; } } else @@ -173,18 +173,12 @@ namespace MCGalaxy.Commands { Player.SendMessage(p, "/warp [name] - warp to that warp"); Player.SendMessage(p, "/warp list - list all the warps"); - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 1)) - { + if (CheckAdditionalPerm(p, 1)) Player.SendMessage(p, "/warp create [name] - create a warp, if a is given, it will be created where they are"); - } - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 2)) - { + if (CheckAdditionalPerm(p, 2)) Player.SendMessage(p, "/warp delete [name] - delete a warp"); - } - if ((int)p.group.Permission >= CommandOtherPerms.GetPerm(this, 3)) - { + if (CheckAdditionalPerm(p, 3)) Player.SendMessage(p, "/warp move [name] - move a warp, if a is given, it will be created where they are"); - } } } }