mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
Reduce award saving overhead, make award saving threadsafe.
This commit is contained in:
parent
40cb0e0746
commit
1d8a4838ac
@ -46,6 +46,7 @@ namespace MCGalaxy.Commands {
|
||||
if (Awards.GiveAward(plName, award)) {
|
||||
Chat.MessageAll("{0} %Swas awarded: &b{1}",
|
||||
PlayerInfo.GetColoredName(p, plName), award);
|
||||
Awards.SavePlayers();
|
||||
} else {
|
||||
Player.Message(p, "The player already has that award."); return;
|
||||
}
|
||||
@ -53,11 +54,11 @@ namespace MCGalaxy.Commands {
|
||||
if (Awards.TakeAward(plName, award)) {
|
||||
Chat.MessageAll("{0} %Shad their &b{1} %Saward removed",
|
||||
PlayerInfo.GetColoredName(p, plName), award);
|
||||
Awards.SavePlayers();
|
||||
} else {
|
||||
Player.Message(p, "The player didn't have the award you tried to take"); return;
|
||||
}
|
||||
}
|
||||
Awards.Save();
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -41,15 +41,16 @@ namespace MCGalaxy.Commands {
|
||||
Player.Message(p, "This award already exists."); return;
|
||||
} else {
|
||||
Chat.MessageAll("Award added: &6{0} : {1}", args[0], args[1]);
|
||||
Awards.SaveAwards();
|
||||
}
|
||||
} else {
|
||||
if (!Awards.Remove(args[1])) {
|
||||
Player.Message(p, "This award does not exist."); return;
|
||||
} else {
|
||||
Chat.MessageAll("Award removed: &6{0}", args[1]);
|
||||
Awards.SaveAwards();
|
||||
}
|
||||
}
|
||||
Awards.Save();
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
|
@ -54,7 +54,6 @@ namespace MCGalaxy {
|
||||
PropertiesFile.Read("text/awardsList.txt", AwardsListLineProcessor, ':');
|
||||
PlayerAwards = new List<PlayerAward>();
|
||||
PropertiesFile.Read("text/playerAwards.txt", PlayerAwardsLineProcessor, ':');
|
||||
Save();
|
||||
}
|
||||
|
||||
static void AwardsListLineProcessor(string key, string value) {
|
||||
@ -76,8 +75,11 @@ namespace MCGalaxy {
|
||||
PlayerAwards.Add(pl);
|
||||
}
|
||||
|
||||
public static void Save() {
|
||||
using (CP437Writer w = new CP437Writer("text/awardsList.txt")) {
|
||||
static readonly object awardLock = new object();
|
||||
public static void SaveAwards() {
|
||||
lock (awardLock)
|
||||
using (CP437Writer w = new CP437Writer("text/awardsList.txt"))
|
||||
{
|
||||
w.WriteLine("# This is a full list of awards. The server will load these and they can be awarded as you please");
|
||||
w.WriteLine("# Format is:");
|
||||
w.WriteLine("# AwardName : Description of award goes after the colon");
|
||||
@ -85,8 +87,13 @@ namespace MCGalaxy {
|
||||
foreach (Award award in AwardsList)
|
||||
w.WriteLine(award.Name + " : " + award.Description);
|
||||
}
|
||||
}
|
||||
|
||||
using (StreamWriter w = new StreamWriter("text/playerAwards.txt")) {
|
||||
static readonly object playerLock = new object();
|
||||
public static void SavePlayers() {
|
||||
lock (playerLock)
|
||||
using (StreamWriter w = new StreamWriter("text/playerAwards.txt"))
|
||||
{
|
||||
foreach (PlayerAward pA in PlayerAwards)
|
||||
w.WriteLine(pA.Name.ToLower() + " : " + pA.Awards.Join(","));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user