aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-01-09 14:00:44 +0900
committersyeyoung <cyong06@naver.com>2021-01-09 14:00:44 +0900
commit3513364b2177cb88c57284c113b367000e93f2e5 (patch)
treedcfc0401cada0bfe319422fa3fe1c61493498777 /src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java
parentb382461db0b5fb96271bf548fa5aa89f0981ae05 (diff)
downloadSkyblock-Dungeons-Guide-3513364b2177cb88c57284c113b367000e93f2e5.tar.gz
Skyblock-Dungeons-Guide-3513364b2177cb88c57284c113b367000e93f2e5.tar.bz2
Skyblock-Dungeons-Guide-3513364b2177cb88c57284c113b367000e93f2e5.zip
what?
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java134
1 files changed, 45 insertions, 89 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java
index 1f7644bc..a1f1cbcb 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/utils/AhUtils.java
@@ -1,29 +1,24 @@
package kr.syeyoung.dungeonsguide.utils;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
+import java.security.*;
+import java.security.cert.CertificateException;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import kr.syeyoung.dungeonsguide.e;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.TreeSet;
-import net.minecraft.nbt.CompressedStreamTools;
-import net.minecraft.nbt.NBTTagCompound;
public class AhUtils {
public static volatile Map<String, AuctionData> auctions = new HashMap<String, AuctionData>();
- private static Map<String, AuctionData> semi_auctions = new HashMap<String, AuctionData>();
-
public static Timer timer = new Timer();
public static int totalAuctions = 0;
@@ -31,93 +26,55 @@ public class AhUtils {
public static void registerTimer() {
timer.schedule(new TimerTask() {
public void run() {
- AhUtils.loadAuctions();
+ try {
+ AhUtils.loadAuctions();
+ } catch (CertificateException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidAlgorithmParameterException e) {
+ e.printStackTrace();
+ } catch (NoSuchPaddingException e) {
+ e.printStackTrace();
+ } catch (BadPaddingException e) {
+ e.printStackTrace();
+ } catch (KeyStoreException e) {
+ e.printStackTrace();
+ } catch (IllegalBlockSizeException e) {
+ e.printStackTrace();
+ } catch (KeyManagementException e) {
+ e.printStackTrace();
+ }
}
}, 0L, 1800000L);
}
- public static void loadAuctions() {
+ public static void loadAuctions() throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, NoSuchPaddingException, BadPaddingException, KeyStoreException, IllegalBlockSizeException, KeyManagementException {
+ System.out.println("I think i'm loading ah");
try {
- int i = 0;
- do {
- } while (loadPage(i++));
- loadBazaar();
+ Map<String, AuctionData> semi_auctions = new HashMap<String, AuctionData>();
+ JsonElement object = e.getDungeonsGuide().getAuthenticator().d("https://dungeonsguide.kro.kr/resource/keys");
+ for (JsonElement element : object.getAsJsonArray()) {
+ JsonObject object1 = element.getAsJsonObject();
+ AuctionData auctionData = new AuctionData(object1.get("id").getAsString());
+ auctionData.lowestBin = object1.get("lowestBin").getAsInt();
+ auctionData.sellPrice = object1.get("sellPrice").getAsInt();
+ auctionData.buyPrice = object1.get("buyPrice").getAsInt();
+ semi_auctions.put(auctionData.id, auctionData);
+ }
auctions = semi_auctions;
- semi_auctions = new HashMap<String, AuctionData>();
- } catch (IOException e) {
+ } catch (Throwable e) {
e.printStackTrace();
}
}
- public static void loadBazaar() throws IOException {
- System.out.println("Fetching bazaar data");
- URL url = new URL("https://api.hypixel.net/skyblock/bazaar");
- InputStreamReader reader = new InputStreamReader(url.openStream());
- JsonObject object = (JsonObject)(new JsonParser()).parse(reader);
- boolean success = object.get("success").getAsBoolean();
- if (!success)
- return;
- JsonObject element = object.getAsJsonObject("products");
- for (Map.Entry<String, JsonElement> product : (Iterable<Map.Entry<String, JsonElement>>)element.entrySet()) {
- String id = product.getKey();
- AuctionData auctionData = semi_auctions.get(id);
- boolean notexisted = (auctionData == null);
- if (notexisted)
- auctionData = new AuctionData(id);
- auctionData.sellPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("sellPrice").getAsInt();
- auctionData.buyPrice = ((JsonElement)product.getValue()).getAsJsonObject().getAsJsonObject("quick_status").get("buyPrice").getAsInt();
- if (notexisted)
- semi_auctions.put(id, auctionData);
- }
- }
-
- public static boolean loadPage(int page) throws IOException {
- System.out.println("Fetching page " + page + " of auctions");
- URL url = new URL("https://api.hypixel.net/skyblock/auctions?page=" + page);
- InputStreamReader reader = new InputStreamReader(url.openStream());
- JsonObject object = (JsonObject)(new JsonParser()).parse(reader);
- boolean success = object.get("success").getAsBoolean();
- if (!success)
- return false;
- int maxPage = object.get("totalPages").getAsInt();
- int totalAuctions = object.get("totalAuctions").getAsInt();
- System.out.println("Fetched page " + page + "/" + maxPage + " of auctions! (" + totalAuctions + " total)");
- JsonArray array = object.get("auctions").getAsJsonArray();
- for (JsonElement element2 : array) {
- JsonObject element = element2.getAsJsonObject();
- JsonElement isBin = element.get("bin");
- if (isBin == null || !isBin.getAsBoolean())
- continue;
- byte[] itemData = Base64.decode(element.get("item_bytes").getAsString().replace("\\u003d", "="));
- NBTTagCompound nbtTagCompound = CompressedStreamTools.readCompressed(new ByteArrayInputStream(itemData));
- NBTTagCompound acutalItem = (NBTTagCompound)nbtTagCompound.getTagList("i", 10).get(0);
- NBTTagCompound attributes = acutalItem.getCompoundTag("tag").getCompoundTag("ExtraAttributes");
- String id = attributes.getString("id");
- if (id.equals("ENCHANTED_BOOK")) {
- NBTTagCompound enchants = attributes.getCompoundTag("enchantments");
- Set<String> keys = enchants.getKeySet();
- if (keys.size() != 1)
- continue;
- String ench = keys.iterator().next();
- int lv = enchants.getInteger(ench);
- id = id + "::" + ench + "-" + lv;
- }
- AuctionData auctionData = semi_auctions.get(id);
- boolean notexisted = (auctionData == null);
- if (notexisted)
- auctionData = new AuctionData(id);
- auctionData.prices.add(element.get("starting_bid").getAsInt());
- if (notexisted)
- semi_auctions.put(id, auctionData);
- }
- return (page < maxPage);
- }
-
public static class AuctionData {
public String id;
- public SortedSet<Integer> prices;
+ public int lowestBin = -1;
public int sellPrice = -1;
@@ -125,7 +82,6 @@ public class AhUtils {
public AuctionData(String id) {
this.id = id;
- this.prices = new TreeSet<Integer>();
}
}
} \ No newline at end of file