Convert the old /os blacklist txt files to VisitBlacklist in level properties.

This commit is contained in:
UnknownShadow200 2016-09-10 11:52:22 +10:00
parent 94879791a8
commit b97dc56257
5 changed files with 35 additions and 29 deletions

View File

@ -267,24 +267,13 @@ namespace MCGalaxy.Commands {
Level.SaveSettings(p.level);
Player.Message(p, value + " has been removed from your map's blacklist.");
} else if (cmd == "BLACKLIST") {
string path = "levels/blacklists/" + p.level.name + ".txt";
if (!File.Exists(path)) {
Player.Message(p, "There are no blacklisted players on this map.");
} else {
Player.Message(p, "Current blocked players on level &b" + p.level.name + "%S:");
string blocked = "";
string[] lines = File.ReadAllLines(path);
foreach (string line in lines) {
string player = line.Split(' ')[1];
blocked += player + ", ";
}
Player.Message(p, blocked);
}
} else if (cmd == "BLACKLIST") {
List<string> blacklist = p.level.VisitAccess.Blacklisted;
if (blacklist.Count > 0)
if (blacklist.Count > 0) {
Player.Message(p, "Blacklisted players: " + blacklist.Join());
} else {
Player.Message(p, "There are no blacklisted players on this map.");
}
} else {
Player.MessageLines(p, zoneHelp);
}

View File

@ -146,10 +146,6 @@ namespace MCGalaxy {
public bool CanJoin(Player p) {
if (p == null) return true;
if (Player.BlacklistCheck(p.name, name)) {
Player.Message(p, "You are blacklisted from going to {0}.", name); return false;
}
if (!VisitAccess.CheckDetailed(p, p.ignorePermission)) return false;
if (File.Exists("text/lockdown/map/" + name)) {
Player.Message(p, "The level " + name + " is locked."); return false;

View File

@ -498,13 +498,6 @@ namespace MCGalaxy {
CurrentAmountOfTnt--;
}
public static bool BlacklistCheck(string name, string foundLevel) {
string path = "levels/blacklists/" + foundLevel + ".txt";
if (!File.Exists(path)) return false;
if (File.ReadAllText(path).Contains(name)) return true;
return false;
}
internal static bool CheckVote(string message, Player p, string a, string b, ref int totalVotes) {
if (!p.voted && (message == a || message == b)) {
totalVotes++;

View File

@ -70,7 +70,7 @@ namespace MCGalaxy {
void LoadPlayerLists() {
agreed = new PlayerList("ranks/agreed.txt");
try {
CheckOldAgreed();
UpgradeOldAgreed();
agreed = PlayerList.Load("agreed.txt");
} catch (Exception ex) {
Server.ErrorLog(ex);
@ -95,7 +95,34 @@ namespace MCGalaxy {
whiteList = PlayerList.Load("whitelist.txt");
}
void CheckOldAgreed() {
static void UpgradeOldBlacklist() {
if (!Directory.Exists("levels/blacklists")) return;
string[] files = Directory.GetFiles("levels/blacklists");
for (int i = 0; i < files.Length; i++) {
string[] blacklist = File.ReadAllLines(files[i]);
List<string> names = new List<string>();
// Lines are in the format: day.month.year name+
foreach (string entry in blacklist) {
string[] parts = entry.Split(' ');
string name = parts[parts.Length - 1];
name = name.Substring(0, name.Length - 1);
names.Add(name);
}
if (names.Count > 0) {
string lvlName = Path.GetFileNameWithoutExtension(files[i]);
string propsPath = LevelInfo.PropertiesPath(lvlName);
using (StreamWriter w = new StreamWriter(propsPath, true)) {
w.WriteLine("VisitBlacklist = " + names.Join());
}
}
File.Delete(files[i]);
}
Directory.Delete("levels/blacklists");
}
static void UpgradeOldAgreed() {
// agreed.txt format used to be names separated by spaces, we need to fix that up.
if (!File.Exists("ranks/agreed.txt")) return;

View File

@ -102,6 +102,7 @@ namespace MCGalaxy {
Background.QueueOnce(CombineEnvFiles);
Background.QueueOnce(LoadMainLevel);
Plugin.Load();
Background.QueueOnce(UpgradeOldBlacklist);
Background.QueueOnce(LoadPlayerLists);
Background.QueueOnce(LoadAutoloadCommands);
Background.QueueOnce(MovePreviousLevelFiles);