ZoneConfig doesn't keep a reference to Level

This commit is contained in:
UnknownShadow200 2018-04-19 10:47:04 +10:00
parent db294ce5cf
commit 58e546dad4
5 changed files with 58 additions and 63 deletions

View File

@ -69,7 +69,7 @@ namespace MCGalaxy.Commands.Moderation {
Zone z = new Zone(p.level);
z.Config.Name = args[offset];
if (!PermissionCmd.Do(p, args, offset + 1, false, z.Access)) return;
if (!PermissionCmd.Do(p, args, offset + 1, false, z.Access, p.level)) return;
Player.Message(p, "Creating zone " + z.ColoredName);
Player.Message(p, "Place or break two blocks to determine the edges.");
@ -105,8 +105,7 @@ namespace MCGalaxy.Commands.Moderation {
}
void EditZone(Player p, string[] args, Zone zone) {
if (!PermissionCmd.Do(p, args, 2, false, zone.Access)) return;
p.level.Save(true);
PermissionCmd.Do(p, args, 2, false, zone.Access, p.level);
}
void SetZoneProp(Player p, string[] args, Zone zone) {

View File

@ -119,17 +119,18 @@ namespace MCGalaxy.Commands.World {
args[1], args[2], args[3]);
} else if (cmd == "PERVISIT") {
// Older realm maps didn't put you on visit whitelist, so make sure we put the owner here
if (!p.level.VisitAccess.Whitelisted.CaselessContains(p.name)) {
p.level.VisitAccess.Whitelist(null, p.name);
AccessController access = p.level.VisitAccess;
if (!access.Whitelisted.CaselessContains(p.name)) {
access.Whitelist(null, p.level, p.name);
}
string rank = value.Length == 0 ? ServerConfig.DefaultRankName : value;
Group grp = Matcher.FindRanks(p, rank);
if (grp != null) p.level.VisitAccess.SetMin(null, grp);
if (grp != null) access.SetMin(null, p.level, grp);
} else if (cmd == "PERBUILD") {
string rank = value.Length == 0 ? ServerConfig.DefaultRankName : value;
Group grp = Matcher.FindRanks(p, rank);
if (grp != null) p.level.BuildAccess.SetMin(null, grp);
if (grp != null) p.level.BuildAccess.SetMin(null, p.level, grp);
} else if (cmd == "TEXTURE" || cmd == "TEXTUREZIP" || cmd == "TEXTUREPACK") {
if (value.Length == 0) {
Command.all.FindByName("Texture").Use(p, "levelzip normal");
@ -181,13 +182,13 @@ namespace MCGalaxy.Commands.World {
internal static bool SetPerms(Player p, Level lvl) {
lvl.Config.RealmOwner = p.name;
lvl.BuildAccess.Whitelist(null, p.name);
lvl.VisitAccess.Whitelist(null, p.name);
lvl.BuildAccess.Whitelist(null, lvl, p.name);
lvl.VisitAccess.Whitelist(null, lvl, p.name);
Group grp = Group.Find(ServerConfig.OSPerbuildDefault);
if (grp == null) return false;
lvl.BuildAccess.SetMin(null, grp);
lvl.BuildAccess.SetMin(null, lvl, grp);
return true;
}
@ -258,11 +259,11 @@ namespace MCGalaxy.Commands.World {
Player.Message(p, "Added zone for &b" + name);
LevelAccessController access = p.level.BuildAccess;
if (access.Blacklisted.CaselessRemove(name)) {
access.OnListChanged(p, name, true, true);
access.OnListChanged(p, p.level, name, true, true);
}
if (!access.Whitelisted.CaselessContains(name)) {
access.Whitelisted.Add(name);
access.OnListChanged(p, name, true, false);
access.OnListChanged(p, p.level, name, true, false);
}
}
@ -271,7 +272,7 @@ namespace MCGalaxy.Commands.World {
LevelAccessController access = p.level.BuildAccess;
if (access.Whitelisted.CaselessRemove(name)) {
access.OnListChanged(p, name, false, true);
access.OnListChanged(p, p.level, name, false, true);
} else {
Player.Message(p, name + " was not whitelisted.");
}
@ -283,7 +284,7 @@ namespace MCGalaxy.Commands.World {
Player.Message(p, name + " is not blacklisted."); return;
}
blacklist.CaselessRemove(name);
p.level.VisitAccess.OnListChanged(p, name, true, true);
p.level.VisitAccess.OnListChanged(p, p.level, name, true, true);
}
static void RemoveVisitPlayer(Player p, string name) {
@ -292,7 +293,7 @@ namespace MCGalaxy.Commands.World {
Player.Message(p, name + " is already blacklisted."); return;
}
blacklist.Add(name);
p.level.VisitAccess.OnListChanged(p, name, false, false);
p.level.VisitAccess.OnListChanged(p, p.level, name, false, false);
}
static void HandleZones(Player p, string cmd, string args) {

View File

@ -24,19 +24,19 @@ namespace MCGalaxy.Commands.World {
public override bool museumUsable { get { return false; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public static bool Do(Player p, string[] args, int offset, bool max, AccessController access) {
public static bool Do(Player p, string[] args, int offset, bool max, AccessController access, Level lvl) {
for (int i = offset; i < args.Length; i++) {
string arg = args[i];
if (arg[0] == '+' || arg[0] == '-') {
if (!SetList(p, access, arg)) return false;
if (!SetList(p, access, arg, lvl)) return false;
} else if (max) {
Group grp = Matcher.FindRanks(p, arg);
if (grp == null) return false;
access.SetMax(p, grp);
access.SetMax(p, lvl, grp);
} else {
Group grp = Matcher.FindRanks(p, arg);
if (grp == null) return false;
access.SetMin(p, grp);
access.SetMin(p, lvl, grp);
}
}
return true;
@ -65,10 +65,10 @@ namespace MCGalaxy.Commands.World {
} else {
access = visit ? lvl.VisitAccess : lvl.BuildAccess;
}
Do(p, args, offset, max, access);
Do(p, args, offset, max, access, lvl);
}
static bool SetList(Player p, AccessController access, string name) {
static bool SetList(Player p, AccessController access, string name, Level lvl) {
bool include = name[0] == '+';
string mode = include ? "whitelist" : "blacklist";
name = name.Substring(1);
@ -86,9 +86,9 @@ namespace MCGalaxy.Commands.World {
}
if (include) {
access.Whitelist(p, name);
access.Whitelist(p, lvl, name);
} else {
access.Blacklist(p, name);
access.Blacklist(p, lvl, name);
}
return true;
}

View File

@ -104,28 +104,28 @@ namespace MCGalaxy {
}
public bool SetMin(Player p, Group grp) {
public bool SetMin(Player p, Level lvl, Group grp) {
string minType = "Min " + Type;
if (!CheckRank(p, Min, minType, false)) return false;
if (!CheckRank(p, grp.Permission, minType, true)) return false;
Min = grp.Permission;
OnPermissionChanged(p, grp, minType);
OnPermissionChanged(p, lvl, grp, minType);
return true;
}
public bool SetMax(Player p, Group grp) {
public bool SetMax(Player p, Level lvl, Group grp) {
string maxType = "Max " + Type;
const LevelPermission ignore = LevelPermission.Nobody;
if (Max != ignore && !CheckRank(p, Max, maxType, false)) return false;
if (grp.Permission != ignore && !CheckRank(p, grp.Permission, maxType, true)) return false;
Max = grp.Permission;
OnPermissionChanged(p, grp, maxType);
OnPermissionChanged(p, lvl, grp, maxType);
return true;
}
public bool Whitelist(Player p, string target) {
public bool Whitelist(Player p, Level lvl, string target) {
if (!CheckList(p, target, true)) return false;
if (Whitelisted.CaselessContains(target)) {
Player.Message(p, "{0} %Sis already whitelisted.", PlayerInfo.GetColoredName(p, target));
@ -137,11 +137,11 @@ namespace MCGalaxy {
Whitelisted.Add(target);
removed = false;
}
OnListChanged(p, target, true, removed);
OnListChanged(p, lvl, target, true, removed);
return true;
}
public bool Blacklist(Player p, string target) {
public bool Blacklist(Player p, Level lvl, string target) {
if (!CheckList(p, target, false)) return false;
if (Blacklisted.CaselessContains(target)) {
Player.Message(p, "{0} %Sis already blacklisted.", PlayerInfo.GetColoredName(p, target));
@ -153,19 +153,18 @@ namespace MCGalaxy {
Blacklisted.Add(target);
removed = false;
}
OnListChanged(p, target, false, removed);
OnListChanged(p, lvl, target, false, removed);
return true;
}
public abstract void OnPermissionChanged(Player p, Group grp, string type);
public abstract void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite);
public abstract void OnPermissionChanged(Player p, Level lvl, Group grp, string type);
public abstract void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite);
bool CheckRank(Player p, LevelPermission perm, string type, bool newPerm) {
if (p != null && perm > p.Rank) {
Player.Message(p, "You cannot change the {0} rank of this level{1} higher than yours.",
type.ToLower(),
newPerm ? " to a rank" : ", as its current " + type.ToLower() + " rank is");
type.ToLower(), newPerm ? " to a rank" : ", as its current " + type.ToLower() + " rank is");
return false;
}
return true;
@ -238,12 +237,12 @@ namespace MCGalaxy {
protected override string MaxCmd { get { return IsVisit ? "PerVisit" : "PerBuild"; } }
public override void OnPermissionChanged(Player p, Group grp, string type) {
public override void OnPermissionChanged(Player p, Level lvl, Group grp, string type) {
string msg = type + " rank changed to " + grp.ColoredName;
DoChange(p, msg);
DoChange(p, lvl, msg);
}
public override void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite) {
public override void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite) {
string type = IsVisit ? "visit" : "build";
string msg = PlayerInfo.GetColoredName(p, name);
if (removedFromOpposite) {
@ -251,15 +250,14 @@ namespace MCGalaxy {
} else {
msg += " %Swas " + type + (whitelist ? " whitelisted" : " blacklisted");
}
DoChange(p, msg);
DoChange(p, lvl, msg);
}
void DoChange(Player p, string msg) {
Level lvl = LevelInfo.FindExact(lvlName);
void DoChange(Player p, Level lvl, string msg) {
Update(lvl);
Logger.Log(LogType.UserActivity, "{0} %Son {1}", msg, lvlName);
if (lvl != null) Chat.MessageLevel(lvl, msg);
if (lvl != null) Chat.MessageLevel(lvl, msg);
if (p != null && p.level != lvl) {
Player.Message(p, "{0} %Son {1}", msg, ColoredName);
}

View File

@ -35,13 +35,10 @@ namespace MCGalaxy {
}
/// <summary> Encapuslates build access permissions for a zone. </summary>
public sealed class ZoneAccessController : AccessController {
readonly Level lvl;
public sealed class ZoneAccessController : AccessController {
readonly ZoneConfig cfg;
public ZoneAccessController(Level lvl, ZoneConfig cfg) {
this.lvl = lvl;
public ZoneAccessController(ZoneConfig cfg) {
this.cfg = cfg;
}
@ -62,16 +59,12 @@ namespace MCGalaxy {
protected override string Type { get { return "build"; } }
protected override string MaxCmd { get { return null; } }
public override void OnPermissionChanged(Player p, Group grp, string type) {
Update();
Logger.Log(LogType.UserActivity, "{0} rank changed to {1} in zone {2}.", type, grp.Name, cfg.Name);
Chat.MessageLevel(lvl, type + " rank changed to " + grp.ColoredName + " %Sin zone " + cfg.Color + cfg.Name);
if (p != null && p.level != lvl) {
Player.Message(p, "{0} rank changed to {1} %Sin {2}%S.", type, grp.ColoredName, ColoredName);
}
public override void OnPermissionChanged(Player p, Level lvl, Group grp, string type) {
string msg = type + " rank changed to " + grp.ColoredName + " %Sin " + ColoredName;
DoChange(p, lvl, msg);
}
public override void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite) {
public override void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite) {
string msg = PlayerInfo.GetColoredName(p, name);
if (removedFromOpposite) {
msg += " %Swas removed from the build" + (whitelist ? " blacklist" : " whitelist");
@ -79,15 +72,19 @@ namespace MCGalaxy {
msg += " %Swas build" + (whitelist ? " whitelisted" : " blacklisted");
}
Update();
Logger.Log(LogType.UserActivity, "{0} in zone {1}", msg, cfg.Name);
Chat.MessageLevel(lvl, msg + " in zone " + cfg.Color + cfg.Name);
if (p != null && p.level != lvl) {
Player.Message(p, "{0} in %S{1}", msg, ColoredName);
}
msg += "in " + ColoredName;
DoChange(p, lvl, msg);
}
void Update() { lvl.Save(true); }
void DoChange(Player p, Level lvl, string msg) {
lvl.Save(true);
Logger.Log(LogType.UserActivity, "{0} %Son {1}", msg, lvl.name);
Chat.MessageLevel(lvl, msg);
if (p != null && p.level != lvl) {
Player.Message(p, "{0} %Son {1}", msg, lvl.ColoredName);
}
}
}
public class Zone {
@ -101,7 +98,7 @@ namespace MCGalaxy {
public Zone(Level lvl) {
Config = new ZoneConfig();
Access = new ZoneAccessController(lvl, Config);
Access = new ZoneAccessController(Config);
}