mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-10-03 10:33:29 -04:00
Add an overload to LevelInfo.Check that outputs LevelConfig instance
This avoids having to pointlessly call GetConfig a second time, which potentially be quite slow
This commit is contained in:
parent
d7aa8b0cab
commit
0540b25c42
@ -36,24 +36,23 @@ namespace MCGalaxy.Commands.World {
|
||||
if (args.Length < 2) {
|
||||
p.Message("You did not specify the destination level name."); return;
|
||||
}
|
||||
LevelConfig cfg;
|
||||
|
||||
string src = Matcher.FindMaps(p, args[0]);
|
||||
if (src == null) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, src, "copy this map")) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, src, "copy this map", out cfg)) return;
|
||||
|
||||
string dst = args[1];
|
||||
if (!Formatter.ValidMapName(p, dst)) return;
|
||||
|
||||
if (!LevelActions.Copy(p, src, dst)) return;
|
||||
Level ignored;
|
||||
LevelConfig cfg = LevelInfo.GetConfig(src, out ignored);
|
||||
Chat.MessageGlobal("Map {0} %Swas copied to {1}", cfg.Color + src, cfg.Color + dst);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
p.Message("%T/CopyLvl [level] [copied level]");
|
||||
p.Message("%HMakes a copy of [level] called [copied Level].");
|
||||
p.Message("%HNote: The level's BlockDB is not copied.");
|
||||
p.Message("%T/CopyLvl [map] [copied map]");
|
||||
p.Message("%HMakes a copy of [map] called [copied map].");
|
||||
p.Message("%HNote: The map's BlockDB is not copied.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,11 @@ namespace MCGalaxy.Commands.World {
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (message.Length == 0 || message.SplitSpaces().Length > 1) { Help(p); return; }
|
||||
string map = Matcher.FindMaps(p, message);
|
||||
LevelConfig cfg;
|
||||
|
||||
if (map == null) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, map, "delete this map")) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, map, "delete this map",out cfg)) return;
|
||||
|
||||
Level ignored;
|
||||
LevelConfig cfg = LevelInfo.GetConfig(map, out ignored);
|
||||
if (!LevelActions.Delete(p, map)) return;
|
||||
Chat.MessageGlobal("Map {0} %Swas deleted", cfg.Color + map);
|
||||
}
|
||||
@ -45,7 +44,7 @@ namespace MCGalaxy.Commands.World {
|
||||
public override void Help(Player p) {
|
||||
p.Message("%T/DeleteLvl [map]");
|
||||
p.Message("%HCompletely deletes [map] (portals, MBs, everything)");
|
||||
p.Message("%HA backup of the map will be placed in the levels/deleted folder");
|
||||
p.Message("%HA backup of the map is made in the levels/deleted folder");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,23 +31,22 @@ namespace MCGalaxy.Commands.World {
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
string[] args = message.SplitSpaces();
|
||||
if (args.Length != 2) { Help(p); return; }
|
||||
LevelConfig cfg;
|
||||
|
||||
string src = Matcher.FindMaps(p, args[0]);
|
||||
if (src == null) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, src, "rename this map")) return;
|
||||
if (!LevelInfo.Check(p, data.Rank, src, "rename this map", out cfg)) return;
|
||||
|
||||
string dst = args[1].ToLower();
|
||||
if (!Formatter.ValidMapName(p, dst)) return;
|
||||
|
||||
if (!LevelActions.Rename(p, src, dst)) return;
|
||||
Level ignored;
|
||||
LevelConfig cfg = LevelInfo.GetConfig(dst, out ignored);
|
||||
Chat.MessageGlobal("Map {0} %Swas renamed to {1}", cfg.Color + src, cfg.Color + dst);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
p.Message("%T/RenameLvl [level] [new name]");
|
||||
p.Message("%HRenames [level] to [new name]");
|
||||
p.Message("%T/RenameLvl [map] [new name]");
|
||||
p.Message("%HRenames [map] to [new name]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,9 +121,9 @@ namespace MCGalaxy {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
internal static bool Check(Player p, LevelPermission plRank, string map, string action) {
|
||||
public static bool Check(Player p, LevelPermission plRank, string map, string action, out LevelConfig cfg) {
|
||||
Level lvl; cfg = GetConfig(map, out lvl);
|
||||
if (p.IsConsole) return true;
|
||||
Level lvl; LevelConfig cfg = GetConfig(map, out lvl);
|
||||
if (lvl != null) return Check(p, plRank, lvl, action);
|
||||
|
||||
AccessController visit = new LevelAccessController(cfg, map, true);
|
||||
@ -134,6 +134,11 @@ namespace MCGalaxy {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool Check(Player p, LevelPermission plRank, string map, string action) {
|
||||
LevelConfig ignored;
|
||||
return Check(p, plRank, map, action, out ignored);
|
||||
}
|
||||
|
||||
public static bool Check(Player p, LevelPermission plRank, Level lvl, string action) {
|
||||
if (p.IsConsole) return true;
|
||||
if (!lvl.VisitAccess.CheckDetailed(p, plRank) || !lvl.BuildAccess.CheckDetailed(p, plRank)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user