/* * Copyright (c) 2018 univento.eu - All rights reserved * You are not allowed to use, distribute or modify this code */ package eu.univento.core.api.items; import eu.univento.core.Core; import io.vertx.core.json.JsonObject; import io.vertx.ext.web.client.WebClient; import lombok.Getter; import java.util.HashMap; public class HeadDB { @Getter private HashMap blocks = new HashMap<>(); @Getter private HashMap food = new HashMap<>(); @Getter private HashMap electronics = new HashMap<>(); @Getter private HashMap characters = new HashMap<>(); @Getter private HashMap flags = new HashMap<>(); @Getter private HashMap letters = new HashMap<>(); @Getter private HashMap halloween = new HashMap<>(); @Getter private HashMap christmas = new HashMap<>(); public HeadDB() { get("blocks", blocks); get("food", food); get("electronics", electronics); get("characters", characters); get("flags", flags); get("letters", letters); get("halloween", halloween); get("christmas", christmas); } private void get(String name, HashMap map) { WebClient.create(Core.getCommons().getVertx()).get(443, "headdb.com", "/api/category/" + name).ssl(true).send(event -> { if (event.failed()) event.cause().printStackTrace(); event.result().bodyAsJsonObject().forEach(stringObjectEntry -> { JsonObject json = new JsonObject(stringObjectEntry.getValue().toString()); map.put(json.getString("name"), json.getJsonObject("valueDecoded").getJsonObject("textures").getJsonObject("SKIN").getString("url")); }); }); } }