Search in sources :

Example 1 with AstralSorcery

use of hellfirepvp.astralsorcery.AstralSorcery in project AstralSorcery by HellFirePvP.

the class PatreonDataManager method loadPatreonEffects.

public static void loadPatreonEffects() {
    Thread tr = new Thread(() -> {
        URLConnection conn;
        try {
            conn = new URL(PATREON_EFFECT_URL).openConnection();
        } catch (IOException e) {
            AstralSorcery.log.error("Failed to connect to patreon fileserver! Not loading patreon files...");
            e.printStackTrace();
            PatreonEffectHelper.loadingFinished = true;
            return;
        }
        PatreonData data;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
            data = GSON.fromJson(br, PatreonData.class);
        } catch (IOException e) {
            AstralSorcery.log.error("Failed to connect to patreon fileserver! Not loading patreon files...");
            e.printStackTrace();
            PatreonEffectHelper.loadingFinished = true;
            return;
        }
        int skipped = 0;
        for (PatreonData.EffectEntry entry : data.getEffectList()) {
            UUID plUuid;
            PatreonEffectType type;
            try {
                plUuid = UUID.fromString(entry.getUuid());
                type = PatreonEffectType.valueOf(entry.getEffectClass());
            } catch (Exception exc) {
                skipped++;
                continue;
            }
            try {
                PatreonEffect pe = type.getProvider().buildEffect(plUuid, entry.getParameters());
                pe.initialize();
                pe.attachEventListeners(MinecraftForge.EVENT_BUS);
                pe.attachTickListeners(AstralSorcery.getProxy().getTickManager()::register);
                PatreonEffectHelper.playerEffectMap.computeIfAbsent(plUuid, uuid -> new ArrayList<>()).add(pe);
                PatreonEffectHelper.effectMap.put(pe.getEffectUUID(), pe);
            } catch (Exception exc) {
                skipped++;
            }
        }
        if (skipped > 0) {
            AstralSorcery.log.warn("Skipped " + skipped + " patreon effects during loading due to malformed data!");
        }
        AstralSorcery.log.info("Patreon effect loading finished.");
        UUID hellfire = UUID.fromString("7f6971c5-fb58-4519-a975-b1b5766e92d1");
        try {
        /*PatreonEffect effect = PatreonEffectType.STAR_HALO.getProvider().buildEffect(hellfire,
                        Arrays.asList("777971c5-fb58-4519-a975-b1b5766e44d1",
                                "null"));
                effect.initialize();
                effect.attachEventListeners(MinecraftForge.EVENT_BUS);
                effect.attachTickListeners(AstralSorcery.getProxy().getTickManager()::register);
                PatreonEffectHelper.playerEffectMap.computeIfAbsent(hellfire, uuid -> new ArrayList<>()).add(effect);
                PatreonEffectHelper.effectMap.put(effect.getEffectUUID(), effect);*/
        } catch (Exception e) {
            e.printStackTrace();
        }
        PatreonEffectHelper.loadingFinished = true;
    });
    tr.setName("AstralSorcery Patreon Effect Loader");
    tr.start();
}
Also used : MinecraftForge(net.minecraftforge.common.MinecraftForge) Gson(com.google.gson.Gson) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) URL(java.net.URL) URLConnection(java.net.URLConnection) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) UUID(java.util.UUID)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 MinecraftForge (net.minecraftforge.common.MinecraftForge)1