diff --git a/Commands/Economy/CmdAward.cs b/Commands/Economy/CmdAward.cs index 17bec40ad..21b57ea3f 100644 --- a/Commands/Economy/CmdAward.cs +++ b/Commands/Economy/CmdAward.cs @@ -45,19 +45,20 @@ namespace MCGalaxy.Commands { if (!take) { if (Awards.GiveAward(plName, award)) { Chat.MessageAll("{0} %Swas awarded: &b{1}", - PlayerInfo.GetColoredName(p, plName), award); + PlayerInfo.GetColoredName(p, plName), award); + Awards.SavePlayers(); } else { Player.Message(p, "The player already has that award."); return; } } else { if (Awards.TakeAward(plName, award)) { Chat.MessageAll("{0} %Shad their &b{1} %Saward removed", - PlayerInfo.GetColoredName(p, plName), award); + 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) { diff --git a/Commands/Economy/CmdAwardMod.cs b/Commands/Economy/CmdAwardMod.cs index e031df8e8..7aed7237c 100644 --- a/Commands/Economy/CmdAwardMod.cs +++ b/Commands/Economy/CmdAwardMod.cs @@ -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]); + Chat.MessageAll("Award removed: &6{0}", args[1]); + Awards.SaveAwards(); } } - Awards.Save(); } public override void Help(Player p) { diff --git a/Economy/Awards.cs b/Economy/Awards.cs index a5a621b64..0354af683 100644 --- a/Economy/Awards.cs +++ b/Economy/Awards.cs @@ -54,7 +54,6 @@ namespace MCGalaxy { PropertiesFile.Read("text/awardsList.txt", AwardsListLineProcessor, ':'); PlayerAwards = new List(); 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,10 +87,15 @@ 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(",")); + w.WriteLine(pA.Name.ToLower() + " : " + pA.Awards.Join(",")); } } #endregion @@ -107,7 +114,7 @@ namespace MCGalaxy { pl.Awards.Add(name); return true; } - + PlayerAward newPl; newPl.Name = playerName; newPl.Awards = new List();