diff options
| author | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-26 12:12:25 +1000 |
|---|---|---|
| committer | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-26 12:12:25 +1000 |
| commit | f0293a74282cece3aa8a2a328559889d6e187209 (patch) | |
| tree | e4bb3d101b8b7e70a58f521a41a44071bb6cc0fa /src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java | |
| parent | 16b89f752b83aa91f1697238d785eb97a4f01f61 (diff) | |
| download | notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.tar.gz notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.tar.bz2 notenoughupdates-f0293a74282cece3aa8a2a328559889d6e187209.zip | |
1.11.7
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index b879c383..680094af 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -23,6 +23,8 @@ import java.io.*; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -226,24 +228,29 @@ public class NEUManager { /** * Downloads and sets auctionPricesJson from the URL specified by AUCTIONS_PRICE_URL. */ + private ExecutorService es = Executors.newCachedThreadPool(); public void updatePrices() { if(System.currentTimeMillis() - auctionLastUpdate > 1000*60*120) { //2 hours craftCost.clear(); System.out.println("[NEU] UPDATING PRICE INFORMATION"); auctionLastUpdate = System.currentTimeMillis(); - try(Reader inReader = new InputStreamReader(new GZIPInputStream(new URL(AUCTIONS_PRICE_URL).openStream()))) { - auctionPricesJson = gson.fromJson(inReader, JsonObject.class); - } catch (IOException e) { - e.printStackTrace(); - } + es.submit(() -> { + try(Reader inReader = new InputStreamReader(new GZIPInputStream(new URL(AUCTIONS_PRICE_URL).openStream()))) { + auctionPricesJson = gson.fromJson(inReader, JsonObject.class); + } catch (IOException e) { + e.printStackTrace(); + } + }); } } public boolean hasAuctionInfo(String internalname) { + if(auctionPricesJson == null) return false; return auctionPricesJson.has("item_data") && auctionPricesJson.get("item_data").getAsJsonObject().has(internalname); } public boolean hasBazaarInfo(String internalname) { + if(auctionPricesJson == null) return false; return auctionPricesJson.has("bazaar") && auctionPricesJson.get("bazaar").getAsJsonObject().has(internalname); } @@ -276,7 +283,7 @@ public class NEUManager { if(info == null || !info.has("price")) { return 0; } - if(!auctionPricesJson.has("ench_prices") || !auctionPricesJson.has("ench_maximums")) { + if(auctionPricesJson == null || !auctionPricesJson.has("ench_prices") || !auctionPricesJson.has("ench_maximums")) { return 0; } JsonObject ench_prices = auctionPricesJson.getAsJsonObject("ench_prices"); |
