mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Implement perbuild whitelist/blacklist in /mapinfo and /perbuild.
This commit is contained in:
parent
cca3e10b8c
commit
5a8da27f6b
@ -89,14 +89,19 @@ namespace MCGalaxy.Commands {
|
||||
" %S: Visit rank = " + Group.findPerm(data.visit).ColoredName);
|
||||
Player.Message(p, " BuildMax Rank = " + Group.findPerm(data.buildmax).ColoredName +
|
||||
" %S: VisitMax Rank = " + Group.findPerm(data.visitmax).ColoredName);
|
||||
List<string> whitelist = data.VisitWhitelist;
|
||||
List<string> blacklist = data.VisitBlacklist;
|
||||
GetBlacklistedPlayers(data.Name, blacklist);
|
||||
|
||||
List<string> vWhitelist = data.VisitWhitelist, vBlacklist = data.VisitBlacklist;
|
||||
List<string> bWhitelist = data.BuildWhitelist, bBlacklist = data.BuildBlacklist;
|
||||
GetBlacklistedPlayers(data.Name, vBlacklist);
|
||||
|
||||
if (whitelist.Count > 0)
|
||||
Player.Message(p, " Visit whitelist: &a" + whitelist.Join("%S, &a"));
|
||||
if (blacklist.Count > 0)
|
||||
Player.Message(p, " Visit blacklist: &c" + blacklist.Join("%S, &c"));
|
||||
if (vWhitelist.Count > 0)
|
||||
Player.Message(p, " Visit whitelist: &a" + vWhitelist.Join("%S, &a"));
|
||||
if (vBlacklist.Count > 0)
|
||||
Player.Message(p, " Visit blacklist: &c" + vBlacklist.Join("%S, &c"));
|
||||
if (bWhitelist.Count > 0)
|
||||
Player.Message(p, " Build whitelist: &a" + bWhitelist.Join("%S, &a"));
|
||||
if (bBlacklist.Count > 0)
|
||||
Player.Message(p, " Build blacklist: &c" + bBlacklist.Join("%S, &c"));
|
||||
|
||||
if (String.IsNullOrEmpty(data.RealmOwner))
|
||||
data.RealmOwner = GetRealmMapOwner(data.Name);
|
||||
@ -165,6 +170,8 @@ namespace MCGalaxy.Commands {
|
||||
public LevelPermission visit, build, visitmax, buildmax;
|
||||
public List<string> VisitWhitelist = new List<string>();
|
||||
public List<string> VisitBlacklist = new List<string>();
|
||||
public List<string> BuildWhitelist = new List<string>();
|
||||
public List<string> BuildBlacklist = new List<string>();
|
||||
// Zombie data
|
||||
public string Authors;
|
||||
public int TotalRounds, HumanRounds;
|
||||
@ -180,6 +187,8 @@ namespace MCGalaxy.Commands {
|
||||
visitmax = lvl.pervisitmax; buildmax = lvl.perbuildmax;
|
||||
VisitWhitelist = new List<string>(lvl.VisitWhitelist);
|
||||
VisitBlacklist = new List<string>(lvl.VisitBlacklist);
|
||||
BuildWhitelist = new List<string>(lvl.BuildWhitelist);
|
||||
BuildBlacklist = new List<string>(lvl.BuildBlacklist);
|
||||
|
||||
Fog = lvl.FogColor; Sky = lvl.SkyColor; Clouds = lvl.CloudColor;
|
||||
Light = lvl.LightColor; Shadow = lvl.ShadowColor;
|
||||
@ -222,6 +231,8 @@ namespace MCGalaxy.Commands {
|
||||
case "pervisitmax": visitmax = GetPerm(value); break;
|
||||
case "visitwhitelist": VisitWhitelist = Parse(value); break;
|
||||
case "visitblacklist": VisitBlacklist = Parse(value); break;
|
||||
case "buildwhitelist": BuildWhitelist = Parse(value); break;
|
||||
case "buildblacklist": BuildBlacklist = Parse(value); break;
|
||||
|
||||
case "authors": Authors = value; break;
|
||||
case "roundsplayed": TotalRounds = int.Parse(value); break;
|
||||
|
@ -37,19 +37,20 @@ namespace MCGalaxy.Commands.World {
|
||||
return grp != null ? level : null;
|
||||
}
|
||||
|
||||
public static void UseList(Player p, string[] args, string target,
|
||||
Func<Level, LevelPermission> getter,
|
||||
Func<Level, List<string>> wlGetter, Func<Level, List<string>> blGetter) {
|
||||
protected void UseList(Player p, string[] args, bool isVisit) {
|
||||
string target = isVisit ? "pervisit" : "perbuild";
|
||||
if (args.Length == 1 && Player.IsSuper(p)) {
|
||||
Command.SuperRequiresArgs(target, p, "level"); return;
|
||||
}
|
||||
Level level = args.Length == 1 ? p.level : LevelInfo.FindMatches(p, args[0]);
|
||||
if (level == null) return;
|
||||
LevelAccess access = isVisit ? level.VisitAccess : level.BuildAccess;
|
||||
|
||||
string name = args.Length == 1 ? args[0] : args[1];
|
||||
string mode = name[0] == '+' ? "whitelist" : "blacklist";
|
||||
List<string> list = name[0] == '+' ? wlGetter(level) : blGetter(level);
|
||||
List<string> other = name[0] == '+' ? blGetter(level) : wlGetter(level);
|
||||
bool include = name[0] == '+';
|
||||
string mode = include ? "whitelist" : "blacklist";
|
||||
List<string> list = include ? access.Whitelisted : access.Blacklisted;
|
||||
List<string> other = include ? access.Blacklisted : access.Whitelisted;
|
||||
name = name.Substring(1);
|
||||
|
||||
if (name == "") {
|
||||
@ -59,12 +60,8 @@ namespace MCGalaxy.Commands.World {
|
||||
Player.Message(p, "You cannot {0} yourself.", mode); return;
|
||||
}
|
||||
|
||||
if (p != null && getter(level) > p.Rank) {
|
||||
Player.Message(p, "You cannot change the {0} {1} permissions " +
|
||||
"for a player higher than your rank.", target, mode); return;
|
||||
}
|
||||
if (p != null && blGetter(level).CaselessContains(p.name)) {
|
||||
Player.Message(p, "You cannot change {0} permissions as you are blacklisted.", target); return;
|
||||
if (p != null && !access.CheckDetailed(p, false)) {
|
||||
Player.Message(p, "Hence you cannot modify the {0} {1}.", target, mode); return;
|
||||
}
|
||||
if (p != null && PlayerInfo.GetGroup(name).Permission > p.Rank) {
|
||||
Player.Message(p, "You cannot whitelist/blacklist players of a higher rank."); return;
|
||||
@ -73,10 +70,10 @@ namespace MCGalaxy.Commands.World {
|
||||
if (list.CaselessContains(name)) {
|
||||
Player.Message(p, "\"{0}\" is already {1}ed.", name, mode); return;
|
||||
}
|
||||
list.Add(name);
|
||||
other.CaselessRemove(name);
|
||||
if (!other.CaselessRemove(name))
|
||||
list.Add(name);
|
||||
|
||||
UpdateAllowBuild(level);
|
||||
access.UpdateAllowBuild();
|
||||
Level.SaveSettings(level);
|
||||
|
||||
string msg = name + " was " + target + " " + mode + "ed";
|
||||
@ -85,13 +82,20 @@ namespace MCGalaxy.Commands.World {
|
||||
if (p == null || p.level != level)
|
||||
Player.Message(p, msg + " on {0}.", level.name);
|
||||
}
|
||||
|
||||
|
||||
static void UpdateAllowBuild(Level level) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
if (p.level != level) continue;
|
||||
p.AllowBuild = level.BuildAccess.Check(p, false);
|
||||
}
|
||||
protected void MaxHelp(Player p, string action) {
|
||||
Player.Message(p, "%T/{0} [Level] [Rank]", name);
|
||||
Player.Message(p, "%HSets the highest rank able to {0} the given level.", action);
|
||||
}
|
||||
|
||||
protected void NormalHelp(Player p, string action, string action2) {
|
||||
Player.Message(p, "%T/{0} [level] [rank]", name);
|
||||
Player.Message(p, "%HSets the lowest rank able to {0} the given level.", action);
|
||||
Player.Message(p, "%T/{0} [level] +[name]", name);
|
||||
Player.Message(p, "%HAllows [name] to {0}, even if their rank cannot.", action2);
|
||||
Player.Message(p, "%T/{0} [level] -[name]", name);
|
||||
Player.Message(p, "%HPrevents [name] from {0}ing, even if their rank can.", action2);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,10 +31,7 @@ namespace MCGalaxy.Commands.World {
|
||||
if (lvl != null) lvl.BuildAccess.SetMax(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/perbuildmax [Level] [Rank]");
|
||||
Player.Message(p, "%HSets the highest rank able to build on the given level.");
|
||||
}
|
||||
public override void Help(Player p) { MaxHelp(p, "build on"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionBuild : PermissionCmd {
|
||||
@ -44,15 +41,17 @@ namespace MCGalaxy.Commands.World {
|
||||
string[] args = message.Split(' ');
|
||||
if (args.Length < 1 || args.Length > 2) { Help(p); return; }
|
||||
|
||||
string name = args[args.Length - 1];
|
||||
if (name.Length > 0 && (name[0] == '+' || name[0] == '-')) {
|
||||
UseList(p, args, false); return;
|
||||
}
|
||||
|
||||
Group grp = null;
|
||||
Level lvl = GetArgs(p, args, ref grp);
|
||||
if (lvl != null) lvl.BuildAccess.SetMin(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/perbuild [Level] [Rank]");
|
||||
Player.Message(p, "%HSets the lowest rank able to build on the given level.");
|
||||
}
|
||||
public override void Help(Player p) { NormalHelp(p, "build on", "build"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPervisitMax : PermissionCmd {
|
||||
@ -67,10 +66,7 @@ namespace MCGalaxy.Commands.World {
|
||||
if (lvl != null) lvl.VisitAccess.SetMax(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/pervisitmax [level] [rank]");
|
||||
Player.Message(p, "%HSets the highest rank able to visit the given level.");
|
||||
}
|
||||
public override void Help(Player p) { MaxHelp(p, "visit"); }
|
||||
}
|
||||
|
||||
public sealed class CmdPermissionVisit : PermissionCmd {
|
||||
@ -82,8 +78,7 @@ namespace MCGalaxy.Commands.World {
|
||||
|
||||
string name = args[args.Length - 1];
|
||||
if (name.Length > 0 && (name[0] == '+' || name[0] == '-')) {
|
||||
PermissionCmd.UseList(p, args, "pervisit", l => l.permissionvisit,
|
||||
l => l.VisitWhitelist, l => l.VisitBlacklist); return;
|
||||
UseList(p, args, true); return;
|
||||
}
|
||||
|
||||
Group grp = null;
|
||||
@ -91,13 +86,6 @@ namespace MCGalaxy.Commands.World {
|
||||
if (lvl != null) lvl.VisitAccess.SetMin(p, grp);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/pervisit [level] [rank]");
|
||||
Player.Message(p, "%HSets the lowest rank able to visit the given level.");
|
||||
Player.Message(p, "%T/pervisit [level] +[name]");
|
||||
Player.Message(p, "%HAllows [name] to visit the map, even if their rank cannot.");
|
||||
Player.Message(p, "%T/pervisit [level] -[name]");
|
||||
Player.Message(p, "%HPrevents [name] from visiting the map, even if their rank can.");
|
||||
}
|
||||
public override void Help(Player p) { NormalHelp(p, "visit", "visit"); }
|
||||
}
|
||||
}
|
@ -148,7 +148,7 @@ namespace MCGalaxy {
|
||||
Player.Message(p, "{0} permission changed to {1}%S on {2}.", target, grp.ColoredName, lvl.name);
|
||||
}
|
||||
|
||||
void UpdateAllowBuild() {
|
||||
internal void UpdateAllowBuild() {
|
||||
if (IsVisit) return;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player p in players) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user