Simplify some use of ItemPerms

This commit is contained in:
UnknownShadow200 2020-05-21 21:17:48 +10:00
parent 5386ad74b4
commit 466f1c9f68
6 changed files with 12 additions and 12 deletions

View File

@ -72,8 +72,7 @@ namespace MCGalaxy {
public static bool CanEditAny(Player p) { public static bool CanEditAny(Player p) {
if (LevelInfo.IsRealmOwner(p.name, p.level.name)) { return true; } if (LevelInfo.IsRealmOwner(p.name, p.level.name)) { return true; }
ItemPerms perms = CommandExtraPerms.Find("Bot", 1); ItemPerms perms = CommandExtraPerms.Find("Bot", 1) ?? new ItemPerms(LevelPermission.Operator);
perms = perms == null ? new ItemPerms(LevelPermission.Operator, null, null) : perms;
if (perms.UsableBy(p.Rank)) { return true; } if (perms.UsableBy(p.Rank)) { return true; }
return false; return false;
} }
@ -308,10 +307,10 @@ namespace MCGalaxy {
ScaleZ == 0 ? "none" : ScaleZ.ToString() ScaleZ == 0 ? "none" : ScaleZ.ToString()
); );
} }
if (String.IsNullOrEmpty(ClickedOnText)) { return; }
ItemPerms perms = CommandExtraPerms.Find("About", 1); if (String.IsNullOrEmpty(ClickedOnText)) return;
perms = perms == null ? new ItemPerms(LevelPermission.AdvBuilder, null, null) : perms; ItemPerms perms = CommandExtraPerms.Find("About", 1) ?? new ItemPerms(LevelPermission.AdvBuilder);
if (!perms.UsableBy(p.Rank)) { return; } //don't show bot's ClickedOnText if player isn't allowed to see message block contents if (!perms.UsableBy(p.Rank)) return; //don't show bot's ClickedOnText if player isn't allowed to see message block contents
p.Message(" Clicked-on text: {0}", ClickedOnText); p.Message(" Clicked-on text: {0}", ClickedOnText);
} }

View File

@ -46,14 +46,14 @@ namespace MCGalaxy {
public static ItemPerms OpchatPerms { public static ItemPerms OpchatPerms {
get { get {
ItemPerms perms = CommandExtraPerms.Find("OpChat", 1); ItemPerms perms = CommandExtraPerms.Find("OpChat", 1);
return perms != null ? perms : new ItemPerms(LevelPermission.Operator, null, null); return perms ?? new ItemPerms(LevelPermission.Operator);
} }
} }
public static ItemPerms AdminchatPerms { public static ItemPerms AdminchatPerms {
get { get {
ItemPerms perms = CommandExtraPerms.Find("AdminChat", 1); ItemPerms perms = CommandExtraPerms.Find("AdminChat", 1);
return perms != null ? perms : new ItemPerms(LevelPermission.Admin, null, null); return perms ?? new ItemPerms(LevelPermission.Admin);
} }
} }

View File

@ -30,6 +30,7 @@ namespace MCGalaxy.Commands.Eco {
if (!ParseArgs(p, message, ref all, "pay", out trans)) return; if (!ParseArgs(p, message, ref all, "pay", out trans)) return;
// Player can use /pay messages to bypass a mute // Player can use /pay messages to bypass a mute
// TODO: Make MessageCmd.CanSpeak more generic so that can be used here instead
if (trans.Reason != null && !p.CanSpeak()) { if (trans.Reason != null && !p.CanSpeak()) {
p.Message("%WCannot specify a payment reason, as you cannot currently speak"); p.Message("%WCannot specify a payment reason, as you cannot currently speak");
return; return;

View File

@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.Moderation {
} }
static void AnnounceOps(Player p, string msg) { static void AnnounceOps(Player p, string msg) {
ItemPerms perms = new ItemPerms(p.hideRank, null, null); ItemPerms perms = new ItemPerms(p.hideRank);
Chat.MessageFrom(ChatScope.Perms, p, msg, perms, null, true); Chat.MessageFrom(ChatScope.Perms, p, msg, perms, null, true);
} }

View File

@ -28,6 +28,8 @@ namespace MCGalaxy {
public LevelPermission MinRank; public LevelPermission MinRank;
public List<LevelPermission> Allowed, Disallowed; public List<LevelPermission> Allowed, Disallowed;
public ItemPerms(LevelPermission min) { Init(min, null, null); }
public ItemPerms(LevelPermission min, List<LevelPermission> allowed, public ItemPerms(LevelPermission min, List<LevelPermission> allowed,
List<LevelPermission> disallowed) { List<LevelPermission> disallowed) {
Init(min, allowed, disallowed); Init(min, allowed, disallowed);

View File

@ -25,9 +25,7 @@ namespace MCGalaxy {
public static class Formatter { public static class Formatter {
public static void PrintCommandInfo(Player p, Command cmd) { public static void PrintCommandInfo(Player p, Command cmd) {
ItemPerms perms = CommandPerms.Find(cmd.name); ItemPerms perms = CommandPerms.Find(cmd.name) ?? new ItemPerms(cmd.defaultRank);
if (perms == null) perms = new ItemPerms(cmd.defaultRank, null, null);
p.Message("Usable by: " + perms.Describe()); p.Message("Usable by: " + perms.Describe());
PrintAliases(p, cmd); PrintAliases(p, cmd);