@@ -176,16 +176,29 @@ public void OnCommandTop(CCSPlayerController? player, CommandInfo info)
176176 printCount = Math . Clamp ( parsedInt , 1 , 25 ) ;
177177 }
178178
179+ Logger . LogInformation ( $ "Player { k4player . PlayerName } requested top { printCount } players.") ;
180+
179181 Task . Run ( async ( ) =>
180182 {
183+ Console . WriteLine ( "Saving all players data" ) ;
184+
181185 await plugin . SaveAllPlayersDataAsync ( ) ;
186+
187+ Console . WriteLine ( "Fetching top data" ) ;
188+
182189 List < ( int points , string name ) > ? rankData = await FetchTopDataAsync ( printCount ) ;
183190
191+ Console . WriteLine ( "Fetched top data, waiting tick to print to chat." ) ;
192+
184193 Server . NextFrame ( ( ) =>
185194 {
195+ Console . WriteLine ( "Printing top data to chat." ) ;
196+
186197 if ( ! k4player . IsValid || ! k4player . IsPlayer )
187198 return ;
188199
200+ Console . WriteLine ( "Player is valid and is player." ) ;
201+
189202 if ( rankData ? . Count > 0 )
190203 {
191204 for ( int i = 0 ; i < rankData . Count ; i ++ )
@@ -195,12 +208,12 @@ public void OnCommandTop(CCSPlayerController? player, CommandInfo info)
195208
196209 Rank rank = GetPlayerRank ( points ) ;
197210
198- k4player . Controller . PrintToChat ( $ " { plugin . Localizer [ "k4.ranks.top.line" , i + 1 , rank . Color , rank . Name , name , points ] } ") ;
211+ player ! . PrintToChat ( $ " { plugin . Localizer [ "k4.ranks.top.line" , i + 1 , rank . Color , rank . Name , name , points ] } ") ;
199212 }
200213 }
201214 else
202215 {
203- k4player . Controller . PrintToChat ( $ " { plugin . Localizer [ "k4.general.prefix" ] } { plugin . Localizer [ "k4.ranks.top.notfound" , printCount ] } ") ;
216+ player ! . PrintToChat ( $ " { plugin . Localizer [ "k4.general.prefix" ] } { plugin . Localizer [ "k4.ranks.top.notfound" , printCount ] } ") ;
204217 }
205218 } ) ;
206219 } ) ;
@@ -223,7 +236,7 @@ public void OnCommandTop(CCSPlayerController? player, CommandInfo info)
223236 }
224237 catch ( Exception ex )
225238 {
226- Logger . LogError ( $ "A problem occurred while fetching top data: { ex . Message } ") ;
239+ Server . NextFrame ( ( ) => { Logger . LogError ( $ "A problem occurred while fetching top data: { ex . Message } ") ; } ) ;
227240 return null ;
228241 }
229242 }
0 commit comments