-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataLooper.java
48 lines (40 loc) · 1.97 KB
/
DataLooper.java
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
package src.ctt.GameMlemBot;
import src.ctt.GameMlemBot.Enums.TimeInterval;
import src.ctt.GameMlemBot.Logic.GameMlemBotManager.GameMlemGuildManager;
import src.ctt.GameMlemBot.Logic.Handler.GameMlem.QuickEventHandler.QuickEventHandler;
import src.ctt.GameMlemBot.Logic.Model.GameMlemData.GameMlemUserDataManager;
public class DataLooper {
public DataLooper() {
new Thread() {
@Override
public void run() {
long saveUserTimeReset = System.currentTimeMillis();
long saveGuildTimeReset = System.currentTimeMillis();
long spawnQuickEventReset = System.currentTimeMillis();
QuickEventHandler quickEventHandler = new QuickEventHandler();
while (true) {
try {
sleep(TimeInterval.TIME_CHECK_INTERVAL_10.getValue());
} catch (Exception ex) {
ex.printStackTrace();
}
if (saveUserTimeReset + TimeInterval.TIME_CHECK_INTERVAL_10.getValue() < System
.currentTimeMillis()) {
saveUserTimeReset = System.currentTimeMillis();
new GameMlemUserDataManager().saveUsersAndRemoveFromCache();
}
if (saveGuildTimeReset + TimeInterval.TIME_CHECK_INTERVAL_10.getValue() < System
.currentTimeMillis()) {
saveGuildTimeReset = System.currentTimeMillis();
new GameMlemGuildManager().saveGuildsAndRemoveFromCache();
}
if (spawnQuickEventReset + TimeInterval.TIME_CHECK_INTERVAL_100.getValue() < System
.currentTimeMillis()) {
spawnQuickEventReset = System.currentTimeMillis();
quickEventHandler.spawnEvent();
}
}
}
}.start();
}
}