aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
diff options
context:
space:
mode:
authorMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-29 12:21:03 +1000
committerMoulberry <james.jenour@student.scotch.wa.edu.au>2020-07-29 12:21:03 +1000
commit6115246bf36fb98037ca0df2faac869eba7845c3 (patch)
tree4e659cf3d0bae323346ef251c995179c490c1115 /src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
parent9716e11a253a370e16dd1f0bdfdd70ac21ee4102 (diff)
downloadnotenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.tar.gz
notenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.tar.bz2
notenoughupdates-6115246bf36fb98037ca0df2faac869eba7845c3.zip
1.11.10.5
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java71
1 files changed, 39 insertions, 32 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
index 07c21304..ea6d2f9f 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java
@@ -19,6 +19,8 @@ import net.minecraft.util.EnumChatFormatting;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class APIManager {
@@ -142,23 +144,25 @@ public class APIManager {
}
public void tick() {
+ if(manager.config.disableAH.value || manager.config.apiKey.value == null || manager.config.apiKey.value.isEmpty()) return;
+
customAH.tick();
long currentTime = System.currentTimeMillis();
if(currentTime - lastPageUpdate > 5*1000) {
- lastPageUpdate = System.currentTimeMillis();
+ lastPageUpdate = currentTime;
updatePageTick();
ahNotification();
}
- if(currentTime - lastProfileUpdate > 10*1000) {
+ /*if(currentTime - lastProfileUpdate > 10*1000) {
lastProfileUpdate = System.currentTimeMillis();
updateProfiles(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""));
- }
+ }*/
if(currentTime - lastCleanup > 120*1000) {
- lastCleanup = System.currentTimeMillis();
+ lastCleanup = currentTime;
cleanup();
}
if(currentTime - lastCustomAHSearch > 60*1000) {
- lastCustomAHSearch = System.currentTimeMillis();
+ lastCustomAHSearch = currentTime;
if(Minecraft.getMinecraft().currentScreen instanceof CustomAHGui || customAH.isRenderOverAuctionView()) {
customAH.updateSearch();
calculateStats();
@@ -263,38 +267,41 @@ public class APIManager {
}
}
+ private ExecutorService es = Executors.newSingleThreadExecutor();
private void cleanup() {
- try {
- long currTime = System.currentTimeMillis();
- Set<String> toRemove = new HashSet<>();
- for(Map.Entry<String, Auction> entry : auctionMap.entrySet()) {
- long timeToEnd = entry.getValue().end - currTime;
- if(timeToEnd < -60) {
- toRemove.add(entry.getKey());
- } else if(currTime - entry.getValue().lastUpdate > 5*60*1000) {
- toRemove.add(entry.getKey());
+ es.submit(() -> {
+ try {
+ long currTime = System.currentTimeMillis();
+ Set<String> toRemove = new HashSet<>();
+ for(Map.Entry<String, Auction> entry : auctionMap.entrySet()) {
+ long timeToEnd = entry.getValue().end - currTime;
+ if(timeToEnd < -60) {
+ toRemove.add(entry.getKey());
+ } else if(currTime - entry.getValue().lastUpdate > 5*60*1000) {
+ toRemove.add(entry.getKey());
+ }
}
- }
- toRemove.removeAll(playerBids);
- for(String aucid : toRemove) {
- auctionMap.remove(aucid);
- }
- for(HashMap<Integer, HashSet<String>> extrasMap : extrasToAucIdMap.values()) {
- for(HashSet<String> aucids : extrasMap.values()) {
- for(String aucid : toRemove) {
- aucids.remove(aucid);
+ toRemove.removeAll(playerBids);
+ for(String aucid : toRemove) {
+ auctionMap.remove(aucid);
+ }
+ for(HashMap<Integer, HashSet<String>> extrasMap : extrasToAucIdMap.values()) {
+ for(HashSet<String> aucids : extrasMap.values()) {
+ for(String aucid : toRemove) {
+ aucids.remove(aucid);
+ }
}
}
+ for(HashSet<String> aucids : internalnameToAucIdMap.values()) {
+ aucids.removeAll(toRemove);
+ }
+ for(TreeMap<Integer, String> lowestBINs : internalnameToLowestBIN.values()) {
+ lowestBINs.values().removeAll(toRemove);
+ }
+ } catch(ConcurrentModificationException e) {
+ lastCleanup = System.currentTimeMillis() - 110*1000;
}
- for(HashSet<String> aucids : internalnameToAucIdMap.values()) {
- aucids.removeAll(toRemove);
- }
- for(TreeMap<Integer, String> lowestBINs : internalnameToLowestBIN.values()) {
- lowestBINs.values().removeAll(toRemove);
- }
- } catch(ConcurrentModificationException e) {
- cleanup();
- }
+ });
}
private void updatePageTick() {