ExpeditionManager.java 1.96 KB
Newer Older
Kinesis's avatar
Kinesis committed
1
2
3
4
package emu.grasscutter.game.expedition;

import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter;
5
import emu.grasscutter.data.DataLoader;
Kinesis's avatar
Kinesis committed
6
7
8
9
10
import emu.grasscutter.server.game.GameServer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

import java.io.FileReader;
11
12
import java.io.InputStreamReader;
import java.io.Reader;
Kinesis's avatar
Kinesis committed
13
14
15
import java.util.Collection;
import java.util.List;

16
17
import static emu.grasscutter.Configuration.*;

Kinesis's avatar
Kinesis committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class ExpeditionManager {
    public GameServer getGameServer() {
        return gameServer;
    }

    private final GameServer gameServer;

    public Int2ObjectMap<List<ExpeditionRewardDataList>> getExpeditionRewardDataList() { return expeditionRewardData; }

    private final Int2ObjectMap<List<ExpeditionRewardDataList>> expeditionRewardData;

    public ExpeditionManager(GameServer gameServer) {
        this.gameServer = gameServer;
        this.expeditionRewardData = new Int2ObjectOpenHashMap<>();
        this.load();
    }

    public synchronized void load() {
36
        try (Reader fileReader = new InputStreamReader(DataLoader.load("ExpeditionReward.json"))) {
Kinesis's avatar
Kinesis committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
            getExpeditionRewardDataList().clear();
            List<ExpeditionRewardInfo> banners = Grasscutter.getGsonFactory().fromJson(fileReader, TypeToken.getParameterized(Collection.class, ExpeditionRewardInfo.class).getType());
            if(banners.size() > 0) {
                for (ExpeditionRewardInfo di : banners) {
                    getExpeditionRewardDataList().put(di.getExpId(), di.getExpeditionRewardDataList());
                }
                Grasscutter.getLogger().info("Expedition reward successfully loaded.");
            } else {
                Grasscutter.getLogger().error("Unable to load expedition reward. Expedition reward size is 0.");
            }
        } catch (Exception e) {
            Grasscutter.getLogger().error("Unable to load expedition reward.", e);
        }
    }
}