-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
70 lines (55 loc) · 2.14 KB
/
Plugin.cs
File metadata and controls
70 lines (55 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Server;
public class Plugin : Plugin<Config>
{
public static Plugin? Instance;
private HttpServer? server;
public override string Name => "SLDataAPI";
public override string Author => "DNT_OF";
public override Version Version => new Version(1, 5, 0);
public override void OnEnabled()
{
base.OnEnabled();
Instance = this;
Exiled.Events.Handlers.Server.WaitingForPlayers += OnWaitingForPlayers;
Exiled.Events.Handlers.Server.RoundStarted += OnRoundStarted;
Exiled.Events.Handlers.Server.RoundEnded += OnRoundEnded;
server = new HttpServer(Config.HttpPort, Config.VerifyToken);
server.Start();
// ★ 修复:插件启用时立即采集一次真实数据,并启动定时循环
// 不再依赖 RoundStarted 事件触发——加载时若回合已在进行中同样能正常工作
DataCollector.IsRoundActive = Round.IsStarted;
DataCollector.InitData(Config.PushIntervalSeconds);
Log.Info($"SLDataAPI v{Version} enabled. HTTP on port {Config.HttpPort}.");
}
public override void OnDisabled()
{
base.OnDisabled();
Exiled.Events.Handlers.Server.WaitingForPlayers -= OnWaitingForPlayers;
Exiled.Events.Handlers.Server.RoundStarted -= OnRoundStarted;
Exiled.Events.Handlers.Server.RoundEnded -= OnRoundEnded;
server?.Stop();
DataCollector.StopTimer();
Instance = null;
}
// ★ 新增:等待玩家阶段也更新数据(大厅状态)
private void OnWaitingForPlayers()
{
DataCollector.IsRoundActive = false;
DataCollector.UpdateDataNow();
Log.Info("SLDataAPI: Waiting for players.");
}
private void OnRoundStarted()
{
DataCollector.IsRoundActive = true;
DataCollector.UpdateDataNow();
Log.Info("SLDataAPI: Round started.");
}
private void OnRoundEnded(RoundEndedEventArgs ev)
{
DataCollector.IsRoundActive = false;
DataCollector.UpdateDataNow();
Log.Info("SLDataAPI: Round ended.");
}
}