File tree Expand file tree Collapse file tree 1 file changed +23
-10
lines changed
Expand file tree Collapse file tree 1 file changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -6,29 +6,42 @@ export class InstancePlugin extends BaseInstancePlugin {
66 private gameTimes : number [ ] = [ ] ;
77
88 async onStart ( ) {
9- this . updateInterval = setInterval ( this . updateUps . bind ( this ) , this . instance . config . get ( "exp_server_ups.update_interval" ) ) ;
9+ if ( ! this . instance . config . get ( "factorio.settings" ) [ "auto_pause" ] ) {
10+ this . setInterval ( ) ;
11+ }
1012 }
1113
1214 onExit ( ) {
13- if ( this . updateInterval ) {
14- clearInterval ( this . updateInterval ) ;
15- }
15+ this . clearInterval ( ) ;
1616 }
1717
1818 async onInstanceConfigFieldChanged ( field : string , curr : unknown ) : Promise < void > {
1919 if ( field === "exp_server_ups.update_interval" ) {
20- this . onExit ( ) ;
21- await this . onStart ( ) ;
20+ this . clearInterval ( ) ;
21+ this . setInterval ( ) ;
2222 } else if ( field === "exp_server_ups.average_interval" ) {
2323 this . gameTimes . splice ( curr as number ) ;
2424 }
2525 }
2626
2727 async onPlayerEvent ( event : lib . PlayerEvent ) : Promise < void > {
28- if ( event . type === "join" && ! this . updateInterval ) {
29- await this . onStart ( ) ;
30- } else if ( event . type === "leave" && this . instance . playersOnline . size == 0 && this . instance . config . get ( "factorio.settings" ) [ "auto_pause" ] as boolean ) {
31- this . onExit ( ) ;
28+ if ( event . type === "join" ) {
29+ this . setInterval ( ) ;
30+ } else if ( event . type === "leave" && this . instance . playersOnline . size == 0 && this . instance . config . get ( "factorio.settings" ) [ "auto_pause" ] ) {
31+ this . clearInterval ( ) ;
32+ }
33+ }
34+
35+ setInterval ( ) {
36+ if ( ! this . updateInterval ) {
37+ this . updateInterval = setInterval ( this . updateUps . bind ( this ) , this . instance . config . get ( "exp_server_ups.update_interval" ) ) ;
38+ }
39+ }
40+
41+ clearInterval ( ) {
42+ if ( this . updateInterval ) {
43+ clearInterval ( this . updateInterval ) ;
44+ this . updateInterval = undefined ;
3245 }
3346 }
3447
You can’t perform that action at this time.
0 commit comments