mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Merge branch 'explosivegaming:main' into aperx
This commit is contained in:
@@ -6,29 +6,42 @@ export class InstancePlugin extends BaseInstancePlugin {
|
|||||||
private gameTimes: number[] = [];
|
private gameTimes: number[] = [];
|
||||||
|
|
||||||
async onStart() {
|
async onStart() {
|
||||||
this.updateInterval = setInterval(this.updateUps.bind(this), this.instance.config.get("exp_server_ups.update_interval"));
|
if (!this.instance.config.get("factorio.settings")["auto_pause"]) {
|
||||||
|
this.setInterval();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onExit() {
|
onExit() {
|
||||||
if (this.updateInterval) {
|
this.clearInterval();
|
||||||
clearInterval(this.updateInterval);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async onInstanceConfigFieldChanged(field: string, curr: unknown): Promise<void> {
|
async onInstanceConfigFieldChanged(field: string, curr: unknown): Promise<void> {
|
||||||
if (field === "exp_server_ups.update_interval") {
|
if (field === "exp_server_ups.update_interval") {
|
||||||
this.onExit();
|
this.clearInterval();
|
||||||
await this.onStart();
|
this.setInterval();
|
||||||
} else if (field === "exp_server_ups.average_interval") {
|
} else if (field === "exp_server_ups.average_interval") {
|
||||||
this.gameTimes.splice(curr as number);
|
this.gameTimes.splice(curr as number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async onPlayerEvent(event: lib.PlayerEvent): Promise<void> {
|
async onPlayerEvent(event: lib.PlayerEvent): Promise<void> {
|
||||||
if (event.type === "join" && !this.updateInterval) {
|
if (event.type === "join") {
|
||||||
await this.onStart();
|
this.setInterval();
|
||||||
} else if (event.type === "leave" && this.instance.playersOnline.size == 0 && this.instance.config.get("factorio.settings")["auto_pause"] as boolean) {
|
} else if (event.type === "leave" && this.instance.playersOnline.size == 0 && this.instance.config.get("factorio.settings")["auto_pause"]) {
|
||||||
this.onExit();
|
this.clearInterval();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval() {
|
||||||
|
if (!this.updateInterval) {
|
||||||
|
this.updateInterval = setInterval(this.updateUps.bind(this), this.instance.config.get("exp_server_ups.update_interval"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clearInterval() {
|
||||||
|
if (this.updateInterval) {
|
||||||
|
clearInterval(this.updateInterval);
|
||||||
|
this.updateInterval = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user