This repository was archived by the owner on Nov 13, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export default class RefreshPlayer implements ILifeCycleTask {
2727 public status : number = 0 ;
2828
2929 private task : any = null ;
30+ private playersChartTask : any = null ;
3031 private playersChart : Array < { value : string } > = [ ] ;
3132
3233 async start ( instance : Instance ) {
@@ -62,13 +63,28 @@ export default class RefreshPlayer implements ILifeCycleTask {
6263 }
6364 } catch ( error ) { }
6465 } , 3000 ) ;
66+
67+ this . playersChartTask = setInterval ( async ( ) => {
68+ try {
69+ const result = await instance . execPreset ( "getPlayer" ) ;
70+ if ( ! result ) return ;
71+ this . playersChart . push ( {
72+ value : result . current_players ? result . current_players : 0
73+ } ) ;
74+ if ( this . playersChart . length > 60 ) {
75+ this . playersChart = this . playersChart . slice ( 1 , this . playersChart . length ) ;
76+ }
77+ instance . info . playersChart = this . playersChart ;
78+ } catch ( error ) { }
79+ } , 600000 ) ;
6580 }
6681
6782 async stop ( instance : Instance ) {
83+ clearInterval ( this . task ) ;
84+ clearInterval ( this . playersChartTask ) ;
6885 instance . info . maxPlayers = - 1 ;
6986 instance . info . currentPlayers = - 1 ;
7087 instance . info . version = "" ;
7188 instance . info . playersChart = [ ] ;
72- clearInterval ( this . task ) ;
7389 }
7490}
You can’t perform that action at this time.
0 commit comments