aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorDoKM <mcazzyman@gmail.com>2021-07-31 16:17:55 +0200
committerDoKM <mcazzyman@gmail.com>2021-07-31 16:17:55 +0200
commitd81917266f02e43837ac98e99c867c9766b897d4 (patch)
treee6b49f1ec0dc10c51d12b4ff1c71c4cc734d6891 /src/main/java/io
parent804b6cfd14c85014a8e233b570fe4e758a7d260d (diff)
downloadNotEnoughUpdates-d81917266f02e43837ac98e99c867c9766b897d4.tar.gz
NotEnoughUpdates-d81917266f02e43837ac98e99c867c9766b897d4.tar.bz2
NotEnoughUpdates-d81917266f02e43837ac98e99c867c9766b897d4.zip
Add Join date, Last saved and guild to pv
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java66
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java35
2 files changed, 101 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
index d59bb5d8..4eb1858a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
@@ -45,6 +45,10 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.NumberFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -141,6 +145,10 @@ public class GuiProfileViewer extends GuiScreen {
if(profileId == null && profile != null && profile.getLatestProfile() != null) {
profileId = profile.getLatestProfile();
}
+ {
+ //this is just to cache the guild info
+ JsonObject guildinfo = profile.getGuildInfo(null);
+ }
this.sizeX = 431;
this.sizeY = 202;
@@ -2198,6 +2206,37 @@ public class GuiProfileViewer extends GuiScreen {
Utils.renderAlignedString(EnumChatFormatting.GOLD+"Purse", EnumChatFormatting.WHITE.toString()+shortNumberFormat(purseBalance, 0),
guiLeft+xStart, guiTop+yStartTop+yOffset, 76);
+ {
+ String lastSaveText = this.getTimeSinceString(profileInfo, "last_save");
+ if(lastSaveText != null) {
+ Utils.renderAlignedString(EnumChatFormatting.AQUA + "Last Saved", EnumChatFormatting.WHITE.toString() + lastSaveText,
+ guiLeft + xStart, guiTop + yStartTop + yOffset * 2, 76);
+ }
+
+ }
+ {
+ String first_join = this.getTimeSinceString(profileInfo, "first_join");
+ if(first_join != null) {
+ Utils.renderAlignedString(EnumChatFormatting.AQUA + "Joined", EnumChatFormatting.WHITE.toString() + first_join,
+ guiLeft + xStart, guiTop + yStartTop + yOffset * 3, 76);
+ }
+
+ }
+ {
+ String first_join = this.getTimeSinceString(profileInfo, "first_join");
+ if(first_join != null) {
+ Utils.renderAlignedString(EnumChatFormatting.AQUA + "Joined", EnumChatFormatting.WHITE.toString() + first_join,
+ guiLeft + xStart, guiTop + yStartTop + yOffset * 3, 76);
+ }
+
+ }
+ {
+ JsonObject guildInfo = profile.getGuildInfo(null);
+ if(guildInfo != null && guildInfo.has("name")){
+ Utils.renderAlignedString(EnumChatFormatting.AQUA + "Guild", EnumChatFormatting.WHITE.toString() + guildInfo.get("name").getAsString(),
+ guiLeft + xStart, guiTop + yStartTop + yOffset * 4, 76);
+ }
+ }
float fairySouls = Utils.getElementAsFloat(Utils.getElement(profileInfo, "fairy_souls_collected"), 0);
@@ -2379,6 +2418,33 @@ public class GuiProfileViewer extends GuiScreen {
}
}
+ private String getTimeSinceString(JsonObject profileInfo, String path){
+ JsonElement lastSaveElement = Utils.getElement(profileInfo, path);
+
+ if (lastSaveElement.isJsonPrimitive()) {
+
+ Instant lastSave = Instant.ofEpochMilli(lastSaveElement.getAsLong());
+ LocalDateTime lastSaveTime = LocalDateTime.ofInstant(lastSave,TimeZone.getDefault().toZoneId());
+ long timeDiff = System.currentTimeMillis() - lastSave.toEpochMilli();
+ LocalDateTime sinceOnline= LocalDateTime.ofInstant(Instant.ofEpochMilli(timeDiff), ZoneId.of("UTC"));
+ String renderText;
+
+ if(timeDiff < 60000L){
+ renderText = sinceOnline.getSecond()+" seconds ago.";
+ } else if(timeDiff < 3600000L){
+ renderText = sinceOnline.getMinute()+" minutes ago.";
+ } else if(timeDiff < 86400000L){
+ renderText = sinceOnline.getHour()+" hours ago.";
+ } else if(timeDiff < 31556952000L){
+ renderText = sinceOnline.getDayOfYear()+" days ago.";
+ } else {
+ renderText = lastSaveTime.format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
+ }
+ return renderText;
+ }
+ return null;
+ }
+
private int backgroundClickedX = -1;
private static char[] c = new char[]{'k', 'm', 'b', 't'};
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
index 9553659d..371e9ef3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java
@@ -310,6 +310,7 @@ public class ProfileViewer {
private String latestProfile = null;
private JsonArray playerInformation = null;
+ private JsonObject guildInformation = null;
private JsonObject basicInfo = null;
private final HashMap<String, JsonObject> profileMap = new HashMap<>();
@@ -331,6 +332,9 @@ public class ProfileViewer {
private AtomicBoolean updatingPlayerInfoState = new AtomicBoolean(false);
private long lastPlayerInfoState = 0;
private AtomicBoolean updatingPlayerStatusState = new AtomicBoolean(false);
+ private AtomicBoolean updatingGuildInfoState = new AtomicBoolean(false);
+ private long lastGuildInfoState = 0;
+ private AtomicBoolean updatingGuildStatusState = new AtomicBoolean(false);
public JsonObject getPlayerStatus() {
if(playerStatus != null) return playerStatus;
@@ -523,6 +527,7 @@ public class ProfileViewer {
}
}
+
String cute_name = profile.get("cute_name").getAsString();
if (backup == null) backup = cute_name;
profileIds.add(cute_name);
@@ -544,6 +549,35 @@ public class ProfileViewer {
}
);
+ return null;
+ }
+ public JsonObject getGuildInfo(Runnable runnable) {
+ if (guildInformation != null) return guildInformation;
+
+ long currentTime = System.currentTimeMillis();
+
+ if (currentTime - lastGuildInfoState < 15*1000 && updatingGuildInfoState.get()) return null;
+
+ lastGuildInfoState = currentTime;
+ updatingGuildInfoState.set(true);
+
+ HashMap<String, String> args = new HashMap<>();
+ args.put("player", "" + uuid);
+ manager.hypixelApi.getHypixelApiAsync(NotEnoughUpdates.INSTANCE.config.apiKey.apiKey, "guild",
+ args, jsonObject -> {
+ updatingGuildInfoState.set(false);
+
+ if (jsonObject == null) return;
+ if (jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) {
+ guildInformation = jsonObject.get("guild").getAsJsonObject();
+ if (guildInformation == null) return;
+ if (runnable != null) runnable.run();
+ }
+ }, () -> {
+ updatingGuildInfoState.set(false);
+ }
+ );
+
return null;
}
@@ -615,6 +649,7 @@ public class ProfileViewer {
public void resetCache() {
playerInformation = null;
+ guildInformation = null;
basicInfo = null;
playerStatus = null;
stats.clear();