Skip to content

Commit faa5a8d

Browse files
committed
Update
1 parent a6243dd commit faa5a8d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/LogCommands.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Essentials.Modules.LogCommands
3535
[ModuleInfo(
3636
Name = "LogCommands",
3737
Author = "Leonardosc",
38-
Version = "1.0.0",
38+
Version = "1.0.1",
3939
Flags = LoadFlags.AUTO_REGISTER_EVENTS
4040
)]
4141
public class LogCommands : EssModule
@@ -57,15 +57,17 @@ public string LogFolder
5757

5858
public override void OnLoad()
5959
{
60-
Logger.LogInfo("Enabled!");
60+
Logger.LogInfo( "Enabled!" );
6161
Instance = this;
6262
}
6363

64-
public override void OnUnload() {
65-
Logger.LogInfo("Disabled!");
64+
public override void OnUnload()
65+
{
66+
Logger.LogInfo( "Disabled!" );
67+
SaveCache();
6668
}
6769

68-
[SubscribeEvent(EventType.ESSENTIALS_COMMAND_POS_EXECUTED)]
70+
[SubscribeEvent( EventType.ESSENTIALS_COMMAND_POS_EXECUTED )]
6971
private void OnCommandExecuted( CommandPosExecuteEvent e )
7072
{
7173
if ( e.Source.IsConsole ) return;
@@ -91,27 +93,33 @@ private void OnCommandExecuted( CommandPosExecuteEvent e )
9193
.Append( ": " )
9294
.Append( $"\"/{e.Command.Name}" )
9395
.Append( e.Arguments.IsEmpty ? "\"" : $" {e.Arguments.Join(0)}\"" );
96+
9497
var text = sb.ToString();
9598

9699
if ( Cache.ContainsKey( playerId ) )
97100
Cache[playerId].Add( text );
98101
else
99102
Cache.Add( playerId, new List<string>{ text } );
103+
104+
#if DEBUG
105+
SaveCache();
106+
#endif
100107
}
101108

102109
private void SaveCache()
103110
{
104-
var contents = new Dictionary<ulong, List<String>>(Cache);
111+
var copyOfCache = new Dictionary<ulong, List<String>>(Cache);
105112
Cache.Clear();
106113

107114
new Thread(() => {
108115
var text = new StringBuilder();
109-
contents.ForEach((k) => {
116+
copyOfCache.ForEach((k) => {
110117
var playerFolder = Path.Combine(LogFolder, k.Key.ToString());
111-
var commandsFile = $"{playerFolder}commands.txt";
118+
var commandsFile = Path.Combine( playerFolder, "commands.txt" );
112119

113120
if ( !Directory.Exists( playerFolder ) )
114121
Directory.CreateDirectory( playerFolder );
122+
115123
if ( !File.Exists( commandsFile ) )
116124
File.Create( commandsFile ).Close();
117125

0 commit comments

Comments
 (0)