From dd91ed7db4a4323126a04ac88bd8a4c6d6c9c82d Mon Sep 17 00:00:00 2001 From: Vixid <52578495+Vixid1@users.noreply.github.com> Date: Mon, 12 Dec 2022 17:29:58 +0000 Subject: Added Highest Wave completed to Kuudra stats in pv (#489) --- .../profileviewer/CrimsonIslePage.java | 35 ++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java index f9d91935..87548f5e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java @@ -32,6 +32,7 @@ import org.lwjgl.opengl.GL11; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.LinkedHashMap; @@ -129,7 +130,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { drawDojoStats(netherIslandPlayerData, guiLeft, guiTop); // Kuudra stats - drawKuudraStats(netherIslandPlayerData, guiLeft, guiTop); + drawKuudraStats(netherIslandPlayerData, guiLeft, guiTop, mouseX, mouseY); // Last matriarch attempt drawLastMatriarchAttempt(netherIslandPlayerData, guiLeft, guiTop); @@ -138,7 +139,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { drawFactionReputation(netherIslandPlayerData, guiLeft, guiTop); } - public void drawKuudraStats(JsonObject data, int guiLeft, int guiTop) { + public void drawKuudraStats(JsonObject data, int guiLeft, int guiTop, int mouseX, int mouseY) { Utils.drawStringCentered( EnumChatFormatting.RED + "Kuudra Stats", Minecraft.getMinecraft().fontRendererObj, @@ -161,26 +162,48 @@ public class CrimsonIslePage extends GuiProfileViewerPage { int completions = kuudraCompletedTiers.has(kuudraTiers[i]) ? kuudraCompletedTiers.get(kuudraTiers[i]).getAsInt() : 0; + // Get the highest wave for this tier of kuudra if they have completed a run + // since infernal kuudra was released + int highestWaveCompleted = kuudraCompletedTiers.has("highest_wave_" + kuudraTiers[i]) ? + kuudraCompletedTiers.get("highest_wave_" + kuudraTiers[i]).getAsInt() : 0; + Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI( KUUDRA_KEYS[i], guiLeft + 8, - guiTop + 25 + (i * 12) + guiTop + 30 + (i * 30) ); Utils.renderAlignedString( EnumChatFormatting.RED + KUUDRA_TIERS[i] + ": ", EnumChatFormatting.WHITE + String.valueOf(completions), guiLeft + 23, - guiTop + 30 + (i * 12), + guiTop + 30 + (i * 30), + 110 + ); + + Utils.renderAlignedString( + EnumChatFormatting.RED + "Highest Wave: ", + EnumChatFormatting.WHITE + (highestWaveCompleted != 0 ? String.valueOf(highestWaveCompleted) : "N/A"), + guiLeft + 23, + guiTop + 42 + (i * 30), 110 ); + + if (highestWaveCompleted == 0) { + if (mouseX > guiLeft + 23 && mouseX < guiLeft + 133 && mouseY < guiTop + 50 + (i*30) && mouseY > guiTop + 42 + (i*30)) { + getInstance().tooltipToDisplay = new ArrayList<>(); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "N/A will only show for highest wave"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "if you have not completed a run for"); + getInstance().tooltipToDisplay.add(EnumChatFormatting.RED + "this tier since Infernal tier was released."); + } + } } Utils.renderAlignedString( - EnumChatFormatting.RED + "Total: ", + EnumChatFormatting.RED + "Total runs: ", EnumChatFormatting.WHITE + String.valueOf(getTotalKuudraRuns(kuudraCompletedTiers)), guiLeft + 23, - guiTop + 40 + (5 * 12), + guiTop + 30 + (5 * 30), 110 ); } -- cgit From 21fa3b25bd2956e5fec89c508bf8ed61fc5cdc06 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Wed, 14 Dec 2022 07:13:22 +1100 Subject: Fix open in skycrypt button not working on linux with some jdks (#490) --- .../commands/help/FeaturesCommand.java | 17 +++++---------- .../notenoughupdates/options/NEUConfigEditor.java | 7 +----- .../profileviewer/GuiProfileViewer.java | 25 +++++----------------- .../moulberry/notenoughupdates/util/Utils.java | 20 +++++++++++++++++ 4 files changed, 31 insertions(+), 38 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java index bc389ad4..bbabc172 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.java @@ -29,11 +29,6 @@ import net.minecraft.event.ClickEvent; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; -import java.awt.*; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - public class FeaturesCommand extends ClientCommandBase { public FeaturesCommand() { super("neufeatures"); @@ -48,13 +43,11 @@ public class FeaturesCommand extends ClientCommandBase { } String url = Constants.MISC.get("featureslist").getAsString(); - Desktop desk = Desktop.getDesktop(); - try { - desk.browse(new URI(url)); - Utils.addChatMessage( EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + - EnumChatFormatting.GOLD + "> Opening Feature List in browser."); - } catch (URISyntaxException | IOException ignored) { - + if (Utils.openUrl(url)) { + Utils.addChatMessage( + EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + + EnumChatFormatting.GOLD + "> Opening Feature List in browser."); + } else { ChatComponentText clickTextFeatures = new ChatComponentText( EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.BOLD + "NEU" + EnumChatFormatting.RESET + EnumChatFormatting.GOLD + "> Click here to open the Feature List in your browser."); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java index e3881f44..fe1f0af4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfigEditor.java @@ -44,8 +44,6 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.awt.*; -import java.net.URI; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -737,10 +735,7 @@ public class NEUConfigEditor extends GuiElement { if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && mouseY >= y + 6 && mouseY <= y + 23) { - try { - Desktop.getDesktop().browse(new URI(socialsLink[socialIndex])); - } catch (Exception ignored) { - } + Utils.openUrl(socialsLink[socialIndex]); return true; } } 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 63717093..4bf65cc6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -20,19 +20,16 @@ package io.github.moulberry.notenoughupdates.profileviewer; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.cosmetics.ShaderManager; import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField; -import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryPage; import io.github.moulberry.notenoughupdates.profileviewer.trophy.TrophyFishPage; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.DungeonsWeight; import io.github.moulberry.notenoughupdates.profileviewer.weight.weight.SkillsWeight; import io.github.moulberry.notenoughupdates.util.AsyncDependencyLoader; -import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -58,8 +55,6 @@ import org.lwjgl.opengl.GL20; import java.awt.*; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; @@ -843,21 +838,11 @@ public class GuiProfileViewer extends GuiScreen { profileId != null ) { if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) { - try { - Desktop desk = Desktop.getDesktop(); - desk.browse( - new URI( - "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + - profileId - ) - ); - Utils.playPressSound(); - return; - } catch (UnsupportedOperationException | IOException | URISyntaxException ignored) { - //no idea how this sounds, but ya know just in case - Utils.playSound(new ResourceLocation("game.player.hurt"), true); - return; - } + String url = "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + + profileId; + Utils.openUrl(url); + Utils.playPressSound(); + return; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index a3f2296c..0ea1dafb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -71,10 +71,13 @@ import java.awt.*; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.math.BigInteger; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.FloatBuffer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -2037,4 +2040,21 @@ public class Utils { System.out.println(message); } } + + public static boolean openUrl(String url) { + try { + Desktop desk = Desktop.getDesktop(); + desk.browse(new URI(url)); + return true; + } catch (UnsupportedOperationException | IOException | URISyntaxException ignored) { + Runtime runtime = Runtime.getRuntime(); + try { + runtime.exec("xdg-open " + url); + return true; + } catch (IOException e) { + Utils.playSound(new ResourceLocation("game.player.hurt"), true); + return false; + } + } + } } -- cgit From c6330fc85211706ee6a3c212bfa50005981e3799 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Sun, 18 Dec 2022 22:34:08 +0100 Subject: Sh (#496) --- .../io/github/moulberry/notenoughupdates/listener/RenderListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java index e1fb8586..f15a26a7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java @@ -965,7 +965,7 @@ public class RenderListener { mayor.getAsJsonObject().get("name").getAsString().equals("Derpy") && NotEnoughUpdates.INSTANCE.config.dungeons.shouldWarningDerpy) { Utils.drawStringScaled( - EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "shMayor Derpy active!", + EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "Mayor Derpy active!", Minecraft.getMinecraft().fontRendererObj, guiLeft + xSize + 4 + 10, guiTop + 85, -- cgit From 4a9e1c462e4bc757c00813bab1944d42fc479d0e Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Thu, 22 Dec 2022 07:22:06 +1100 Subject: Added essence shop tooltip to pv (#488) --- .../notenoughupdates/profileviewer/ExtraPage.java | 25 ++++++++++++++++++++-- .../moulberry/notenoughupdates/util/Constants.java | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index 21ccc683..5f477196 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -39,6 +39,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; @@ -108,7 +109,9 @@ public class ExtraPage extends GuiProfileViewerPage { float xStart, float yStartTop, float xOffset, - float yOffset + float yOffset, + float mouseX, + float mouseY ) { int guiLeft = GuiProfileViewer.getGuiLeft(); int guiTop = GuiProfileViewer.getGuiTop(); @@ -143,6 +146,24 @@ public class ExtraPage extends GuiProfileViewerPage { guiTop + yStartTop + (yOffset - 1) * i, 76 ); + if (Constants.ESSENCESHOPS == null) return; + JsonObject essenceShops = Constants.ESSENCESHOPS; + if (mouseX >= guiLeft + xStart + xOffset && mouseX <= guiLeft + xStart + xOffset + 76 && + mouseY >= guiTop + yStartTop + (yOffset - 1) * i && + mouseY <= guiTop + yStartTop + (yOffset - 1) * i + 10) { + getInstance().tooltipToDisplay = new ArrayList<>(); + if (essenceShops.get(essenceName) == null) continue; + + for (Map.Entry entry : essenceShops.get(essenceName).getAsJsonObject().entrySet()) { + int perkTier = + (profileInfo.has("perks") && profileInfo.get("perks").getAsJsonObject().has(entry.getKey()) ? profileInfo.get("perks").getAsJsonObject().get(entry.getKey()).getAsInt() : 0); + getInstance().tooltipToDisplay.add( + EnumChatFormatting.GOLD + entry.getValue().getAsJsonObject().get("name").getAsString() + ": " + EnumChatFormatting.AQUA + + perkTier + "/" + entry.getValue().getAsJsonObject().get("costs").getAsJsonArray().size() + ); + } + + } } } @@ -414,7 +435,7 @@ public class ExtraPage extends GuiProfileViewerPage { 76 ); - drawEssence(profileInfo, xStart, yStartTop, xOffset, yOffset); + drawEssence(profileInfo, xStart, yStartTop, xOffset, yOffset, mouseX, mouseY); if (topKills == null) { topKills = new TreeMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java index e7674aa9..0105ba1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Constants.java @@ -77,6 +77,7 @@ public class Constants { public static JsonObject WEIGHT; public static JsonObject RNGSCORE; public static JsonObject ABIPHONE; + public static JsonObject ESSENCESHOPS; private static final ReentrantLock lock = new ReentrantLock(); @@ -100,6 +101,7 @@ public class Constants { WEIGHT = Utils.getConstant("weight", gson); RNGSCORE = Utils.getConstant("rngscore", gson); ABIPHONE = Utils.getConstant("abiphone", gson); + ESSENCESHOPS = Utils.getConstant("essenceshops", gson); parseEssenceCosts(); } catch (Exception ex) { -- cgit From 2bb3cb42e890a80205928d19fef6538860f142fe Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 22 Dec 2022 19:36:42 +0100 Subject: Merge pull request #502 * maxed stats are green --- .../notenoughupdates/profileviewer/ExtraPage.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index 5f477196..4c58e57a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -156,11 +156,15 @@ public class ExtraPage extends GuiProfileViewerPage { for (Map.Entry entry : essenceShops.get(essenceName).getAsJsonObject().entrySet()) { int perkTier = - (profileInfo.has("perks") && profileInfo.get("perks").getAsJsonObject().has(entry.getKey()) ? profileInfo.get("perks").getAsJsonObject().get(entry.getKey()).getAsInt() : 0); - getInstance().tooltipToDisplay.add( - EnumChatFormatting.GOLD + entry.getValue().getAsJsonObject().get("name").getAsString() + ": " + EnumChatFormatting.AQUA + - perkTier + "/" + entry.getValue().getAsJsonObject().get("costs").getAsJsonArray().size() - ); + (profileInfo.has("perks") && profileInfo.get("perks").getAsJsonObject().has(entry.getKey()) ? profileInfo + .get("perks") + .getAsJsonObject() + .get(entry.getKey()) + .getAsInt() : 0); + int max = entry.getValue().getAsJsonObject().get("costs").getAsJsonArray().size(); + EnumChatFormatting formatting = perkTier == max ? EnumChatFormatting.GREEN : EnumChatFormatting.AQUA; + String name = entry.getValue().getAsJsonObject().get("name").getAsString(); + getInstance().tooltipToDisplay.add(EnumChatFormatting.GOLD + name + ": " + formatting + perkTier + "/" + max); } } -- cgit From a9c58929460830662f28a2ebb5b3d09c687bd21d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Thu, 22 Dec 2022 19:38:21 +0100 Subject: Merge pull request #501 * ArrayIndexOutOfBoundsException * just change the condition to >= instead of == --- .../notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java index d3b9c04d..ef2a52bb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorDraggableList.java @@ -118,6 +118,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { int i = 0; int yOff = 0; for (int strIndex : activeText) { + if (strIndex >= exampleText.length) continue; String str = exampleText[strIndex]; String[] multilines = str.split("\n"); -- cgit From a7a2293d000a0ff16ddd2413989801a63868da52 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Thu, 22 Dec 2022 21:25:00 +0100 Subject: [TRIVIAL] "Fixed" smallest neu bug in history (#505) (wanna know what else is small) --- .../io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java index e4b4269d..aa977413 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemRecipe.java @@ -232,7 +232,7 @@ public class GuiItemRecipe extends GuiScreen { int row = i / hotbarSize; int col = i % hotbarSize; if (row == 0) - slots.add(new RecipeSlot(HOTBAR_SLOT_X + i * SLOT_SPACING, HOTBAR_SLOT_Y, item)); + slots.add(new RecipeSlot(HOTBAR_SLOT_X + i * SLOT_SPACING, HOTBAR_SLOT_Y + 1, item)); else slots.add(new RecipeSlot( PLAYER_INVENTORY_X + col * SLOT_SPACING, -- cgit From 7535b1f9c24d56522fd9526a8b9ad8940d130995 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Fri, 23 Dec 2022 17:27:23 +0100 Subject: RepoEditing: Allow opening files in the external editor (#487) --- .../moulberry/notenoughupdates/NEUManager.java | 8 ++++-- .../moulberry/notenoughupdates/NEUOverlay.java | 29 ++++++++++++++++++++-- .../commands/dev/DevTestCommand.java | 13 +++++++--- .../notenoughupdates/options/NEUConfig.java | 3 +++ .../notenoughupdates/overlays/TimersOverlay.java | 1 + 5 files changed, 47 insertions(+), 7 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index ca0d91d2..ce15b09a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -288,7 +288,7 @@ public class NEUManager { public void loadItem(String internalName) { itemstackCache.remove(internalName); try { - JsonObject json = getJsonFromFile(new File(new File(repoLocation, "items"), internalName + ".json")); + JsonObject json = getJsonFromFile(getItemFileForInternalName(internalName)); if (json == null) { return; } @@ -971,6 +971,10 @@ public class NEUManager { return getUUIDFromNBT(tag); } + public File getItemFileForInternalName(String internalName) { + return new File(new File(repoLocation, "items"), internalName + ".json"); + } + public void writeItemToFile(ItemStack stack) { String internalname = getInternalNameForItem(stack); @@ -984,7 +988,7 @@ public class NEUManager { json.addProperty("modver", NotEnoughUpdates.VERSION); try { - writeJson(json, new File(new File(repoLocation, "items"), internalname + ".json")); + writeJson(json, getItemFileForInternalName(internalname)); } catch (IOException ignored) { } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index cff83cca..686f6a27 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -46,6 +46,7 @@ import io.github.moulberry.notenoughupdates.util.LerpingFloat; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.SpecialColour; import io.github.moulberry.notenoughupdates.util.Utils; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -84,8 +85,10 @@ import org.lwjgl.opengl.GL14; import org.lwjgl.util.vector.Vector2f; import java.awt.*; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -1156,8 +1159,30 @@ public class NEUOverlay extends Gui { manager.jsonToStack(item)); } } else if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing && - Keyboard.getEventCharacter() == 'k') { - Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(internalname.get(), item)); + keyPressed == Keyboard.KEY_K) { + if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + var externalEditorCommand = NotEnoughUpdates.INSTANCE.config.hidden.externalEditor; + if (externalEditorCommand == null) { + Utils.addChatMessage( + "§e[NEU] §3No external editor set! Run §b/neudevtest exteditor §3 " + + "to set your external editor. Optionally use {} as a placeholder for the filename."); + } else { + var externalFileName = manager.getItemFileForInternalName(internalname.get()).getAbsolutePath(); + if (externalEditorCommand.contains("{}")) { + externalEditorCommand = externalEditorCommand.replace("{}", externalFileName); + } else { + externalEditorCommand += " " + externalFileName; + } + try { + Runtime.getRuntime().exec(externalEditorCommand); + } catch (IOException e) { + Utils.addChatMessage("§e[NEU]§4 Could not open external editor."); + e.printStackTrace(); + } + } + } else { + Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(internalname.get(), item)); + } return true; } else if (keyPressed == manager.keybindItemSelect.getKeyCode() && NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 69033345..cf266dca 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -19,20 +19,17 @@ package io.github.moulberry.notenoughupdates.commands.dev; -import com.google.gson.Gson; import io.github.moulberry.notenoughupdates.BuildFlags; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor; import io.github.moulberry.notenoughupdates.core.util.MiscUtils; import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper; -import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone; import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; -import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.util.PronounDB; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.TabListUtils; @@ -142,6 +139,16 @@ public class DevTestCommand extends ClientCommandBase { .collect(Collectors.joining("\n")))); return; } + if (args.length >= 1 && args[0].equalsIgnoreCase("exteditor")) { + if (args.length > 1) { + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor = String.join( + " ", + Arrays.copyOfRange(args, 1, args.length) + ); + } + Utils.addChatMessage("§e[NEU] §fYour external editor is: §Z" + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor); + return; + } if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) { if (args.length == 1) { NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index f936ceb1..b5237a46 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -456,6 +456,9 @@ public class NEUConfig extends Config { @Expose public boolean hasOpenedWaypointMenu = false; + @Expose + public String externalEditor = null; + } public static ArrayList createDefaultEnchantColours() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 7edbee6b..8db06651 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -357,6 +357,7 @@ public class TimersOverlay extends TextTabOverlay { String clean = line.replaceAll("(\u00a7.)", ""); String[] cleanSplit = clean.split(" "); hidden.cookieBuffRemaining = 0; + if (line.contains("Not")) break; for (int i = 0; i + 1 < cleanSplit.length; i++) { if (i % 2 == 1) continue; -- cgit From df8663e5958fe43d0c68fde3f4d31e45b2f15da1 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 24 Dec 2022 03:48:50 +1100 Subject: Gui element scale (#485) --- .../core/config/gui/GuiPositionEditor.java | 36 +++++++++++----------- .../miscfeatures/PetInfoOverlay.java | 8 +++-- .../options/seperateSections/LocationEdit.java | 12 ++++++++ .../notenoughupdates/overlays/FuelBar.java | 5 ++- .../notenoughupdates/overlays/TextOverlay.java | 22 +++++++++---- 5 files changed, 55 insertions(+), 28 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java index 6fb8f353..1b71e3ce 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiPositionEditor.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.core.config.gui; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -27,6 +28,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; @@ -45,10 +47,9 @@ public class GuiPositionEditor extends GuiScreen { private int grabbedX = 0; private int grabbedY = 0; private int clickedPos = -1; - + private int oldGuiScale = -1; public static boolean renderDrill = false; - private int guiScaleOverride = -1; public GuiPositionEditor( LinkedHashMap overlayPositions, @@ -83,6 +84,16 @@ public class GuiPositionEditor extends GuiScreen { this.elementHeights = height; this.positionChangedCallback = positionChangedCallback; this.closedCallback = closedCallback; + int newGuiScale = NotEnoughUpdates.INSTANCE.config.locationedit.guiScale; + if (newGuiScale != 0) { + if (Minecraft.getMinecraft().gameSettings.guiScale != 0) { + this.oldGuiScale = Minecraft.getMinecraft().gameSettings.guiScale; + } else { + this.oldGuiScale = 4; + } + if (newGuiScale == 4) Minecraft.getMinecraft().gameSettings.guiScale = 0; + else Minecraft.getMinecraft().gameSettings.guiScale = NotEnoughUpdates.INSTANCE.config.locationedit.guiScale; + } } @Override @@ -91,17 +102,14 @@ public class GuiPositionEditor extends GuiScreen { closedCallback.run(); renderDrill = false; clickedPos = -1; + if (this.oldGuiScale != -1) Minecraft.getMinecraft().gameSettings.guiScale = this.oldGuiScale; } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); - ScaledResolution scaledResolution; - if (guiScaleOverride >= 0) { - scaledResolution = Utils.pushGuiScale(guiScaleOverride); - } else { - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - } + GlStateManager.pushMatrix(); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); this.width = scaledResolution.getScaledWidth(); this.height = scaledResolution.getScaledHeight(); @@ -127,9 +135,6 @@ public class GuiPositionEditor extends GuiScreen { if (position.isCenterY()) y -= elementHeight / 2; Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); - Utils.pushGuiScale(-1); - - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2, 8, true, 0xffffff ); @@ -137,6 +142,7 @@ public class GuiPositionEditor extends GuiScreen { scaledResolution.getScaledWidth() / 2, 18, true, 0xffffff ); } + GlStateManager.popMatrix(); } @Override @@ -144,12 +150,7 @@ public class GuiPositionEditor extends GuiScreen { super.mouseClicked(mouseX, mouseY, mouseButton); if (mouseButton == 0) { - ScaledResolution scaledResolution; - if (guiScaleOverride >= 0) { - scaledResolution = Utils.pushGuiScale(guiScaleOverride); - } else { - scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - } + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; for (int i = positions.size() - 1; i >= 0; i--) { @@ -171,7 +172,6 @@ public class GuiPositionEditor extends GuiScreen { } } - Utils.pushGuiScale(-1); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 61ebf7b5..13179179 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -661,7 +661,7 @@ public class PetInfoOverlay extends TextOverlay { JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get("ROCK;0"); if (petItem != null) { - Vector2f position = getPosition(overlayWidth, overlayHeight); + Vector2f position = getPosition(overlayWidth, overlayHeight, false); int x = (int) position.x; int y = (int) position.y; @@ -700,16 +700,18 @@ public class PetInfoOverlay extends TextOverlay { } if (petItem != null) { - Vector2f position = getPosition(overlayWidth, overlayHeight); + Vector2f position = getPosition(overlayWidth, overlayHeight, true); int x = (int) position.x; int y = (int) position.y; ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(petItem); GlStateManager.enableDepth(); GlStateManager.pushMatrix(); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.locationedit.guiScale); GlStateManager.translate(x - 2, y - 2, 0); GlStateManager.scale(2, 2, 1); Utils.drawItemStack(stack, 0, 0); + Utils.pushGuiScale(0); GlStateManager.popMatrix(); } @@ -718,7 +720,7 @@ public class PetInfoOverlay extends TextOverlay { JsonObject petItem2 = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get( currentPet2.skin != null ? currentPet2.skin : (currentPet2.petType + ";" + currentPet2.rarity.petId)); if (petItem2 != null) { - Vector2f position = getPosition(overlayWidth, overlayHeight); + Vector2f position = getPosition(overlayWidth, overlayHeight, false); int x = (int) position.x; int y = (int) position.y + NotEnoughUpdates.INSTANCE.config.petOverlay.petOverlayText.size() * 10 + 10; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java index fdfb6f93..52fd0c4a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/LocationEdit.java @@ -19,10 +19,12 @@ package io.github.moulberry.notenoughupdates.options.seperateSections; +import com.google.gson.annotations.Expose; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; public class LocationEdit { @@ -37,6 +39,16 @@ public class LocationEdit { ) public Position positions = new Position(-1, -1); + @Expose + @ConfigOption( + name = "Edit Gui Scale", + desc = "Change the size of NEU's overlays" + ) + @ConfigEditorDropdown( + values = {"Default", "Small", "Normal", "Large", "Auto"} + ) + public int guiScale = 0; + @ConfigOption( name = "Edit Dungeon Map", desc = "The NEU dungeon map has it's own editor (/neumap).\n" + diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FuelBar.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FuelBar.java index a70035f1..f2e485f2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FuelBar.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FuelBar.java @@ -100,7 +100,8 @@ public class FuelBar { fuelAmount = .3f; } if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + GlStateManager.pushMatrix(); + ScaledResolution scaledResolution = Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.locationedit.guiScale); Position position = NotEnoughUpdates.INSTANCE.config.mining.drillFuelBarPosition; int x = position.getAbsX(scaledResolution, NotEnoughUpdates.INSTANCE.config.mining.drillFuelBarWidth); @@ -139,6 +140,8 @@ public class FuelBar { Minecraft.getMinecraft().fontRendererObj.drawString(str, x + 2, y, 0xffffff, false ); + Utils.pushGuiScale(0); + GlStateManager.popMatrix(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java index 7884b2ac..2fbbe27d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TextOverlay.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.overlays; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -120,12 +121,15 @@ public abstract class TextOverlay { return new Vector2f(); } - protected Vector2f getPosition(int overlayWidth, int overlayHeight) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + protected Vector2f getPosition(int overlayWidth, int overlayHeight, boolean scaled) { + GlStateManager.pushMatrix(); + ScaledResolution scaledResolution; + if (!scaled) scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + else scaledResolution = Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.locationedit.guiScale); int x = position.getAbsX(scaledResolution, overlayWidth); int y = position.getAbsY(scaledResolution, overlayHeight); - + GlStateManager.popMatrix(); return new Vector2f(x, y); } @@ -138,17 +142,19 @@ public abstract class TextOverlay { private void render(List strings, boolean dummy) { if (strings == null) return; - + if (!dummy) { + GlStateManager.pushMatrix(); + Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.locationedit.guiScale); + } Vector2f size = getSize(strings); overlayHeight = (int) size.y; overlayWidth = (int) size.x; - Vector2f position = getPosition(overlayWidth, overlayHeight); + Vector2f position = getPosition(overlayWidth, overlayHeight, !dummy); int x = (int) position.x; int y = (int) position.y; TextOverlayStyle style = styleSupplier.get(); - if (style == TextOverlayStyle.BACKGROUND) Gui.drawRect(x, y, x + overlayWidth, y + overlayHeight, 0x80000000); GlStateManager.enableBlend(); @@ -204,5 +210,9 @@ public abstract class TextOverlay { } } } + if (!dummy) { + Utils.pushGuiScale(0); + GlStateManager.popMatrix(); + } } } -- cgit From bd96ab7fcbdba398022686df9ad6ec2acf7a7281 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 24 Dec 2022 04:23:46 +1100 Subject: fix farming overlay showing the wrong skill sometimes (#500) --- .../moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java index 08cbb189..51f3d351 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/FarmingSkillOverlay.java @@ -167,6 +167,9 @@ public class FarmingSkillOverlay extends TextOverlay { //Set default skilltype to Farming and get BZprice config value boolean useBZPrice = NotEnoughUpdates.INSTANCE.config.skillOverlays.useBZPrice; skillType = "Farming"; + Farming = 1; + Alch = 0; + Foraging = 0; //WARTS if (internalname.startsWith("THEORETICAL_HOE_WARTS")) { -- cgit From 3a00eb285c9f46ee8a0cd615e325c8723a3aa15d Mon Sep 17 00:00:00 2001 From: heyngra Date: Sat, 24 Dec 2022 02:16:00 +0100 Subject: Fix NullPointerException in ItemTooltipRngListener (#510) --- .../moulberry/notenoughupdates/listener/ItemTooltipRngListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java index 2b7a9bef..d6d7087f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ItemTooltipRngListener.java @@ -210,7 +210,8 @@ public class ItemTooltipRngListener { dungeonData.clear(); JsonObject leveling = Constants.LEVELING; - if (!leveling.has("slayer_boss_xp") || + if (leveling == null || + !leveling.has("slayer_boss_xp") || !leveling.has("slayer_highest_tier") || !leveling.has("slayer_tier_colors") || !leveling.has("rng_meter_dungeon_score")) { -- cgit From 5b1c9f4959ff16be963217917a72d5bf669c4d8b Mon Sep 17 00:00:00 2001 From: GodOfPro <59516901+GodOfProDev@users.noreply.github.com> Date: Sat, 24 Dec 2022 04:46:40 +0330 Subject: Fixed total highest waves being included in total runs (#509) --- .../github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java index 87548f5e..95009b1d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/CrimsonIslePage.java @@ -211,6 +211,7 @@ public class CrimsonIslePage extends GuiProfileViewerPage { public int getTotalKuudraRuns(JsonObject completedRuns) { int totalRuns = 0; for (Map.Entry runs : completedRuns.entrySet()) { + if (runs.getKey().startsWith("highest_wave")) continue; totalRuns += runs.getValue().getAsInt(); } return totalRuns; -- cgit From 4fd32fb0575fbb698b2c7611f357595255ce2635 Mon Sep 17 00:00:00 2001 From: Lulonaut Date: Sat, 24 Dec 2022 02:19:54 +0100 Subject: allow coin ingredients with decimal places (#506) --- .../moulberry/notenoughupdates/recipes/Ingredient.java | 12 ++++++------ .../io/github/moulberry/notenoughupdates/util/ItemUtils.java | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java index c973f8c0..38d2447b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/Ingredient.java @@ -32,7 +32,7 @@ import java.util.Set; public class Ingredient { public static final String SKYBLOCK_COIN = "SKYBLOCK_COIN"; - private final int count; + private final double count; private final String internalItemId; private final NEUManager manager; private ItemStack itemStack; @@ -42,7 +42,7 @@ public class Ingredient { String[] parts = ingredientIdentifier.split(":"); internalItemId = parts[0]; if (parts.length == 2) { - count = Integer.parseInt(parts[1]); + count = Double.parseDouble(parts[1]); } else if (parts.length == 1) { count = 1; } else { @@ -50,13 +50,13 @@ public class Ingredient { } } - public Ingredient(NEUManager manager, String internalItemId, int count) { + public Ingredient(NEUManager manager, String internalItemId, double count) { this.manager = manager; this.count = count; this.internalItemId = internalItemId; } - private Ingredient(NEUManager manager, int coinValue) { + private Ingredient(NEUManager manager, double coinValue) { this.manager = manager; this.internalItemId = SKYBLOCK_COIN; this.count = coinValue; @@ -82,7 +82,7 @@ public class Ingredient { return "SKYBLOCK_COIN".equals(internalItemId); } - public int getCount() { + public double getCount() { return count; } @@ -97,7 +97,7 @@ public class Ingredient { } JsonObject itemInfo = manager.getItemInformation().get(internalItemId); itemStack = manager.jsonToStack(itemInfo); - itemStack.stackSize = count; + itemStack.stackSize = (int) count; return itemStack; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java index 2ff9692d..bc44f656 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemUtils.java @@ -42,13 +42,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.function.BiFunction; public class ItemUtils { - public static ItemStack getCoinItemStack(long coinAmount) { + public static ItemStack getCoinItemStack(double coinAmount) { String uuid = "2070f6cb-f5db-367a-acd0-64d39a7e5d1b"; String texture = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTM4MDcxNzIxY2M1YjRjZDQwNmNlNDMxYTEzZjg2MDgzYTg5NzNlMTA2NGQyZjg4OTc4Njk5MzBlZTZlNTIzNyJ9fX0="; @@ -63,7 +62,7 @@ public class ItemUtils { "ewogICJ0aW1lc3RhbXAiIDogMTYzNTk1NzQ4ODQxNywKICAicHJvZmlsZUlkIiA6ICJmNThkZWJkNTlmNTA0MjIyOGY2MDIyMjExZDRjMTQwYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJ1bnZlbnRpdmV0YWxlbnQiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2I5NTFmZWQ2YTdiMmNiYzIwMzY5MTZkZWM3YTQ2YzRhNTY0ODE1NjRkMTRmOTQ1YjZlYmMwMzM4Mjc2NmQzYiIsCiAgICAgICJtZXRhZGF0YSIgOiB7CiAgICAgICAgIm1vZGVsIiA6ICJzbGltIgogICAgICB9CiAgICB9CiAgfQp9"; } ItemStack skull = Utils.createSkull( - "\u00A7r\u00A76" + NumberFormat.getInstance(Locale.US).format(coinAmount) + " Coins", + "§r§6" + NumberFormat.getInstance().format(coinAmount) + " Coins", uuid, texture ); -- cgit From 978e084c4a9f3d8899ccbfa9894b42e5bbf0aa3a Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 24 Dec 2022 21:07:25 +1100 Subject: fix "an" where should be "a" (#516) --- .../notenoughupdates/options/seperateSections/TooltipTweaks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java index 5c320db1..8539c3c4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/TooltipTweaks.java @@ -227,7 +227,7 @@ public class TooltipTweaks { @Expose @ConfigOption( name = "Abiphone NPC Location", - desc = "Click on an NPC to set an marker at the location" + desc = "Click on an NPC to set a marker at the location" ) @ConfigEditorBoolean public boolean abiphoneContactMarker = true; -- cgit From 0cba03b165fc66cf2c56e1a5669024f2976d2f9c Mon Sep 17 00:00:00 2001 From: GodOfPro <59516901+GodOfProDev@users.noreply.github.com> Date: Sun, 25 Dec 2022 14:18:51 +0330 Subject: Fix total kills, deaths not being reset on profile switch (#512) Override the reset cache --- .../github/moulberry/notenoughupdates/profileviewer/ExtraPage.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index 4c58e57a..a1b15b82 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -590,4 +590,10 @@ public class ExtraPage extends GuiProfileViewerPage { } return null; } + + @Override + public void resetCache() { + topDeaths = null; + topKills = null; + } } -- cgit From 1ce926e405392b03eb6c6afd6f7cc7996f461ce7 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Tue, 27 Dec 2022 02:06:02 +1100 Subject: set combat overlay to be off by default (#523) --- .../notenoughupdates/options/seperateSections/SkillOverlays.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java index db0a0e94..f9dbe69e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/SkillOverlays.java @@ -24,7 +24,6 @@ import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; -import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDraggableList; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorFSR; @@ -303,7 +302,7 @@ public class SkillOverlays { ) @ConfigEditorBoolean @ConfigAccordionId(id = 4) - public boolean combatSkillOverlay = true; + public boolean combatSkillOverlay = false; @Expose @ConfigOption( -- cgit From 95d6a0c52af4511a90ebde2fe339f3f31cc5b9ae Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 26 Dec 2022 23:44:23 +0100 Subject: No More Guessing - Find Out Exactly How Much Time is Left in Star Cult Events (#513) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../io/github/moulberry/notenoughupdates/util/StarCultCalculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java b/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java index 02ec5ad3..4c4fe02d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/StarCultCalculator.java @@ -101,7 +101,7 @@ public class StarCultCalculator { } if (active && activeTill != 0) { - return "Active!"; + return "Active! (" + Utils.prettyTime(activeTill - System.currentTimeMillis()) + ")"; } return Utils.prettyTime(cultStart.toEpochMilli() - l); -- cgit From de2b44e25e513592e36689cd2f50e932082dc37c Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Wed, 28 Dec 2022 05:39:57 +1100 Subject: Fix aucion profit taking too much tax (#525) 1% tax added for auctions collected above 1M coins --- .../github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java index 88ca0cc8..82c392e4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionProfit.java @@ -104,7 +104,7 @@ public class AuctionProfit { int coins = tryParse(EnumChatFormatting.getTextWithoutFormattingCodes(coinsString.trim())); if (coins != 0) { if (coins > 1000000) { - coins /= 1.1; + coins /= 1.01; } coinsToCollect += coins; } @@ -113,7 +113,7 @@ public class AuctionProfit { if (line.contains("§7Status: §aSold!") || line.contains("§7Status: §aEnded!")) { if (coinsToCheck != 0) { if (coinsToCheck > 1000000) { - coinsToCheck /= 1.1; + coinsToCheck /= 1.01; } coinsToCollect += coinsToCheck; coinsToCheck = 0; -- cgit From d9c0192761734a9cf4595f990df408a278b1e430 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Wed, 28 Dec 2022 05:41:05 +1100 Subject: explain better how to use colour codes in /neurename (#526) explain better how to use colour codes --- .../io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java index 7d541296..674e4068 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java @@ -221,7 +221,7 @@ public class GuiItemCustomize extends GuiScreen { tooltipToDisplay = Lists.newArrayList( EnumChatFormatting.AQUA + "Set a custom name for the item", EnumChatFormatting.GREEN + "", - EnumChatFormatting.GREEN + "Type \"&&\" to use colour codes", + EnumChatFormatting.GREEN + "Type \"&&\" for \u00B6", EnumChatFormatting.GREEN + "Type \"**\" for \u272A", EnumChatFormatting.GREEN + "Type \"*1-9\" for \u278A-\u2792", EnumChatFormatting.GREEN + "", -- cgit From fa7abebe73f629c17e7a43d8c50307d2f8aa588e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 27 Dec 2022 19:56:24 +0100 Subject: Craft cost price calculation improved (#511) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../io/github/moulberry/notenoughupdates/auction/APIManager.java | 6 ++++++ .../io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt | 2 ++ 2 files changed, 8 insertions(+) (limited to 'src/main/java/io') 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 53e72dc1..e606fc49 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -27,6 +27,7 @@ import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.recipes.Ingredient; +import io.github.moulberry.notenoughupdates.recipes.ItemShopRecipe; import io.github.moulberry.notenoughupdates.recipes.NeuRecipe; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.Utils; @@ -902,6 +903,11 @@ public class APIManager { if (recipes != null) RECIPE_ITER: for (NeuRecipe recipe : recipes) { + if (recipe instanceof ItemShopRecipe) { + if (vanillaItem) { + continue; + } + } if (recipe.hasVariableCost() || !recipe.shouldUseForCraftCost()) continue; float craftPrice = 0; for (Ingredient i : recipe.getIngredients()) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt index c4b64969..e6dc0abc 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/recipes/KatRecipe.kt @@ -161,4 +161,6 @@ data class KatRecipe( override fun getBackground(): ResourceLocation { return ResourceLocation("notenoughupdates:textures/gui/katting_tall.png") } + + override fun shouldUseForCraftCost() = false } -- cgit From 354aed689ae3d5d7bfd8ab1d7ce9002127b8c526 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Wed, 28 Dec 2022 03:19:19 +0100 Subject: Issue with "god pot" in Todo list resolved (#521) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../github/moulberry/notenoughupdates/overlays/TimersOverlay.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 8db06651..74c64972 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -37,7 +37,6 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.input.Keyboard; import org.lwjgl.util.vector.Vector2f; import java.time.ZoneId; @@ -302,10 +301,14 @@ public class TimersOverlay extends TextTabOverlay { boolean foundCookieBuffText = false; boolean foundGodPotText = false; + boolean foundEffectsText = false; if (SBInfo.getInstance().getLocation() != null && !SBInfo.getInstance().getLocation().equals("dungeon") && SBInfo.getInstance().footer != null) { String formatted = SBInfo.getInstance().footer.getFormattedText(); for (String line : formatted.split("\n")) { + if (line.contains("Active Effects")) { + foundEffectsText = true; + } Matcher activeEffectsMatcher = PATTERN_ACTIVE_EFFECTS.matcher(line); if (activeEffectsMatcher.matches()) { foundGodPotText = true; @@ -411,7 +414,7 @@ public class TimersOverlay extends TextTabOverlay { } } - if (!foundGodPotText) { + if (!foundGodPotText && foundEffectsText) { hidden.godPotionDuration = 0; } -- cgit From 400033abc97a281b3ca71a771734f139b7949875 Mon Sep 17 00:00:00 2001 From: efefury <69400149+efefury@users.noreply.github.com> Date: Sat, 31 Dec 2022 00:48:37 +0000 Subject: show neu nw if soopy doesn't work (#532) --- .../notenoughupdates/profileviewer/BasicPage.java | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index 30ac269b..873ee9f2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -265,6 +265,16 @@ public class BasicPage extends GuiProfileViewerPage { networth = profile.getNetWorth(profileId); } + //Networth is under 0 + //If = -1 -> an error occurred + //If = -2 -> still loading networth + String stateStr = EnumChatFormatting.RED + "An error occurred"; + if (networth == -2) { + stateStr = EnumChatFormatting.YELLOW + "Loading..."; + } else if (networth == -1) { + networth = profile.getNetWorth(profileId); + } + if (networth > 0) { Utils.drawStringCentered( EnumChatFormatting.GREEN + "Net Worth: " + EnumChatFormatting.GOLD + @@ -302,16 +312,16 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.GOLD + networthIRLMoney ); - getInstance().tooltipToDisplay.add(""); if (NotEnoughUpdates.INSTANCE.config.profileViewer.useSoopyNetworth && profile.getSoopyNetworthLeaderboardPosition() >= 0 && profile.isProfileMaxSoopyWeight(profile, profileId)) { - + getInstance().tooltipToDisplay.add(""); String lbPosStr = EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format( profile.getSoopyNetworthLeaderboardPosition()); - getInstance().tooltipToDisplay.add(lbPosStr + EnumChatFormatting.GREEN + " on soopy's networth leaderboard!"); + getInstance().tooltipToDisplay.add( + lbPosStr + EnumChatFormatting.GREEN + " on soopy's networth leaderboard!"); } if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { @@ -336,15 +346,6 @@ public class BasicPage extends GuiProfileViewerPage { } } } else { - //Networth is under 0 - //If = -1 -> an error occured - //If = -2 -> still loading networth - - String stateStr = EnumChatFormatting.RED + "An error occured"; - if (networth == -2) { - stateStr = EnumChatFormatting.YELLOW + "Loading..."; - } - Utils.drawStringCentered( EnumChatFormatting.GREEN + "Net Worth: " + stateStr, fr, @@ -886,14 +887,14 @@ public class BasicPage extends GuiProfileViewerPage { EnumChatFormatting.DARK_GREEN + "#" + EnumChatFormatting.GOLD + GuiProfileViewer.numberFormat.format( profile.getSoopyWeightLeaderboardPosition()); getInstance().tooltipToDisplay.add(""); - String stateStr = EnumChatFormatting.RED + "An error occured"; + String stateStr = EnumChatFormatting.RED + "An error occurred"; if (weight == -2) { stateStr = EnumChatFormatting.YELLOW + "Loading"; } if (weight > 0) getInstance().tooltipToDisplay.add(lbPosStr + EnumChatFormatting.GREEN + " on soopy's weight leaderboard!"); else - getInstance().tooltipToDisplay.add(stateStr + " soopy's weight leaderboard"); + getInstance().tooltipToDisplay.add(stateStr + " on soopy's weight leaderboard"); } } } -- cgit From ac34faf4ad240448a8906ab4cc1acd0d4f0614ce Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sat, 31 Dec 2022 03:07:01 +0100 Subject: Probably fixing the cookie buff timer problem (#527) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: nopo --- .../notenoughupdates/miscfeatures/CookieWarning.java | 14 ++++++++++---- .../moulberry/notenoughupdates/overlays/TimersOverlay.java | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java index ab8c5e57..80751371 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/CookieWarning.java @@ -30,6 +30,7 @@ import net.minecraft.util.EnumChatFormatting; public class CookieWarning { private static boolean hasNotified; + private static boolean hasErrorMessage; public static void resetNotification() { hasNotified = false; @@ -74,7 +75,9 @@ public class CookieWarning { return; } if (timeLine != null) { - String[] digits = timeLine.replaceAll("(\u00a7.)", "").split(" "); + String clean = timeLine.replaceAll("(\u00a7.)", ""); + clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2"); + String[] digits = clean.split(" "); int minutes = 0; try { for (int i = 0; i < digits.length; i++) { @@ -109,9 +112,12 @@ public class CookieWarning { } // ignore seconds } } catch (NumberFormatException e) { - e.printStackTrace(); - Utils.addChatMessage(EnumChatFormatting.RED + - "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."); + if (!hasErrorMessage) { + e.printStackTrace(); + Utils.addChatMessage(EnumChatFormatting.RED + + "NEU ran into an issue when retrieving the Booster Cookie Timer. Check the logs for details."); + hasErrorMessage = true; + } hasNotified = true; } if (minutes < NotEnoughUpdates.INSTANCE.config.notifications.boosterCookieWarningMins && !hasNotified) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 74c64972..6e20c77d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -344,9 +344,9 @@ public class TimersOverlay extends TextTabOverlay { } } } catch (Exception e) { - e.printStackTrace(); if (!hasErrorMessage) { Utils.addChatMessage(EnumChatFormatting.YELLOW + "[NEU] Unable to work out your god pot timer"); + e.printStackTrace(); hasErrorMessage = true; } break; @@ -358,6 +358,7 @@ public class TimersOverlay extends TextTabOverlay { foundCookieBuffText = true; } else if (foundCookieBuffText) { String clean = line.replaceAll("(\u00a7.)", ""); + clean = clean.replaceAll("(\\d)([smhdy])", "$1 $2"); String[] cleanSplit = clean.split(" "); hidden.cookieBuffRemaining = 0; if (line.contains("Not")) break; -- cgit From d6f67a21586947e22643592e4f419edf23f58638 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 31 Dec 2022 13:33:42 +1100 Subject: fix farming overlay accordion not working in item overlays (#530) --- .../options/seperateSections/ItemOverlays.java | 69 +++++++++++----------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java index 84bce030..d477b62b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java @@ -24,7 +24,6 @@ import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; -import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorColour; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDraggableList; import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; @@ -121,7 +120,7 @@ public class ItemOverlays { name = "Block Zapper Overlay", desc = "" ) - @ConfigEditorAccordion(id = 6) + @ConfigEditorAccordion(id = 2) public boolean zapperAccordion = false; @Expose @@ -130,7 +129,7 @@ public class ItemOverlays { desc = "Show which blocks will be destroyed when using the Block Zapper" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 6) + @ConfigAccordionId(id = 2) public boolean enableZapperOverlay = true; @Expose @@ -140,14 +139,14 @@ public class ItemOverlays { searchTags = "color" ) @ConfigEditorColour - @ConfigAccordionId(id = 6) + @ConfigAccordionId(id = 2) public String zapperOverlayColour = "0:102:171:5:0"; @ConfigOption( name = "Smooth AOTE/AOTV/Hyp", desc = "" ) - @ConfigEditorAccordion(id = 2) + @ConfigEditorAccordion(id = 3) public boolean aoteAccordion = false; @Expose @@ -156,7 +155,7 @@ public class ItemOverlays { desc = "Teleport smoothly to your destination when using AOTE or AOTV" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 2) + @ConfigAccordionId(id = 3) public boolean enableSmoothAOTE = true; @Expose @@ -165,7 +164,7 @@ public class ItemOverlays { desc = "Teleport smoothly to your destination when using Hyperion" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 2) + @ConfigAccordionId(id = 3) public boolean enableSmoothHyperion = true; @Expose @@ -178,7 +177,7 @@ public class ItemOverlays { maxValue = 500, minStep = 25 ) - @ConfigAccordionId(id = 2) + @ConfigAccordionId(id = 3) public int smoothTpMillis = 125; @Expose @@ -191,7 +190,7 @@ public class ItemOverlays { maxValue = 500, minStep = 25 ) - @ConfigAccordionId(id = 2) + @ConfigAccordionId(id = 3) public int smoothTpMillisEtherwarp = 50; @Expose @@ -200,14 +199,14 @@ public class ItemOverlays { desc = "Remove the explosion effect when using a hyperion" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 2) + @ConfigAccordionId(id = 3) public boolean disableHyperionParticles = true; @ConfigOption( name = "Etherwarp", desc = "" ) - @ConfigEditorAccordion(id = 3) + @ConfigEditorAccordion(id = 4) public boolean etherwarpAccordion = false; @Expose @@ -216,7 +215,7 @@ public class ItemOverlays { desc = "Zoom in on targeted blocks with etherwarp, making it easier to adjust at a distance" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 3) + @ConfigAccordionId(id = 4) public boolean etherwarpZoom = true; @Expose @@ -225,7 +224,7 @@ public class ItemOverlays { desc = "Display an overlay which tells you if the etherwarp will fail." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 3) + @ConfigAccordionId(id = 4) public boolean enableEtherwarpHelperOverlay = true; @Expose @@ -234,7 +233,7 @@ public class ItemOverlays { desc = "Display an overlay that tells you what block you will TP to." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 3) + @ConfigAccordionId(id = 4) public boolean enableEtherwarpBlockOverlay = true; @Expose @@ -243,7 +242,7 @@ public class ItemOverlays { desc = "Don't display the etherwarp block overlay when you can't TP to the block" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 3) + @ConfigAccordionId(id = 4) public boolean disableOverlayWhenFailed = false; @Expose @@ -253,14 +252,14 @@ public class ItemOverlays { searchTags = "color" ) @ConfigEditorColour - @ConfigAccordionId(id = 3) + @ConfigAccordionId(id = 4) public String etherwarpHighlightColour = "00:70:156:8:96"; @ConfigOption( name = "Bonemerang Overlay", desc = "" ) - @ConfigEditorAccordion(id = 4) + @ConfigEditorAccordion(id = 5) public boolean bonemerangAccordion = false; @Expose @@ -269,7 +268,7 @@ public class ItemOverlays { desc = "Shows info about the bonemerang while holding it." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 4) + @ConfigAccordionId(id = 5) public boolean enableBonemerangOverlay = true; @Expose @@ -278,7 +277,7 @@ public class ItemOverlays { desc = "Highlight entities that will be hit by your bonemerang" ) @ConfigEditorBoolean - @ConfigAccordionId(id = 4) + @ConfigAccordionId(id = 5) public boolean highlightTargeted = true; @Expose @@ -296,7 +295,7 @@ public class ItemOverlays { "\u00a77Targets: \u00a76\u00a7l10" } ) - @ConfigAccordionId(id = 4) + @ConfigAccordionId(id = 5) public List bonemerangOverlayText = new ArrayList<>(Arrays.asList(0, 1)); @Expose @@ -307,7 +306,7 @@ public class ItemOverlays { @ConfigEditorDropdown( values = {"Background", "No Shadow", "Shadow Only", "Full Shadow"} ) - @ConfigAccordionId(id = 4) + @ConfigAccordionId(id = 5) public int bonemerangOverlayStyle = 0; @Expose @ConfigOption( @@ -316,14 +315,14 @@ public class ItemOverlays { "Might cause some lag." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 4) + @ConfigAccordionId(id = 5) public boolean bonemerangFastUpdate = false; @ConfigOption( name = "Minion Crystal Radius Overlay", desc = "" ) - @ConfigEditorAccordion(id = 5) + @ConfigEditorAccordion(id = 6) public boolean crystalAccordion = false; @Expose @@ -332,7 +331,7 @@ public class ItemOverlays { desc = "Show a block overlay for the effective radius of minion crystals (farming, mining, etc)." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 5) + @ConfigAccordionId(id = 6) public boolean enableCrystalOverlay = true; @Expose @@ -341,14 +340,14 @@ public class ItemOverlays { desc = "Show the crystal overlay, even when a minion crystal is not being held." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 5) + @ConfigAccordionId(id = 6) public boolean alwaysShowCrystal = false; @ConfigOption( name = "Farming Overlays", desc = "" ) - @ConfigEditorAccordion(id = 6) + @ConfigEditorAccordion(id = 7) public boolean farmingAccordion = false; @Expose @@ -357,7 +356,7 @@ public class ItemOverlays { desc = "Show a block overlay for the effected blocks of prismapump's ability." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 6) + @ConfigAccordionId(id = 7) public boolean enablePrismapumpOverlay = true; @Expose @@ -366,7 +365,7 @@ public class ItemOverlays { desc = "Show a block overlay for the effected blocks of the hoe of tilling's ability." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 6) + @ConfigAccordionId(id = 7) public boolean enableHoeOverlay = true; @Expose @@ -375,18 +374,18 @@ public class ItemOverlays { desc = "Show a block overlay for the effected blocks of dirt wand's ability." ) @ConfigEditorBoolean - @ConfigAccordionId(id = 6) + @ConfigAccordionId(id = 7) public boolean enableDirtWandOverlay = true; @ConfigOption( name="Custom Wither Cloak", desc = "" ) - @ConfigEditorAccordion(id = 7) + @ConfigEditorAccordion(id = 8) public boolean customWitherCloakAccordion = false; @Expose - @ConfigAccordionId(id = 7) + @ConfigAccordionId(id = 8) @ConfigOption( name = "Enable Custom Wither Cloak", desc = "Replaces Hypixel Wither Cloak with custom shields due to the Hypixel Wither Cloak being difficult to see through" @@ -395,7 +394,7 @@ public class ItemOverlays { public boolean customWitherCloakToggle = true; @Expose - @ConfigAccordionId(id = 7) + @ConfigAccordionId(id = 8) @ConfigOption( name = "Shield Count", desc = "The amount of shields circling the player\n0 = No shields" @@ -408,7 +407,7 @@ public class ItemOverlays { public int customWitherCloakCount = 6; @Expose - @ConfigAccordionId(id = 7) + @ConfigAccordionId(id = 8) @ConfigOption( name = "Shield Speed", desc = "How fast they circle the player\n0 = Not moving\nNegative = Spinning opposite direction" @@ -437,7 +436,7 @@ public class ItemOverlays { */ @Expose - @ConfigAccordionId(id = 7) + @ConfigAccordionId(id = 8) @ConfigOption( name = "Shield Distance From Player", desc = "How far (in blocks) each shield is from the player\n" + @@ -451,7 +450,7 @@ public class ItemOverlays { public float customWitherCloakDistance = 1.2f; @Expose - @ConfigAccordionId(id = 7) + @ConfigAccordionId(id = 8) @ConfigOption( name = "\u00A7aInspiration:", desc = "\u00A76u/Sori0612 \u00A77on \u00A7cReddit\n\n\u00A78https://tinyurl.com/creeperveil" -- cgit From 81a7db8fd001c99b846579547b1f7f1637fd73bb Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 31 Dec 2022 13:40:10 +1100 Subject: Fix daily powder resetting at the wrong time (#518) --- .../notenoughupdates/overlays/TimersOverlay.java | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java index 6e20c77d..419c9785 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/TimersOverlay.java @@ -726,7 +726,7 @@ public class TimersOverlay extends TextTabOverlay { // Daily Mithril Powder display long mithrilPowderCompleted = hidden.dailyMithrilPowerCompleted + 1000 * 60 * 60 * 24 - currentTime; - if (hidden.dailyMithrilPowerCompleted < midnightReset) { + if (hidden.dailyMithrilPowerCompleted < catacombsReset) { map.put( 7, DARK_AQUA + "Mithril Powder: " + @@ -734,29 +734,29 @@ public class TimersOverlay extends TextTabOverlay { ); } else if ( NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyMithrilPowderDisplay >= DISPLAYTYPE.VERYSOON.ordinal() && - (hidden.dailyMithrilPowerCompleted < (midnightReset - TimeEnums.HALFANHOUR.time))) { + (hidden.dailyMithrilPowerCompleted < (catacombsReset - TimeEnums.HALFANHOUR.time))) { map.put( 7, DARK_AQUA + "Mithril Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.verySoonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyMithrilPowderDisplay >= DISPLAYTYPE.SOON.ordinal() && - (hidden.dailyMithrilPowerCompleted < (midnightReset - TimeEnums.HOUR.time))) { + (hidden.dailyMithrilPowerCompleted < (catacombsReset - TimeEnums.HOUR.time))) { map.put( 7, DARK_AQUA + "Mithril Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.soonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if ( NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyMithrilPowderDisplay >= DISPLAYTYPE.KINDASOON.ordinal() && - (hidden.dailyMithrilPowerCompleted < (midnightReset - (TimeEnums.HOUR.time * 3)))) { + (hidden.dailyMithrilPowerCompleted < (catacombsReset - (TimeEnums.HOUR.time * 3)))) { map.put( 7, DARK_AQUA + "Mithril Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.kindaSoonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyMithrilPowderDisplay >= DISPLAYTYPE.ALWAYS.ordinal()) { @@ -764,12 +764,12 @@ public class TimersOverlay extends TextTabOverlay { 7, DARK_AQUA + "Mithril Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.defaultColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } // Daily Gemstone Powder Display - if (hidden.dailyGemstonePowderCompleted < midnightReset) { + if (hidden.dailyGemstonePowderCompleted < catacombsReset) { map.put( 8, DARK_AQUA + "Gemstone Powder: " + @@ -777,29 +777,29 @@ public class TimersOverlay extends TextTabOverlay { ); } else if ( NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyGemstonePowderDisplay >= DISPLAYTYPE.VERYSOON.ordinal() && - (hidden.dailyGemstonePowderCompleted < (midnightReset - TimeEnums.HALFANHOUR.time))) { + (hidden.dailyGemstonePowderCompleted < (catacombsReset - TimeEnums.HALFANHOUR.time))) { map.put( 8, DARK_AQUA + "Gemstone Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.verySoonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyGemstonePowderDisplay >= DISPLAYTYPE.SOON.ordinal() && - (hidden.dailyGemstonePowderCompleted < (midnightReset - TimeEnums.HOUR.time))) { + (hidden.dailyGemstonePowderCompleted < (catacombsReset - TimeEnums.HOUR.time))) { map.put( 8, DARK_AQUA + "Gemstone Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.soonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if ( NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyGemstonePowderDisplay >= DISPLAYTYPE.KINDASOON.ordinal() && - (hidden.dailyGemstonePowderCompleted < (midnightReset - (TimeEnums.HOUR.time * 3)))) { + (hidden.dailyGemstonePowderCompleted < (catacombsReset - (TimeEnums.HOUR.time * 3)))) { map.put( 8, DARK_AQUA + "Gemstone Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.kindaSoonColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } else if (NotEnoughUpdates.INSTANCE.config.miscOverlays.dailyGemstonePowderDisplay >= DISPLAYTYPE.ALWAYS.ordinal()) { @@ -807,7 +807,7 @@ public class TimersOverlay extends TextTabOverlay { 8, DARK_AQUA + "Gemstone Powder: " + EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.defaultColour] + - Utils.prettyTime(timeDiffMidnightNow) + Utils.prettyTime(catacombsDiffNow) ); } -- cgit From 103c2ed444d2f4d3becd300fb169b3e60b468c47 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 31 Dec 2022 13:41:19 +1100 Subject: Fixed better containers flashing white for a few ticks (#524) --- .../moulberry/notenoughupdates/miscfeatures/BetterContainers.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java index ad0b238a..dc7b0e15 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java @@ -22,7 +22,6 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.events.SlotClickEvent; -import io.github.moulberry.notenoughupdates.listener.RenderListener; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.client.renderer.GlStateManager; @@ -90,7 +89,7 @@ public class BetterContainers { public static void bindHook(TextureManager textureManager, ResourceLocation location) { long currentMillis = System.currentTimeMillis(); - if (isChestOpen() && RenderListener.inventoryLoaded) { + if (isChestOpen()) { int invHashcode = lastInvHashcode; if (currentMillis - lastHashcodeCheck > 50) { -- cgit From fbdbde5ea7db57e41e4defd4377ec2d4773f315d Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Sat, 31 Dec 2022 14:06:45 +1100 Subject: fix current xp showing above max xp for level 100 (#515) --- .../moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 13179179..37cb14b5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -496,7 +496,7 @@ public class PetInfoOverlay extends TextOverlay { DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); if (pet == null) return 0; try { - return Float.parseFloat(df.format(pet.petLevel.getPercentageToNextLevel() * 100f)); + return Float.parseFloat(df.format(Math.min(pet.petLevel.getPercentageToNextLevel() * 100f, 100f))); } catch (Exception ignored) { return 0; } @@ -516,7 +516,8 @@ public class PetInfoOverlay extends TextOverlay { roundFloat(currentPet.petLevel.getExpRequiredForNextLevel()) + EnumChatFormatting.YELLOW + " (" + getLevelPercent(currentPet) + "%)"; - String lvlString = EnumChatFormatting.AQUA + "" + Utils.shortNumberFormat(levelXp, 0) + "/" + + String lvlString = EnumChatFormatting.AQUA + "" + + Utils.shortNumberFormat(Math.min(levelXp, currentPet.petLevel.getExpRequiredForNextLevel()), 0) + "/" + Utils.shortNumberFormat(currentPet.petLevel.getExpRequiredForNextLevel(), 0) + EnumChatFormatting.YELLOW + " (" + getLevelPercent(currentPet) + "%)"; -- cgit From adc3222fae3dc66c56ccede50c62ff741929be16 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Sun, 1 Jan 2023 10:41:51 -0800 Subject: Some PV Cleanup (#520) * Remove Unused Import "org.luaj.vm2.ast.Str" Add final keyword in various places, creating slight performance increases * Refactoring, Error Prevention, and Duplicate Code Simplification Rename "stats" declared in line 1723 to "playerStats" to avoid hiding the "stats" field declared at line 648. Rename "passiveStats" declared in line 1723 to "passivePlayerStats" to avoid hiding the "passiveStats" field declared at line 649. Rename "networth" declared in line 939 to "playerNetworth" to avoid hiding the "networth" field declared at line 650. Rename "networth" declared in line 910 to "soopyNetworthData" to avoid hiding the "networth" field declared at line 650. soopyNetworthData Change if check to "isEmpty" rather than size() > 0 Add function getAuctionPriceHelper to increase readability and decrease duplicate code Replaced null with Empty Collections in some cases, to make caller logic simpler Remove commented code for Catacombs in skilltoSkillDesiplayMap Merge if statementes with their enclosing if statements, as they were unnecessarily nested. * Redefine petRarityToNumMap and skillToSkillDisplayMap as ImmutableMaps rather than HashMap and LinkedHashMap respectively due to their immutable nature. * Fix typo in SkyCrypt capilization Add final to some variables for improved performance. --- .../profileviewer/GuiProfileViewer.java | 205 +++---- .../profileviewer/ProfileViewer.java | 630 +++++++++++---------- 2 files changed, 430 insertions(+), 405 deletions(-) (limited to 'src/main/java/io') 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 4bf65cc6..de5d384a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -171,7 +171,10 @@ public class GuiProfileViewer extends GuiScreen { ); public final GuiElementTextField playerNameTextField; public final GuiElementTextField inventoryTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); - public final GuiElementTextField killDeathSearchTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); + public final GuiElementTextField killDeathSearchTextField = new GuiElementTextField( + "", + GuiElementTextField.SCALE_TEXT + ); private final Map pages = new HashMap<>(); public int sizeX; public int sizeY; @@ -189,7 +192,7 @@ public class GuiProfileViewer extends GuiScreen { private double lastBgBlurFactor = -1; private boolean showBingoPage; - public GuiProfileViewer(ProfileViewer.Profile profile) { + public GuiProfileViewer(final ProfileViewer.Profile profile) { GuiProfileViewer.profile = profile; GuiProfileViewer.profileId = profile.getLatestProfile(); String name = ""; @@ -216,7 +219,7 @@ public class GuiProfileViewer extends GuiScreen { pages.put(ProfileViewerPage.CRIMSON_ISLE, new CrimsonIslePage(this)); } - private static float getMaxLevelXp(JsonArray levels, int offset, int maxLevel) { + private static float getMaxLevelXp(final JsonArray levels, final int offset, final int maxLevel) { float xpTotal = 0; for (int i = offset; i < offset + maxLevel - 1; i++) { @@ -227,7 +230,7 @@ public class GuiProfileViewer extends GuiScreen { } @Deprecated - public static String shortNumberFormat(double n, int iteration) { + public static String shortNumberFormat(final double n, final int iteration) { return StringUtils.shortNumberFormat(n, iteration ); } @@ -249,7 +252,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { + public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) { currentTime = System.currentTimeMillis(); if (startTime == 0) startTime = currentTime; @@ -272,10 +275,10 @@ public class GuiProfileViewer extends GuiScreen { } } - this.sizeX = 431; - this.sizeY = 202; - guiLeft = (this.width - this.sizeX) / 2; - guiTop = (this.height - this.sizeY) / 2; + sizeX = 431; + sizeY = 202; + guiLeft = (width - sizeX) / 2; + guiTop = (height - sizeY) / 2; JsonObject currProfileInfo = profile != null ? profile.getProfileInformation(profileId) : null; if (NotEnoughUpdates.INSTANCE.config.profileViewer.alwaysShowBingoTab) { @@ -317,7 +320,7 @@ public class GuiProfileViewer extends GuiScreen { if (!(page == ProfileViewerPage.LOADING)) { playerNameTextField.render(guiLeft + sizeX - 100, guiTop + sizeY + 5); - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); if (profile != null) { //Render Profile chooser button @@ -375,8 +378,10 @@ public class GuiProfileViewer extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_unknown); Utils.drawTexturedRect(guiLeft - 16 - 5, guiTop + sizeY + 5, 16, 16, GL11.GL_NEAREST); } - //Render Open In Skycrypt button - renderBlurredBackground(width, height, guiLeft + 100 + 6 + 2, guiTop + sizeY + 3 + 2, 100 - 4, 20 - 4); + //Render Open In SkyCrypt button + renderBlurredBackground( + width, + height, guiLeft + 100 + 6 + 2, guiTop + sizeY + 3 + 2, 100 - 4, 20 - 4); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); Utils.drawTexturedRect( guiLeft + 100 + 6, @@ -390,7 +395,7 @@ public class GuiProfileViewer extends GuiScreen { GL11.GL_NEAREST ); Utils.drawStringCenteredScaledMaxWidth( - "Open in Skycrypt", + "Open in SkyCrypt", Minecraft.getMinecraft().fontRendererObj, guiLeft + 50 + 100 + 6, guiTop + sizeY + 3 + 10, @@ -399,12 +404,15 @@ public class GuiProfileViewer extends GuiScreen { new Color(63, 224, 208, 255).getRGB() ); - if (profileDropdownSelected && !profile.getProfileNames().isEmpty() && scaledResolution.getScaleFactor() < 4) { - int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; - - int numProfiles = profile.getProfileNames().size(); - int sizeYDropdown = numProfiles * dropdownOptionSize; - renderBlurredBackground(width, height, guiLeft + 2, guiTop + sizeY + 23, 100 - 4, sizeYDropdown - 2); + if ( + profileDropdownSelected && !profile.getProfileNames().isEmpty() && scaledResolution.getScaleFactor() < 4) { + final int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; + + final int numProfiles = profile.getProfileNames().size(); + final int sizeYDropdown = numProfiles * dropdownOptionSize; + renderBlurredBackground( + width, + height, guiLeft + 2, guiTop + sizeY + 23, 100 - 4, sizeYDropdown - 2); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); Utils.drawTexturedRect(guiLeft, guiTop + sizeY + 23 - 3, 100, 3, 100 / 200f, 1, 0, 3 / 185f, GL11.GL_NEAREST); Utils.drawTexturedRect( @@ -431,7 +439,7 @@ public class GuiProfileViewer extends GuiScreen { ); for (int yIndex = 0; yIndex < profile.getProfileNames().size(); yIndex++) { - String otherProfileId = profile.getProfileNames().get(yIndex); + final String otherProfileId = profile.getProfileNames().get(yIndex); Utils.drawStringCenteredScaledMaxWidth( otherProfileId, Minecraft.getMinecraft().fontRendererObj, @@ -517,7 +525,7 @@ public class GuiProfileViewer extends GuiScreen { switch (page) { case LOADING: String str = EnumChatFormatting.YELLOW + "Loading player profiles."; - long currentTimeMod = System.currentTimeMillis() % 1000; + final long currentTimeMod = System.currentTimeMillis() % 1000; if (currentTimeMod > 333) { if (currentTimeMod < 666) { str += "."; @@ -537,7 +545,7 @@ public class GuiProfileViewer extends GuiScreen { //This is just here to inform the player what to do //like typing /api new or telling them to go find a psychotherapist - long timeDiff = System.currentTimeMillis() - startTime; + final long timeDiff = System.currentTimeMillis() - startTime; if (timeDiff > 20000) { Utils.drawStringCentered( @@ -575,11 +583,11 @@ public class GuiProfileViewer extends GuiScreen { 0 ); if (timeDiff > 360000) { - long second = (timeDiff / 1000) % 60; - long minute = (timeDiff / (1000 * 60)) % 60; - long hour = (timeDiff / (1000 * 60 * 60)) % 24; + final long second = (timeDiff / 1000) % 60; + final long minute = (timeDiff / (1000 * 60)) % 60; + final long hour = (timeDiff / (1000 * 60 * 60)) % 24; - String time = String.format("%02d:%02d:%02d", hour, minute, second); + final String time = String.format("%02d:%02d:%02d", hour, minute, second); Utils.drawStringCentered( EnumChatFormatting.YELLOW + "You've wasted your time here for: " + time, Minecraft.getMinecraft().fontRendererObj, @@ -693,17 +701,17 @@ public class GuiProfileViewer extends GuiScreen { if (currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { int ignoredTabs = 0; - List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - ProfileViewerPage iPage = ProfileViewerPage.getById(configList.get(i)); + final ProfileViewerPage iPage = ProfileViewerPage.getById(configList.get(i)); if (iPage == null) continue; if (iPage.stack == null || (iPage == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - int i2 = i - ignoredTabs; - int x = guiLeft + i2 * 28; - int y = guiTop - 28; + final int i2 = i - ignoredTabs; + final int x = guiLeft + i2 * 28; + final int y = guiTop - 28; if (mouseX > x && mouseX < x + 28) { if (mouseY > y && mouseY < y + 32) { @@ -720,41 +728,42 @@ public class GuiProfileViewer extends GuiScreen { } if (tooltipToDisplay != null) { - List grayTooltip = new ArrayList<>(tooltipToDisplay.size()); - for (String line : tooltipToDisplay) { + final List grayTooltip = new ArrayList<>(tooltipToDisplay.size()); + for (final String line : tooltipToDisplay) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, + width, height, -1, Minecraft.getMinecraft().fontRendererObj); tooltipToDisplay = null; } } - private void renderTabs(boolean renderPressed) { + private void renderTabs(final boolean renderPressed) { int ignoredTabs = 0; - List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); + final ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); if (page == null) continue; if (page.stack == null || (page == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - boolean pressed = page == currentPage; + final boolean pressed = page == currentPage; if (pressed == renderPressed) { renderTab(page.stack, i - ignoredTabs, pressed); } } } - private void renderTab(ItemStack stack, int xIndex, boolean pressed) { + private void renderTab(final ItemStack stack, final int xIndex, final boolean pressed) { GlStateManager.disableLighting(); GlStateManager.enableBlend(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.enableAlpha(); GlStateManager.alphaFunc(516, 0.1F); - int x = guiLeft + xIndex * 28; - int y = guiTop - 28; + final int x = guiLeft + xIndex * 28; + final int y = guiTop - 28; float uMin = 0; float uMax = 28 / 256f; @@ -788,20 +797,20 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException { if (currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { int ignoredTabs = 0; - List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); + final ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); if (page == null) continue; if (page.stack == null || (page == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - int i2 = i - ignoredTabs; - int x = guiLeft + i2 * 28; - int y = guiTop - 28; + final int i2 = i - ignoredTabs; + final int x = guiLeft + i2 * 28; + final int y = guiTop - 28; if (mouseX > x && mouseX < x + 28) { if (mouseY > y && mouseY < y + 32) { @@ -838,8 +847,9 @@ public class GuiProfileViewer extends GuiScreen { profileId != null ) { if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) { - String url = "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + - profileId; + final String url = + "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + + profileId; Utils.openUrl(url); Utils.playPressSound(); return; @@ -847,7 +857,7 @@ public class GuiProfileViewer extends GuiScreen { } if (mouseX > guiLeft && mouseX < guiLeft + 100 && profile != null && !profile.getProfileNames().isEmpty()) { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) { if (scaledResolution.getScaleFactor() >= 4) { profileDropdownSelected = false; @@ -866,7 +876,7 @@ public class GuiProfileViewer extends GuiScreen { if (profileNum >= profile.getProfileNames().size()) profileNum = 0; if (profileNum < 0) profileNum = profile.getProfileNames().size() - 1; - String newProfileId = profile.getProfileNames().get(profileNum); + final String newProfileId = profile.getProfileNames().get(profileNum); if (profileId != null && !profileId.equals(newProfileId)) { resetCache(); } @@ -875,11 +885,11 @@ public class GuiProfileViewer extends GuiScreen { profileDropdownSelected = !profileDropdownSelected; } } else if (scaledResolution.getScaleFactor() < 4 && profileDropdownSelected) { - int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; - int extraY = mouseY - (guiTop + sizeY + 23); - int index = extraY / dropdownOptionSize; + final int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; + final int extraY = mouseY - (guiTop + sizeY + 23); + final int index = extraY / dropdownOptionSize; if (index >= 0 && index < profile.getProfileNames().size()) { - String newProfileId = profile.getProfileNames().get(index); + final String newProfileId = profile.getProfileNames().get(index); if (profileId != null && !profileId.equals(newProfileId)) { resetCache(); } @@ -898,7 +908,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { + protected void keyTyped(final char typedChar, final int keyCode) throws IOException { super.keyTyped(typedChar, keyCode); if (pages.containsKey(currentPage)) { @@ -921,7 +931,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { + protected void mouseReleased(final int mouseX, final int mouseY, final int mouseButton) { super.mouseReleased(mouseX, mouseY, mouseButton); if (pages.containsKey(currentPage)) { @@ -930,17 +940,17 @@ public class GuiProfileViewer extends GuiScreen { } public void renderXpBar( - String skillName, - ItemStack stack, - int x, - int y, - int xSize, - ProfileViewer.Level levelObj, - int mouseX, - int mouseY + final String skillName, + final ItemStack stack, + final int x, + final int y, + final int xSize, + final ProfileViewer.Level levelObj, + final int mouseX, + final int mouseY ) { - float level = levelObj.level; - int levelFloored = (int) Math.floor(level); + final float level = levelObj.level; + final int levelFloored = (int) Math.floor(level); Utils.renderAlignedString(skillName, EnumChatFormatting.WHITE.toString() + levelFloored, x + 14, y - 4, xSize - 20); @@ -956,24 +966,27 @@ public class GuiProfileViewer extends GuiScreen { if (mouseX > x && mouseX < x + 120) { if (mouseY > y - 4 && mouseY < y + 13) { - String levelStr; + final String levelStr; String totalXpStr = null; if (skillName.contains("Catacombs")) { totalXpStr = EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE + - numberFormat.format(levelObj.totalXp) + EnumChatFormatting.DARK_GRAY + " (" + + numberFormat.format(levelObj.totalXp) + EnumChatFormatting.DARK_GRAY + " (" + DECIMAL_FORMAT.format(getPercentage(skillName.toLowerCase(), levelObj)) + "% to 50)"; } - // Adds overflow level to each level object that is maxed, avoids hotm level as there is no overflow xp for it + // Adds overflow level to each level object that is maxed, avoids hotm level as there is no overflow xp for it if (levelObj.maxed) { levelStr = levelObj.maxLevel != 7 ? - EnumChatFormatting.GOLD + "MAXED!" + EnumChatFormatting.GRAY + " (Overflow level: " + String.format("%.2f", levelObj.level) + ")" : - EnumChatFormatting.GOLD + "MAXED!"; + EnumChatFormatting.GOLD + "MAXED!" + EnumChatFormatting.GRAY + " (Overflow level: " + String.format( + "%.2f", + levelObj.level + ) + ")" : + EnumChatFormatting.GOLD + "MAXED!"; } else { if (skillName.contains("Class Average")) { levelStr = "Progress: " + EnumChatFormatting.DARK_PURPLE + String.format("%.1f", (level % 1 * 100)) + "%"; totalXpStr = "Exact Class Average: " + EnumChatFormatting.WHITE + String.format("%.2f", levelObj.level); } else { - int maxXp = (int) levelObj.maxXpForLevel; + final int maxXp = (int) levelObj.maxXpForLevel; levelStr = EnumChatFormatting.DARK_PURPLE + StringUtils.shortNumberFormat(Math.round((level % 1) * maxXp)) + @@ -993,8 +1006,8 @@ public class GuiProfileViewer extends GuiScreen { } } - NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs - NBTTagCompound display = new NBTTagCompound(); + final NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs + final NBTTagCompound display = new NBTTagCompound(); display.setString("Name", skillName); nbt.setTag("display", display); stack.setTagCompound(nbt); @@ -1010,14 +1023,14 @@ public class GuiProfileViewer extends GuiScreen { return ((BasicPage) pages.get(ProfileViewerPage.BASIC)).entityPlayer; } - public void renderGoldBar(float x, float y, float xSize) { + public void renderGoldBar(final float x, final float y, final float xSize) { if (!OpenGlHelper.areShadersSupported()) { renderBar(x, y, xSize, 1); return; } Minecraft.getMinecraft().getTextureManager().bindTexture(icons); - ShaderManager shaderManager = ShaderManager.getInstance(); + final ShaderManager shaderManager = ShaderManager.getInstance(); shaderManager.loadShader("make_gold"); shaderManager.loadData("make_gold", "amount", (startTime - System.currentTimeMillis()) / 10000f); @@ -1037,11 +1050,11 @@ public class GuiProfileViewer extends GuiScreen { GL20.glUseProgram(0); } - public void renderBar(float x, float y, float xSize, float completed) { + public void renderBar(final float x, final float y, final float xSize, float completed) { Minecraft.getMinecraft().getTextureManager().bindTexture(icons); completed = Math.round(completed / 0.05f) * 0.05f; - float notCompleted = 1 - completed; + final float notCompleted = 1 - completed; GlStateManager.color(1, 1, 1, 1); float width; @@ -1105,8 +1118,8 @@ public class GuiProfileViewer extends GuiScreen { * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to * apply scales and translations manually. */ - private Matrix4f createProjectionMatrix(int width, int height) { - Matrix4f projMatrix = new Matrix4f(); + private Matrix4f createProjectionMatrix(final int width, final int height) { + final Matrix4f projMatrix = new Matrix4f(); projMatrix.setIdentity(); projMatrix.m00 = 2.0F / (float) width; projMatrix.m11 = 2.0F / (float) (-height); @@ -1121,8 +1134,8 @@ public class GuiProfileViewer extends GuiScreen { private void blurBackground() { if (!OpenGlHelper.isFramebufferEnabled()) return; - int width = Minecraft.getMinecraft().displayWidth; - int height = Minecraft.getMinecraft().displayHeight; + final int width = Minecraft.getMinecraft().displayWidth; + final int height = Minecraft.getMinecraft().displayHeight; if (blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); @@ -1154,7 +1167,7 @@ public class GuiProfileViewer extends GuiScreen { ); blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) { + } catch (final Exception ignored) { } } if (blurShaderVert == null) { @@ -1167,7 +1180,7 @@ public class GuiProfileViewer extends GuiScreen { ); blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (Exception ignored) { + } catch (final Exception ignored) { } } if (blurShaderHorz != null && blurShaderVert != null) { @@ -1186,7 +1199,7 @@ public class GuiProfileViewer extends GuiScreen { } } - public float getPercentage(String skillName, ProfileViewer.Level level) { + public float getPercentage(final String skillName, final ProfileViewer.Level level) { if (level.maxed) { return 100; } @@ -1209,13 +1222,13 @@ public class GuiProfileViewer extends GuiScreen { * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] */ - public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { + public void renderBlurredBackground(final int width, final int height, final int x, final int y, final int blurWidth, final int blurHeight) { if (!OpenGlHelper.isFramebufferEnabled()) return; - float uMin = x / (float) width; - float uMax = (x + blurWidth) / (float) width; - float vMin = (height - y) / (float) height; - float vMax = (height - y - blurHeight) / (float) height; + final float uMin = x / (float) width; + final float uMax = (x + blurWidth) / (float) width; + final float vMin = (height - y) / (float) height; + final float vMax = (height - y - blurHeight) / (float) height; blurOutputVert.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); @@ -1248,22 +1261,22 @@ public class GuiProfileViewer extends GuiScreen { this(-1, null, null); } - ProfileViewerPage(int id, Item item, String name) { + ProfileViewerPage(final int id, final Item item, final String name) { this.id = id; if (item == null) { stack = null; } else { stack = new ItemStack(item); - NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs - NBTTagCompound display = new NBTTagCompound(); + final NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs + final NBTTagCompound display = new NBTTagCompound(); display.setString("Name", name); nbt.setTag("display", display); stack.setTagCompound(nbt); } } - public static ProfileViewerPage getById(int id) { - for (ProfileViewerPage page : values()) { + public static ProfileViewerPage getById(final int id) { + for (final ProfileViewerPage page : values()) { if (page.id == id) { return page; } 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 5337a99c..8aef917c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.profileviewer; +import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -36,7 +37,6 @@ import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; -import org.luaj.vm2.ast.Str; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; @@ -57,47 +57,56 @@ import java.util.regex.Pattern; public class ProfileViewer { - private static final HashMap petRarityToNumMap = new HashMap() { - { - put("COMMON", "0"); - put("UNCOMMON", "1"); - put("RARE", "2"); - put("EPIC", "3"); - put("LEGENDARY", "4"); - put("MYTHIC", "5"); - } - }; - private static final LinkedHashMap skillToSkillDisplayMap = - new LinkedHashMap() { - { - put("taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE + "Taming")); - put("mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY + "Mining")); - put( - "foraging", - Utils.createItemStack(Item.getItemFromBlock(Blocks.sapling), EnumChatFormatting.DARK_GREEN + "Foraging") - ); - put( - "enchanting", - Utils.createItemStack(Item.getItemFromBlock(Blocks.enchanting_table), EnumChatFormatting.GREEN + "Enchanting") - ); - put( - "carpentry", - Utils.createItemStack(Item.getItemFromBlock(Blocks.crafting_table), EnumChatFormatting.DARK_RED + "Carpentry") - ); - put("farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming")); - put("combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED + "Combat")); - put("fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA + "Fishing")); - put("alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE + "Alchemy")); - put("runecrafting", Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE + "Runecrafting")); - put("social", Utils.createItemStack(Items.emerald, EnumChatFormatting.DARK_GREEN + "Social")); - // put("catacombs", Utils.createItemStack(Item.getItemFromBlock(Blocks.deadbush), EnumChatFormatting.GOLD+"Catacombs")); - put("zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD + "Rev Slayer")); - put("spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD + "Tara Slayer")); - put("wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD + "Sven Slayer")); - put("enderman", Utils.createItemStack(Items.ender_pearl, EnumChatFormatting.GOLD + "Ender Slayer")); - put("blaze", Utils.createItemStack(Items.blaze_rod, EnumChatFormatting.GOLD + "Blaze Slayer")); - } - }; + private static final ImmutableMap petRarityToNumMap = + ImmutableMap.builder() + .put("COMMON", "0") + .put("UNCOMMON", "1") + .put("RARE", "2") + .put("EPIC", "3") + .put("LEGENDARY", "4") + .put("MYTHIC", "5") + .build(); + + private static final ImmutableMap skillToSkillDisplayMap = + ImmutableMap.builder() + .put("taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE + "Taming")) + .put("mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY + "Mining")) + .put( + "foraging", + Utils.createItemStack( + Item.getItemFromBlock(Blocks.sapling), + EnumChatFormatting.DARK_GREEN + "Foraging" + ) + ) + .put( + "enchanting", + Utils.createItemStack( + Item.getItemFromBlock(Blocks.enchanting_table), + EnumChatFormatting.GREEN + "Enchanting" + ) + ) + .put( + "carpentry", + Utils.createItemStack( + Item.getItemFromBlock(Blocks.crafting_table), + EnumChatFormatting.DARK_RED + "Carpentry" + ) + ) + .put("farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming")) + .put("combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED + "Combat")) + .put("fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA + "Fishing")) + .put("alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE + "Alchemy")) + .put( + "runecrafting", + Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE + "Runecrafting") + ) + .put("social", Utils.createItemStack(Items.emerald, EnumChatFormatting.DARK_GREEN + "Social")) + .put("zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD + "Rev Slayer")) + .put("spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD + "Tara Slayer")) + .put("wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD + "Sven Slayer")) + .put("enderman", Utils.createItemStack(Items.ender_pearl, EnumChatFormatting.GOLD + "Ender Slayer")) + .put("blaze", Utils.createItemStack(Items.blaze_rod, EnumChatFormatting.GOLD + "Blaze Slayer")) + .build(); private static final ItemStack CAT_FARMING = Utils.createItemStack( Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming" @@ -452,7 +461,7 @@ public class ProfileViewer { private final HashMap uuidToProfileMap = new HashMap<>(); private final HashMap nameToUuid = new HashMap<>(); - public ProfileViewer(NEUManager manager) { + public ProfileViewer(final NEUManager manager) { this.manager = manager; } @@ -469,20 +478,20 @@ public class ProfileViewer { } public static Map getSkillToSkillDisplayMap() { - return Collections.unmodifiableMap(skillToSkillDisplayMap); + return skillToSkillDisplayMap; } - public static Level getLevel(JsonArray levelingArray, float xp, int levelCap, boolean cumulative) { - Level levelObj = new Level(); + public static Level getLevel(final JsonArray levelingArray, float xp, final int levelCap, final boolean cumulative) { + final Level levelObj = new Level(); levelObj.totalXp = xp; levelObj.maxLevel = levelCap; for (int level = 0; level < levelingArray.size(); level++) { - float levelXp = levelingArray.get(level).getAsFloat(); + final float levelXp = levelingArray.get(level).getAsFloat(); if (levelXp > xp) { if (cumulative) { - float previous = level > 0 ? levelingArray.get(level - 1).getAsFloat() : 0; + final float previous = level > 0 ? levelingArray.get(level - 1).getAsFloat() : 0; levelObj.maxXpForLevel = (levelXp - previous); levelObj.level = 1 + level + (xp - levelXp) / levelObj.maxXpForLevel; } else { @@ -526,8 +535,8 @@ public class ProfileViewer { return null; } - public void getHypixelProfile(String name, Consumer callback) { - String nameF = name.toLowerCase(); + public void getHypixelProfile(final String name, final Consumer callback) { + final String nameF = name.toLowerCase(); manager.apiUtils .newHypixelApiRequest("player") .queryArgument("name", nameF) @@ -552,12 +561,12 @@ public class ProfileViewer { ); } - public void putNameUuid(String name, String uuid) { + public void putNameUuid(final String name, final String uuid) { nameToUuid.put(name, uuid); } - public void getPlayerUUID(String name, Consumer uuidCallback) { - String nameF = name.toLowerCase(); + public void getPlayerUUID(final String name, final Consumer uuidCallback) { + final String nameF = name.toLowerCase(); if (nameToUuid.containsKey(nameF)) { uuidCallback.accept(nameToUuid.get(nameF)); return; @@ -570,7 +579,7 @@ public class ProfileViewer { .thenAccept(jsonObject -> { if (jsonObject.has("id") && jsonObject.get("id").isJsonPrimitive() && ((JsonPrimitive) jsonObject.get("id")).isString()) { - String uuid = jsonObject.get("id").getAsString(); + final String uuid = jsonObject.get("id").getAsString(); nameToUuid.put(nameF, uuid); uuidCallback.accept(uuid); return; @@ -579,8 +588,8 @@ public class ProfileViewer { }); } - public void getProfileByName(String name, Consumer callback) { - String nameF = name.toLowerCase(); + public void getProfileByName(final String name, final Consumer callback) { + final String nameF = name.toLowerCase(); if (nameToUuid.containsKey(nameF) && nameToUuid.get(nameF) == null) { callback.accept(null); @@ -612,8 +621,8 @@ public class ProfileViewer { ); } - public Profile getProfile(String uuid, Consumer callback) { - Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid)); + public Profile getProfile(final String uuid, final Consumer callback) { + final Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid)); if (profile.skyblockProfiles != null) { callback.accept(profile); } else { @@ -622,7 +631,7 @@ public class ProfileViewer { return profile; } - public Profile getProfileReset(String uuid, Consumer callback) { + public Profile getProfileReset(final String uuid, final Consumer callback) { if (uuidToProfileMap.containsKey(uuid)) uuidToProfileMap.get(uuid).resetCache(); return getProfile(uuid, callback); } @@ -668,7 +677,7 @@ public class ProfileViewer { private long lastGuildInfoState = 0; private long lastBingoInfoState = 0; - public Profile(String uuid) { + public Profile(final String uuid) { this.uuid = uuid; } @@ -676,12 +685,12 @@ public class ProfileViewer { if (playerStatus != null) return playerStatus; if (updatingPlayerStatusState.get()) return null; - long currentTime = System.currentTimeMillis(); + final long currentTime = System.currentTimeMillis(); if (currentTime - lastStatusInfoState < 15 * 1000) return null; lastStatusInfoState = currentTime; updatingPlayerStatusState.set(true); - HashMap args = new HashMap<>(); + final HashMap args = new HashMap<>(); args.put("uuid", "" + uuid); manager.apiUtils .newHypixelApiRequest("status") @@ -699,8 +708,9 @@ public class ProfileViewer { } public JsonObject getBingoInformation() { - long currentTime = System.currentTimeMillis(); - if (bingoInformation != null && currentTime - lastBingoInfoState < 15 * 1000) return bingoInformation; + final long currentTime = System.currentTimeMillis(); + if (bingoInformation != null && currentTime - + lastBingoInfoState < 15 * 1000) return bingoInformation; if (updatingBingoInfo.get() && bingoInformation != null) return bingoInformation; if (updatingBingoInfo.get() && bingoInformation == null) return null; @@ -725,11 +735,11 @@ public class ProfileViewer { } public class SoopyNetworthData { - private HashMap categoryWorth; + private final HashMap categoryWorth; private Long totalWorth; - private String[] keys; + private final String[] keys; - SoopyNetworthData(JsonObject nwData) { + SoopyNetworthData(final JsonObject nwData) { categoryWorth = new HashMap<>(); if (nwData == null || nwData.isJsonNull()) { @@ -744,7 +754,7 @@ public class ProfileViewer { } totalWorth = nwData.get("total").getAsLong(); - for (Map.Entry entry : nwData.get("categories").getAsJsonObject().entrySet()) { + for (final Map.Entry entry : nwData.get("categories").getAsJsonObject().entrySet()) { if (entry.getValue().isJsonNull()) { continue; } @@ -768,7 +778,7 @@ public class ProfileViewer { return totalWorth; } - public long getCategory(String name) { + public long getCategory(final String name) { if (categoryWorth.containsKey(name)) return categoryWorth.get(name); return 0; } @@ -792,16 +802,16 @@ public class ProfileViewer { return soopyWeightLeaderboardPosition; } - public boolean isProfileMaxSoopyWeight(ProfileViewer.Profile profile, String profileName) { + public boolean isProfileMaxSoopyWeight(final ProfileViewer.Profile profile, final String profileName) { String highestProfileName = ""; double largestProfileWeight = 0; for (int yIndex = 0; yIndex < profileNames.size(); yIndex++) { - String otherProfileId = profileNames.get(yIndex); - Map skyblockInfo = profile.getSkyblockInfo(otherProfileId); + final String otherProfileId = profileNames.get(yIndex); + final Map skyblockInfo = profile.getSkyblockInfo(otherProfileId); if (skyblockInfo == null) continue; - SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); - double weightValue = senitherWeight.getTotalWeight().getRaw(); + final SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); + final double weightValue = senitherWeight.getTotalWeight().getRaw(); if (weightValue > largestProfileWeight) { largestProfileWeight = weightValue; @@ -816,14 +826,14 @@ public class ProfileViewer { * Returns SoopyNetworthData with total = -1 if error * Returns null if still loading */ - public SoopyNetworthData getSoopyNetworth(String profileName, Runnable callback) { + public SoopyNetworthData getSoopyNetworth(String profileName, final Runnable callback) { if (profileName == null) profileName = latestProfile; if (soopyNetworth.get(profileName) != null) { callback.run(); return soopyNetworth.get(profileName); } - JsonArray playerInfo = getSkyblockProfiles(() -> {}); + final JsonArray playerInfo = getSkyblockProfiles(() -> {}); if (playerInfo == null) return null; //Not sure how to support the callback in these cases if (updatingSoopyNetworth.get()) @@ -833,7 +843,7 @@ public class ProfileViewer { soopyNetworthLeaderboardPosition = -2; //loading manager.apiUtils .request() - .url("https://soopy.dev/api/v2/leaderboard/networth/user/" + this.uuid) + .url("https://soopy.dev/api/v2/leaderboard/networth/user/" + uuid) .requestJson() .handle((jsonObject, throwable) -> { if (throwable != null) throwable.printStackTrace(); @@ -854,7 +864,7 @@ public class ProfileViewer { soopyWeightLeaderboardPosition = -2; //loading manager.apiUtils .request() - .url("https://soopy.dev/api/v2/leaderboard/weight/user/" + this.uuid) + .url("https://soopy.dev/api/v2/leaderboard/weight/user/" + uuid) .requestJson() .handle((jsonObject, throwable) -> { if (throwable != null) throwable.printStackTrace(); @@ -874,7 +884,7 @@ public class ProfileViewer { manager.apiUtils .request() - .url("https://soopy.dev/api/v2/player_networth/" + this.uuid) + .url("https://soopy.dev/api/v2/player_networth/" + uuid) .method("POST") .postData("application/json", skyblockProfiles.toString()) .requestJson() @@ -887,9 +897,9 @@ public class ProfileViewer { if (!skyblockProfiles.get(i).isJsonObject()) { return null; } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - String cuteName = profile.get("cute_name").getAsString(); + final String cuteName = profile.get("cute_name").getAsString(); soopyNetworth.put(cuteName, new SoopyNetworthData(null)); } @@ -903,19 +913,22 @@ public class ProfileViewer { if (!skyblockProfiles.get(i).isJsonObject()) { return null; } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - String cuteName = profile.get("cute_name").getAsString(); - String profileId = profile.get("profile_id").getAsString(); + final String cuteName = profile.get("cute_name").getAsString(); + final String profileId = profile.get("profile_id").getAsString(); - SoopyNetworthData networth; + final SoopyNetworthData soopyNetworthData; if (jsonObject.getAsJsonObject("data").get(profileId).isJsonNull()) { - networth = new SoopyNetworthData(null); + soopyNetworthData = new SoopyNetworthData(null); } else { - networth = new SoopyNetworthData(jsonObject.getAsJsonObject("data").get(profileId).getAsJsonObject()); + soopyNetworthData = new SoopyNetworthData(jsonObject + .getAsJsonObject("data") + .get(profileId) + .getAsJsonObject()); } - soopyNetworth.put(cuteName, networth); + soopyNetworth.put(cuteName, soopyNetworthData); } updatingSoopyNetworth.set(false); @@ -931,73 +944,53 @@ public class ProfileViewer { if (getProfileInformation(profileName) == null) return -1; if (getInventoryInfo(profileName) == null) return -1; - JsonObject inventoryInfo = getInventoryInfo(profileName); - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject inventoryInfo = getInventoryInfo(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); - HashMap mostExpensiveInternal = new HashMap<>(); + final HashMap mostExpensiveInternal = new HashMap<>(); - long networth = 0; - for (Map.Entry entry : inventoryInfo.entrySet()) { + long playerNetworth = 0; + for (final Map.Entry entry : inventoryInfo.entrySet()) { if (entry.getValue().isJsonArray()) { - for (JsonElement element : entry.getValue().getAsJsonArray()) { + for (final JsonElement element : entry.getValue().getAsJsonArray()) { if (element != null && element.isJsonObject()) { - JsonObject item = element.getAsJsonObject(); - String internalname = item.get("internalname").getAsString(); + final JsonObject item = element.getAsJsonObject(); + final String internalname = item.get("internalname").getAsString(); if (manager.auctionManager.isVanillaItem(internalname)) continue; - JsonObject bzInfo = manager.auctionManager.getBazaarInfo(internalname); - - long auctionPrice; - if (bzInfo != null && bzInfo.has("curr_sell")) { - auctionPrice = (int) bzInfo.get("curr_sell").getAsFloat(); - } else { - auctionPrice = (long) manager.auctionManager.getItemAvgBin(internalname); - if (auctionPrice <= 0) { - auctionPrice = manager.auctionManager.getLowestBin(internalname); - } - } + final long auctionPrice = getAuctionPriceHelper(internalname); try { if (item.has("item_contents")) { - JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); - byte[] bytes = new byte[bytesArr.size()]; + final JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); + final byte[] bytes = new byte[bytesArr.size()]; for (int bytesArrI = 0; bytesArrI < bytesArr.size(); bytesArrI++) { bytes[bytesArrI] = bytesArr.get(bytesArrI).getAsByte(); } - NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); - NBTTagList items = contents_nbt.getTagList("i", 10); + final NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream( + bytes)); + final NBTTagList items = contents_nbt.getTagList("i", 10); for (int j = 0; j < items.tagCount(); j++) { - if (items.getCompoundTagAt(j).getKeySet().size() > 0) { - NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); - String internalname2 = manager.getInternalnameFromNBT(nbt); + if (!items.getCompoundTagAt(j).getKeySet().isEmpty()) { + final NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); + final String internalname2 = manager.getInternalnameFromNBT(nbt); if (internalname2 != null) { if (manager.auctionManager.isVanillaItem(internalname2)) continue; - JsonObject bzInfo2 = manager.auctionManager.getBazaarInfo(internalname2); - - long auctionPrice2; - if (bzInfo2 != null && bzInfo2.has("curr_sell")) { - auctionPrice2 = (int) bzInfo2.get("curr_sell").getAsFloat(); - } else { - auctionPrice2 = (long) manager.auctionManager.getItemAvgBin(internalname2); - if (auctionPrice2 <= 0) { - auctionPrice2 = manager.auctionManager.getLowestBin(internalname2); - } - } - - int count2 = items.getCompoundTagAt(j).getByte("Count"); + final long auctionPrice2 = getAuctionPriceHelper(internalname2); + final int count2 = items.getCompoundTagAt(j).getByte("Count"); mostExpensiveInternal.put( internalname2, auctionPrice2 * count2 + mostExpensiveInternal.getOrDefault(internalname2, 0L) ); - networth += auctionPrice2 * count2; + playerNetworth += auctionPrice2 * count2; } } } } - } catch (IOException ignored) { + } catch (final IOException ignored) { } int count = 1; @@ -1008,56 +1001,68 @@ public class ProfileViewer { internalname, auctionPrice * count + mostExpensiveInternal.getOrDefault(internalname, 0L) ); - networth += auctionPrice * count; + playerNetworth += auctionPrice * count; } } } } - if (networth == 0) return -1; - - networth = (int) (networth * 1.3f); - - JsonObject petsInfo = getPetsInfo(profileName); - if (petsInfo != null && petsInfo.has("pets")) { - if (petsInfo.get("pets").isJsonArray()) { - JsonArray pets = petsInfo.get("pets").getAsJsonArray(); - for (JsonElement element : pets) { - if (element.isJsonObject()) { - JsonObject pet = element.getAsJsonObject(); - - String petname = pet.get("type").getAsString(); - String tier = pet.get("tier").getAsString(); - String tierNum = petRarityToNumMap.get(tier); - if (tierNum != null) { - String internalname2 = petname + ";" + tierNum; - JsonObject info2 = manager.auctionManager.getItemAuctionInfo(internalname2); - if (info2 == null || !info2.has("price") || !info2.has("count")) continue; - int auctionPrice2 = (int) (info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); - - networth += auctionPrice2; - } + if (playerNetworth == 0) return -1; + + playerNetworth = (int) (playerNetworth * 1.3f); + + final JsonObject petsInfo = getPetsInfo(profileName); + if (petsInfo != null && petsInfo.has("pets") && petsInfo.get("pets").isJsonArray()) { + final JsonArray pets = petsInfo.get("pets").getAsJsonArray(); + for (final JsonElement element : pets) { + if (element.isJsonObject()) { + final JsonObject pet = element.getAsJsonObject(); + + final String petname = pet.get("type").getAsString(); + final String tier = pet.get("tier").getAsString(); + final String tierNum = petRarityToNumMap.get(tier); + if (tierNum != null) { + final String internalname2 = petname + ";" + tierNum; + final JsonObject info2 = manager.auctionManager.getItemAuctionInfo(internalname2); + if (info2 == null || !info2.has("price") || !info2.has("count")) continue; + final int auctionPrice2 = (int) (info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); + + playerNetworth += auctionPrice2; } } } } - float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), 0); - float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); + final float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), 0); + final float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); - networth += bankBalance + purseBalance; + playerNetworth += bankBalance + purseBalance; - this.networth.put(profileName, networth); - return networth; + networth.put(profileName, playerNetworth); + return playerNetworth; + } + + private long getAuctionPriceHelper(final String internalname) { + final JsonObject bzInfo = manager.auctionManager.getBazaarInfo(internalname); + + if (bzInfo != null && bzInfo.has("curr_sell")) { + return (int) bzInfo.get("curr_sell").getAsFloat(); + } else { + final long auctionPrice = (long) manager.auctionManager.getItemAvgBin(internalname); + if (auctionPrice <= 0) { + return manager.auctionManager.getLowestBin(internalname); + } + return auctionPrice; + } } public String getLatestProfile() { return latestProfile; } - public JsonArray getSkyblockProfiles(Runnable runnable) { + public JsonArray getSkyblockProfiles(final Runnable runnable) { if (skyblockProfiles != null) return skyblockProfiles; - long currentTime = System.currentTimeMillis(); + final long currentTime = System.currentTimeMillis(); if (currentTime - lastPlayerInfoState < 15 * 1000 && updatingSkyblockProfilesState.get()) return null; lastPlayerInfoState = currentTime; @@ -1078,22 +1083,21 @@ public class ProfileViewer { profileNames.clear(); - for (JsonElement profileEle : skyblockProfiles) { - JsonObject profile = profileEle.getAsJsonObject(); + for (final JsonElement profileEle : skyblockProfiles) { + final JsonObject profile = profileEle.getAsJsonObject(); if (!profile.has("members")) continue; - JsonObject members = profile.get("members").getAsJsonObject(); + final JsonObject members = profile.get("members").getAsJsonObject(); if (members.has(uuid)) { - JsonObject member = members.get(uuid).getAsJsonObject(); + final JsonObject member = members.get(uuid).getAsJsonObject(); - if (member.has("coop_invitation")) { - if (!member.get("coop_invitation").getAsJsonObject().get("confirmed").getAsBoolean()) { - continue; - } + if (member.has("coop_invitation") && + !member.get("coop_invitation").getAsJsonObject().get("confirmed").getAsBoolean()) { + continue; } - String cuteName = profile.get("cute_name").getAsString(); + final String cuteName = profile.get("cute_name").getAsString(); profileNames.add(cuteName); if (profile.has("selected") && profile.get("selected").getAsBoolean()) { lastCuteName = cuteName; @@ -1109,10 +1113,10 @@ public class ProfileViewer { return null; } - public JsonObject getGuildInformation(Runnable runnable) { + public JsonObject getGuildInformation(final Runnable runnable) { if (guildInformation != null) return guildInformation; - long currentTime = System.currentTimeMillis(); + final long currentTime = System.currentTimeMillis(); if (currentTime - lastGuildInfoState < 15 * 1000 && updatingGuildInfoState.get()) return null; lastGuildInfoState = currentTime; @@ -1142,7 +1146,7 @@ public class ProfileViewer { } public JsonObject getProfileInformation(String profileName) { - JsonArray playerInfo = getSkyblockProfiles(() -> {}); + final JsonArray playerInfo = getSkyblockProfiles(() -> {}); if (playerInfo == null) return null; if (profileName == null) profileName = latestProfile; if (profileMap.containsKey(profileName)) return profileMap.get(profileName); @@ -1152,12 +1156,12 @@ public class ProfileViewer { skyblockProfiles = null; return null; } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { if (!profile.has("members")) return null; - JsonObject members = profile.get("members").getAsJsonObject(); + final JsonObject members = profile.get("members").getAsJsonObject(); if (!members.has(uuid)) continue; - JsonObject profileInfo = members.get(uuid).getAsJsonObject(); + final JsonObject profileInfo = members.get(uuid).getAsJsonObject(); if (profile.has("banking")) { profileInfo.add("banking", profile.get("banking").getAsJsonObject()); } @@ -1173,25 +1177,25 @@ public class ProfileViewer { } public List getCoopProfileInformation(String profileName) { - JsonArray playerInfo = getSkyblockProfiles(() -> {}); - if (playerInfo == null) return null; + final JsonArray playerInfo = getSkyblockProfiles(() -> {}); + if (playerInfo == null) return Collections.emptyList(); if (profileName == null) profileName = latestProfile; if (coopProfileMap.containsKey(profileName)) return coopProfileMap.get(profileName); for (int i = 0; i < skyblockProfiles.size(); i++) { if (!skyblockProfiles.get(i).isJsonObject()) { skyblockProfiles = null; - return null; + return Collections.emptyList(); } - JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { - if (!profile.has("members")) return null; - JsonObject members = profile.get("members").getAsJsonObject(); - if (!members.has(uuid)) return null; - List coopList = new ArrayList<>(); - for (Map.Entry islandMember : members.entrySet()) { + if (!profile.has("members")) return Collections.emptyList(); + final JsonObject members = profile.get("members").getAsJsonObject(); + if (!members.has(uuid)) return Collections.emptyList(); + final List coopList = new ArrayList<>(); + for (final Map.Entry islandMember : members.entrySet()) { if (!islandMember.getKey().equals(uuid)) { - JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); + final JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); coopList.add(coopProfileInfo); } } @@ -1200,7 +1204,7 @@ public class ProfileViewer { } } - return null; + return Collections.emptyList(); } public void resetCache() { @@ -1219,30 +1223,30 @@ public class ProfileViewer { networth.clear(); } - public int getCap(JsonObject leveling, String skillName) { - JsonElement capsElement = Utils.getElement(leveling, "leveling_caps"); + public int getCap(final JsonObject leveling, final String skillName) { + final JsonElement capsElement = Utils.getElement(leveling, "leveling_caps"); return capsElement != null && capsElement.isJsonObject() && capsElement.getAsJsonObject().has(skillName) ? capsElement.getAsJsonObject().get(skillName).getAsInt() : 50; } public Map getSkyblockInfo(String profileName) { - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); - if (profileInfo == null) return null; + if (profileInfo == null) return Collections.emptyMap(); if (profileName == null) profileName = latestProfile; - List coopProfileInfo = getCoopProfileInformation(profileName); + final List coopProfileInfo = getCoopProfileInformation(profileName); if (skyblockInfoCache.containsKey(profileName)) return skyblockInfoCache.get(profileName); - JsonObject leveling = Constants.LEVELING; + final JsonObject leveling = Constants.LEVELING; if (leveling == null || !leveling.has("social")) { Utils.showOutdatedRepoNotification(); - return null; + return Collections.emptyMap(); } - Map out = new HashMap<>(); + final Map out = new HashMap<>(); - List skills = Arrays.asList( + final List skills = Arrays.asList( "taming", "mining", "foraging", @@ -1256,14 +1260,14 @@ public class ProfileViewer { "social" ); float totalSkillXP = 0; - for (String skillName : skills) { + for (final String skillName : skills) { float skillExperience = Utils.getElementAsFloat( Utils.getElement(profileInfo, "experience_skill_" + (skillName.equals("social") ? "social2" : skillName)), 0 ); // Get the coop's social skill experience since social is a shared skill if (skillName.equals("social")) { - for (JsonObject coopProfile : coopProfileInfo) { + for (final JsonObject coopProfile : coopProfileInfo) { skillExperience += Utils.getElementAsFloat( Utils.getElement(coopProfile, "experience_skill_social2"), 0 @@ -1279,7 +1283,7 @@ public class ProfileViewer { levelingArray = Utils.getElement(leveling, "social").getAsJsonArray(); } - int maxLevel = + final int maxLevel = getCap(leveling, skillName) + ( skillName.equals("farming") @@ -1291,7 +1295,7 @@ public class ProfileViewer { // Skills API disabled? if (totalSkillXP <= 0) { - return null; + return Collections.emptyMap(); } out.put( @@ -1314,9 +1318,9 @@ public class ProfileViewer { ) ); - List dungeonClasses = Arrays.asList("healer", "tank", "mage", "archer", "berserk"); - for (String className : dungeonClasses) { - float classExperience = Utils.getElementAsFloat( + final List dungeonClasses = Arrays.asList("healer", "tank", "mage", "archer", "berserk"); + for (final String className : dungeonClasses) { + final float classExperience = Utils.getElementAsFloat( Utils.getElement(profileInfo, "dungeons.player_classes." + className + ".experience"), 0 ); @@ -1331,9 +1335,9 @@ public class ProfileViewer { ); } - List slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze"); - for (String slayerName : slayers) { - float slayerExperience = Utils.getElementAsFloat(Utils.getElement( + final List slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze"); + for (final String slayerName : slayers) { + final float slayerExperience = Utils.getElementAsFloat(Utils.getElement( profileInfo, "slayer_bosses." + slayerName + ".xp" ), 0); @@ -1349,64 +1353,64 @@ public class ProfileViewer { } public JsonObject getInventoryInfo(String profileName) { - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; if (profileName == null) profileName = latestProfile; if (inventoryCacheMap.containsKey(profileName)) return inventoryCacheMap.get(profileName); - String inv_armor_bytes = Utils.getElementAsString( + final String inv_armor_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "inv_armor.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String fishing_bag_bytes = Utils.getElementAsString( + final String fishing_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "fishing_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String quiver_bytes = Utils.getElementAsString( + final String quiver_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "quiver.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String ender_chest_contents_bytes = Utils.getElementAsString( + final String ender_chest_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "ender_chest_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); //Todo clean this up //Fake string is so for I loop works the same - String backpack_contents_json_fake = "fake should fix later"; - JsonObject backpack_contents_json = (JsonObject) Utils.getElement(profileInfo, "backpack_contents"); - JsonObject backpack_icons = (JsonObject) Utils.getElement(profileInfo, "backpack_icons"); - String personal_vault_contents_bytes = Utils.getElementAsString( + final String backpack_contents_json_fake = "fake should fix later"; + final JsonObject backpack_contents_json = (JsonObject) Utils.getElement(profileInfo, "backpack_contents"); + final JsonObject backpack_icons = (JsonObject) Utils.getElement(profileInfo, "backpack_icons"); + final String personal_vault_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "personal_vault_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String wardrobe_contents_bytes = Utils.getElementAsString( + final String wardrobe_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "wardrobe_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String potion_bag_bytes = Utils.getElementAsString( + final String potion_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "potion_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String inv_contents_bytes = Utils.getElementAsString( + final String inv_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "inv_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String talisman_bag_bytes = Utils.getElementAsString( + final String talisman_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "talisman_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String candy_inventory_contents_bytes = Utils.getElementAsString( + final String candy_inventory_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "candy_inventory_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - String equipment_contents_bytes = Utils.getElementAsString( + final String equipment_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "equippment_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - JsonObject inventoryInfo = new JsonObject(); + final JsonObject inventoryInfo = new JsonObject(); - String[] inv_names = new String[]{ + final String[] inv_names = new String[]{ "inv_armor", "fishing_bag", "quiver", @@ -1420,7 +1424,7 @@ public class ProfileViewer { "candy_inventory_contents", "equippment_contents", }; - String[] inv_bytes = new String[]{ + final String[] inv_bytes = new String[]{ inv_armor_bytes, fishing_bag_bytes, quiver_bytes, @@ -1436,26 +1440,26 @@ public class ProfileViewer { }; for (int i = 0; i < inv_bytes.length; i++) { try { - String bytes = inv_bytes[i]; + final String bytes = inv_bytes[i]; JsonArray contents = new JsonArray(); if (inv_names[i].equals("backpack_contents")) { - JsonObject temp = getBackpackData(backpack_contents_json, backpack_icons); + final JsonObject temp = getBackpackData(backpack_contents_json, backpack_icons); contents = (JsonArray) temp.get("contents"); inventoryInfo.add("backpack_sizes", temp.get("backpack_sizes")); } else { - NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( + final NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( new ByteArrayInputStream(Base64.getDecoder().decode(bytes)) ); - NBTTagList items = inv_contents_nbt.getTagList("i", 10); + final NBTTagList items = inv_contents_nbt.getTagList("i", 10); for (int j = 0; j < items.tagCount(); j++) { - JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + final JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); contents.add(item); } } inventoryInfo.add(inv_names[i], contents); - } catch (IOException e) { + } catch (final IOException e) { inventoryInfo.add(inv_names[i], new JsonArray()); } } @@ -1465,9 +1469,9 @@ public class ProfileViewer { return inventoryInfo; } - public JsonObject getBackpackData(JsonObject backpackContentsJson, JsonObject backpackIcons) { + public JsonObject getBackpackData(final JsonObject backpackContentsJson, final JsonObject backpackIcons) { if (backpackContentsJson == null || backpackIcons == null) { - JsonObject bundledReturn = new JsonObject(); + final JsonObject bundledReturn = new JsonObject(); bundledReturn.add("contents", new JsonArray()); bundledReturn.add("backpack_sizes", new JsonArray()); @@ -1477,10 +1481,13 @@ public class ProfileViewer { String[] backpackArray = new String[0]; //Create backpack array which sizes up - for (Map.Entry backpackIcon : backpackIcons.entrySet()) { + for (final Map.Entry backpackIcon : backpackIcons.entrySet()) { if (backpackIcon.getValue() instanceof JsonObject) { - JsonObject backpackData = (JsonObject) backpackContentsJson.get(backpackIcon.getKey()); - String bytes = Utils.getElementAsString(backpackData.get("data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); + final JsonObject backpackData = (JsonObject) backpackContentsJson.get(backpackIcon.getKey()); + final String bytes = Utils.getElementAsString( + backpackData.get("data"), + "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" + ); backpackArray = growArray(bytes, Integer.parseInt(backpackIcon.getKey()), backpackArray); } } @@ -1488,9 +1495,9 @@ public class ProfileViewer { //reduce backpack array to filter out not existent backpacks { String[] tempBackpackArray = new String[0]; - for (String s : backpackArray) { + for (final String s : backpackArray) { if (s != null) { - String[] veryTempBackpackArray = new String[tempBackpackArray.length + 1]; + final String[] veryTempBackpackArray = new String[tempBackpackArray.length + 1]; System.arraycopy(tempBackpackArray, 0, veryTempBackpackArray, 0, tempBackpackArray.length); veryTempBackpackArray[veryTempBackpackArray.length - 1] = s; @@ -1500,54 +1507,54 @@ public class ProfileViewer { backpackArray = tempBackpackArray; } - JsonArray backpackSizes = new JsonArray(); - JsonArray contents = new JsonArray(); + final JsonArray backpackSizes = new JsonArray(); + final JsonArray contents = new JsonArray(); - for (String backpack : backpackArray) { + for (final String backpack : backpackArray) { try { - NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( + final NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( new ByteArrayInputStream(Base64.getDecoder().decode(backpack)) ); - NBTTagList items = inv_contents_nbt.getTagList("i", 10); + final NBTTagList items = inv_contents_nbt.getTagList("i", 10); backpackSizes.add(new JsonPrimitive(items.tagCount())); for (int j = 0; j < items.tagCount(); j++) { - JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + final JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); contents.add(item); } - } catch (IOException ignored) { + } catch (final IOException ignored) { } } - JsonObject bundledReturn = new JsonObject(); + final JsonObject bundledReturn = new JsonObject(); bundledReturn.add("contents", contents); bundledReturn.add("backpack_sizes", backpackSizes); return bundledReturn; } - public String[] growArray(String bytes, int index, String[] oldArray) { - int newSize = Math.max(index + 1, oldArray.length); + public String[] growArray(final String bytes, final int index, final String[] oldArray) { + final int newSize = Math.max(index + 1, oldArray.length); - String[] newArray = new String[newSize]; + final String[] newArray = new String[newSize]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); newArray[index] = bytes; return newArray; } - public JsonObject getPetsInfo(String profileName) { - JsonObject profileInfo = getProfileInformation(profileName); + public JsonObject getPetsInfo(final String profileName) { + final JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; if (petsInfoMap.containsKey(profileName)) return petsInfoMap.get(profileName); - JsonObject petsInfo = new JsonObject(); - JsonElement petsElement = profileInfo.get("pets"); + final JsonObject petsInfo = new JsonObject(); + final JsonElement petsElement = profileInfo.get("pets"); if (petsElement != null && petsElement.isJsonArray()) { JsonObject activePet = null; - JsonArray pets = petsElement.getAsJsonArray(); + final JsonArray pets = petsElement.getAsJsonArray(); for (int i = 0; i < pets.size(); i++) { - JsonObject pet = pets.get(i).getAsJsonObject(); + final JsonObject pet = pets.get(i).getAsJsonObject(); if (pet.has("active") && pet.get("active").getAsBoolean()) { activePet = pet; break; @@ -1562,46 +1569,46 @@ public class ProfileViewer { } public JsonObject getCollectionInfo(String profileName) { - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; - JsonObject resourceCollectionInfo = getResourceCollectionInformation(); + final JsonObject resourceCollectionInfo = getResourceCollectionInformation(); if (resourceCollectionInfo == null) return null; if (profileName == null) profileName = latestProfile; if (collectionInfoMap.containsKey(profileName)) return collectionInfoMap.get(profileName); - List coopMembers = getCoopProfileInformation(profileName); - JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); - JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); - JsonObject fakeMember = new JsonObject(); + final List coopMembers = getCoopProfileInformation(profileName); + final JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); + final JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); + final JsonObject fakeMember = new JsonObject(); fakeMember.add("crafted_generators", crafted_generators_element); coopMembers.add(coopMembers.size(), fakeMember); - JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); + final JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); if (unlocked_coll_tiers_element == null || collectionInfoElement == null) { return null; } - JsonObject collectionInfo = new JsonObject(); - JsonObject collectionTiers = new JsonObject(); - JsonObject minionTiers = new JsonObject(); + final JsonObject collectionInfo = new JsonObject(); + final JsonObject collectionTiers = new JsonObject(); + final JsonObject minionTiers = new JsonObject(); JsonObject personalAmounts = new JsonObject(); - JsonObject totalAmounts = new JsonObject(); + final JsonObject totalAmounts = new JsonObject(); if (collectionInfoElement.isJsonObject()) { personalAmounts = collectionInfoElement.getAsJsonObject(); } - for (Map.Entry entry : personalAmounts.entrySet()) { + for (final Map.Entry entry : personalAmounts.entrySet()) { totalAmounts.addProperty(entry.getKey(), entry.getValue().getAsLong()); } - List coopProfiles = getCoopProfileInformation(profileName); + final List coopProfiles = getCoopProfileInformation(profileName); if (coopProfiles != null) { - for (JsonObject coopProfile : coopProfiles) { - JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); + for (final JsonObject coopProfile : coopProfiles) { + final JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); if (coopCollectionInfoElement != null && coopCollectionInfoElement.isJsonObject()) { - for (Map.Entry entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { - float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); + for (final Map.Entry entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { + final float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); totalAmounts.addProperty(entry.getKey(), existing + entry.getValue().getAsLong()); } } @@ -1609,34 +1616,36 @@ public class ProfileViewer { } if (unlocked_coll_tiers_element.isJsonArray()) { - JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); + final JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); for (int i = 0; i < unlocked_coll_tiers.size(); i++) { - String unlocked = unlocked_coll_tiers.get(i).getAsString(); + final String unlocked = unlocked_coll_tiers.get(i).getAsString(); - Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + final Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); if (matcher.find()) { - String tier_str = matcher.group(1); - int tier = Integer.parseInt(tier_str); - String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); + final String tier_str = matcher.group(1); + final int tier = Integer.parseInt(tier_str); + final String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); if (!collectionTiers.has(coll) || collectionTiers.get(coll).getAsInt() < tier) { collectionTiers.addProperty(coll, tier); } } } } - for (JsonObject current_member_info : coopMembers) { + for (final JsonObject current_member_info : coopMembers) { if ( !current_member_info.has("crafted_generators") || !current_member_info.get("crafted_generators").isJsonArray() ) continue; - JsonArray crafted_generators = Utils.getElement(current_member_info, "crafted_generators").getAsJsonArray(); + final JsonArray crafted_generators = Utils + .getElement(current_member_info, "crafted_generators") + .getAsJsonArray(); for (int j = 0; j < crafted_generators.size(); j++) { - String unlocked = crafted_generators.get(j).getAsString(); - Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + final String unlocked = crafted_generators.get(j).getAsString(); + final Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); if (matcher.find()) { - String tierString = matcher.group(1); - int tier = Integer.parseInt(tierString); - String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); + final String tierString = matcher.group(1); + final int tier = Integer.parseInt(tierString); + final String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); if (!minionTiers.has(coll) || minionTiers.get(coll).getAsInt() < tier) { minionTiers.addProperty(coll, tier); } @@ -1644,24 +1653,24 @@ public class ProfileViewer { } } - JsonObject maxAmount = new JsonObject(); - JsonObject updatedCollectionTiers = new JsonObject(); - for (Map.Entry totalAmountsEntry : totalAmounts.entrySet()) { - String collName = totalAmountsEntry.getKey(); - int collTier = (int) Utils.getElementAsFloat(collectionTiers.get(collName), 0); + final JsonObject maxAmount = new JsonObject(); + final JsonObject updatedCollectionTiers = new JsonObject(); + for (final Map.Entry totalAmountsEntry : totalAmounts.entrySet()) { + final String collName = totalAmountsEntry.getKey(); + final int collTier = (int) Utils.getElementAsFloat(collectionTiers.get(collName), 0); - int currentAmount = (int) Utils.getElementAsFloat(totalAmounts.get(collName), 0); + final int currentAmount = (int) Utils.getElementAsFloat(totalAmounts.get(collName), 0); if (currentAmount > 0) { - for (Map.Entry resourceEntry : resourceCollectionInfo.entrySet()) { - JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers"); + for (final Map.Entry resourceEntry : resourceCollectionInfo.entrySet()) { + final JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers"); if (tiersElement != null && tiersElement.isJsonArray()) { - JsonArray tiers = tiersElement.getAsJsonArray(); + final JsonArray tiers = tiersElement.getAsJsonArray(); int maxTierAcquired = -1; int maxAmountRequired = -1; for (int i = 0; i < tiers.size(); i++) { - JsonObject tierInfo = tiers.get(i).getAsJsonObject(); - int tier = tierInfo.get("tier").getAsInt(); - int amountRequired = tierInfo.get("amountRequired").getAsInt(); + final JsonObject tierInfo = tiers.get(i).getAsJsonObject(); + final int tier = tierInfo.get("tier").getAsInt(); + final int amountRequired = tierInfo.get("amountRequired").getAsInt(); if (currentAmount >= amountRequired) { maxTierAcquired = tier; } @@ -1676,7 +1685,7 @@ public class ProfileViewer { } } - for (Map.Entry collectionTiersEntry : updatedCollectionTiers.entrySet()) { + for (final Map.Entry collectionTiersEntry : updatedCollectionTiers.entrySet()) { collectionTiers.add(collectionTiersEntry.getKey(), collectionTiersEntry.getValue()); } @@ -1691,39 +1700,42 @@ public class ProfileViewer { return collectionInfo; } - public PlayerStats.Stats getPassiveStats(String profileName) { + public PlayerStats.Stats getPassiveStats(final String profileName) { if (passiveStats.get(profileName) != null) return passiveStats.get(profileName); - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; - PlayerStats.Stats passiveStats = PlayerStats.getPassiveBonuses(getSkyblockInfo(profileName), profileInfo); + final PlayerStats.Stats passivePlayerStats = PlayerStats.getPassiveBonuses( + getSkyblockInfo(profileName), + profileInfo + ); - if (passiveStats != null) { - passiveStats.add(PlayerStats.getBaseStats()); + if (passivePlayerStats != null) { + passivePlayerStats.add(PlayerStats.getBaseStats()); } - this.passiveStats.put(profileName, passiveStats); + passiveStats.put(profileName, passivePlayerStats); - return passiveStats; + return passivePlayerStats; } - public PlayerStats.Stats getStats(String profileName) { + public PlayerStats.Stats getStats(final String profileName) { if (stats.get(profileName) != null) return stats.get(profileName); - JsonObject profileInfo = getProfileInformation(profileName); + final JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) { return null; } - PlayerStats.Stats stats = PlayerStats.getStats( + final PlayerStats.Stats playerStats = PlayerStats.getStats( getSkyblockInfo(profileName), getInventoryInfo(profileName), getCollectionInfo(profileName), getPetsInfo(profileName), profileInfo ); - if (stats == null) return null; - this.stats.put(profileName, stats); - return stats; + if (playerStats == null) return null; + stats.put(profileName, playerStats); + return playerStats; } public String getUuid() { -- cgit From a683745aad92c190b64ef269ca7b15cc40e54778 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 3 Jan 2023 13:51:23 +0100 Subject: Meet Your New Dungeon Group Members in Seconds! (#529) * This feature allows players to view the profile of another player who has joined their dungeon group through the party finder by hovering and clicking on the chat message announcing the player's arrival. * regex on top * Constants stay upper the case. Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../notenoughupdates/listener/ChatListener.java | 52 ++++++++++++++++------ .../options/seperateSections/Misc.java | 8 ++++ 2 files changed, 46 insertions(+), 14 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java index 54c378ec..31930b01 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/ChatListener.java @@ -38,6 +38,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChatStyle; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraft.util.StringUtils; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -54,12 +55,15 @@ import static io.github.moulberry.notenoughupdates.overlays.SlayerOverlay.timeSi import static io.github.moulberry.notenoughupdates.overlays.SlayerOverlay.timeSinceLastBoss2; public class ChatListener { + private final NotEnoughUpdates neu; - private static final Pattern SLAYER_XP = Pattern.compile( + + private static final Pattern SLAYER_EXP_PATTERN = Pattern.compile( " (Spider|Zombie|Wolf|Enderman|Blaze) Slayer LVL (\\d) - (?:Next LVL in ([\\d,]+) XP!|LVL MAXED OUT!)"); + private static final Pattern SKY_BLOCK_LEVEL_PATTERN = Pattern.compile("\\[(\\d{1,4})\\] .*"); + private final Pattern PARTY_FINDER_PATTERN = Pattern.compile("§dParty Finder §r§f> (.*)§ejoined the dungeon group!"); - private static final Pattern SKYBLOCK_LVL_MESSAGE = Pattern.compile("\\[(\\d{1,4})\\] .*"); - AtomicBoolean missingRecipe = new AtomicBoolean(false); + private AtomicBoolean missingRecipe = new AtomicBoolean(false); public ChatListener(NotEnoughUpdates neu) { this.neu = neu; @@ -147,15 +151,7 @@ public class ChatListener { if (NotEnoughUpdates.INSTANCE.config.misc.replaceSocialOptions1 == 1) { - ChatStyle pvClickStyle = Utils.createClickStyle( - ClickEvent.Action.RUN_COMMAND, - "/pv " + username, - "" + EnumChatFormatting.YELLOW + "Click to open " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + - username + EnumChatFormatting.RESET + EnumChatFormatting.YELLOW + "'s profile in " + - EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD + "NEU's" + EnumChatFormatting.RESET + - EnumChatFormatting.YELLOW + " profile viewer." - ); - + ChatStyle pvClickStyle = getPVChatStyle(username); if (partyOrGuildChat) { chatComponent.getSiblings().get(0).setChatStyle(pvClickStyle); } else { @@ -183,6 +179,17 @@ public class ChatListener { return chatComponent; } + private static ChatStyle getPVChatStyle(String username) { + return Utils.createClickStyle( + ClickEvent.Action.RUN_COMMAND, + "/pv " + username, + "" + EnumChatFormatting.YELLOW + "Click to open " + EnumChatFormatting.AQUA + EnumChatFormatting.BOLD + + username + EnumChatFormatting.RESET + EnumChatFormatting.YELLOW + "'s profile in " + + EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD + "NEU's" + EnumChatFormatting.RESET + + EnumChatFormatting.YELLOW + " profile viewer." + ); + } + /** * 1) When receiving "You are playing on profile" messages, will set the current profile. * 2) When a /viewrecipe command fails (i.e. player does not have recipe unlocked, will open the custom recipe GUI) @@ -197,13 +204,16 @@ public class ChatListener { return; } else if (e.type == 0) { e.message = replaceSocialControlsWithPV(e.message); + if (NotEnoughUpdates.INSTANCE.config.misc.dungeonGroupsPV) { + e.message = dungeonPartyJoinPV(e.message); + } } DungeonWin.onChatMessage(e); String r = null; String unformatted = Utils.cleanColour(e.message.getUnformattedText()); - Matcher matcher = SLAYER_XP.matcher(unformatted); + Matcher matcher = SLAYER_EXP_PATTERN.matcher(unformatted); if (unformatted.startsWith("You are playing on profile: ")) { SBInfo.getInstance().setCurrentProfile(unformatted .substring("You are playing on profile: ".length()) @@ -298,7 +308,7 @@ public class ChatListener { " You've earned a Crystal Loot Bundle!")) OverlayManager.crystalHollowOverlay.message(unformatted); - Matcher LvlMatcher = SKYBLOCK_LVL_MESSAGE.matcher(unformatted); + Matcher LvlMatcher = SKY_BLOCK_LEVEL_PATTERN.matcher(unformatted); if (LvlMatcher.matches()) { if (Integer.parseInt(LvlMatcher.group(1)) < NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel && NotEnoughUpdates.INSTANCE.config.misc.filterChatLevel != 0) { @@ -317,4 +327,18 @@ public class ChatListener { if (unformatted.equals("ENDER NODE! You found Endermite Nest!")) EnderNodes.displayEndermiteNotif(); } + + private IChatComponent dungeonPartyJoinPV(IChatComponent message) { + String text = message.getFormattedText(); + Matcher matcher = PARTY_FINDER_PATTERN.matcher(text); + + if (matcher.find()) { + String name = StringUtils.stripControlCodes(matcher.group(1)).trim(); + ChatComponentText componentText = new ChatComponentText(text); + componentText.setChatStyle(getPVChatStyle(name)); + return componentText; + } else { + return message; + } + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 11ace314..62f5a81a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -295,4 +295,12 @@ public class Misc { @ConfigEditorBoolean public boolean abiphoneFavourites = true; + @Expose + @ConfigOption( + name = "Dungeon Groups PV", + desc = "View another player's profile by clicking on the chat message when they join in a dungeon group." + ) + @ConfigEditorBoolean + public boolean dungeonGroupsPV = true; + } -- cgit From dea9a94fb430f4c4a7ab2a8e9d642780d71423e3 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Wed, 4 Jan 2023 01:24:26 +1100 Subject: Hotkeys for wardrobe slots (#494) * Hotkeys for wardrobe slots, e.g when in the wardrobe, pressing 1 will select the first wardrobe slot * fix wardrobe keybinds not updating * fix up some stuff * i suppose * I should learn more kotlin * considered --- .../notenoughupdates/NotEnoughUpdates.java | 3 +- .../miscfeatures/WardrobeMouseButtons.kt | 59 ++++++++++ .../notenoughupdates/options/NEUConfig.java | 10 +- .../options/seperateSections/WardrobeKeybinds.java | 126 +++++++++++++++++++++ .../moulberry/notenoughupdates/util/Utils.java | 7 ++ 5 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index bc2666d3..f10db528 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -63,6 +63,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.PowerStoneStatsDisplay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; +import io.github.moulberry.notenoughupdates.miscfeatures.WardrobeMouseButtons; import io.github.moulberry.notenoughupdates.miscfeatures.WitherCloakChanger; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; @@ -83,7 +84,6 @@ import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.FuelBar; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewer; -import io.github.moulberry.notenoughupdates.recipes.KatRecipe; import io.github.moulberry.notenoughupdates.recipes.RecipeGenerator; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.SBInfo; @@ -349,6 +349,7 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(FrozenTreasuresHighlighter.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneFavourites.getInstance()); MinecraftForge.EVENT_BUS.register(AbiphoneContactHelper.getInstance()); + MinecraftForge.EVENT_BUS.register(new WardrobeMouseButtons()); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { IReloadableResourceManager manager = (IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt new file mode 100644 index 00000000..4e99f5a7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/WardrobeMouseButtons.kt @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ +package io.github.moulberry.notenoughupdates.miscfeatures + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import io.github.moulberry.notenoughupdates.core.config.KeybindHelper +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class WardrobeMouseButtons { + + private val keybinds: List get() = listOf( + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot1, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot2, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot3, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot4, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot5, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot6, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot7, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot8, + NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.wardrobeSlot9, + ) + private var lastClick = -1L + + @SubscribeEvent + fun onGui(event: GuiScreenEvent) { + if (!NotEnoughUpdates.INSTANCE.config.wardrobeKeybinds.enableWardrobeKeybinds) return + val gui = event.gui as? GuiChest ?: return + if (!Utils.getOpenChestName().contains("Wardrobe")) return + + for (i in keybinds.indices) { + if (KeybindHelper.isKeyDown(keybinds[i])) { + if (System.currentTimeMillis() - lastClick > 300) { + Utils.sendLeftMouseClick(gui.inventorySlots.windowId, 36 + i) + lastClick = System.currentTimeMillis() + } + break + } + } + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index b5237a46..129f973b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -34,7 +34,6 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiEnchantColour; import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor; import io.github.moulberry.notenoughupdates.miscgui.NEUOverlayPlacements; import io.github.moulberry.notenoughupdates.options.customtypes.NEUDebugFlag; -import io.github.moulberry.notenoughupdates.options.seperateSections.WorldConfig; import io.github.moulberry.notenoughupdates.options.seperateSections.AHGraph; import io.github.moulberry.notenoughupdates.options.seperateSections.AHTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.AccessoryBag; @@ -66,6 +65,8 @@ import io.github.moulberry.notenoughupdates.options.seperateSections.StorageGUI; import io.github.moulberry.notenoughupdates.options.seperateSections.Toolbar; import io.github.moulberry.notenoughupdates.options.seperateSections.TooltipTweaks; import io.github.moulberry.notenoughupdates.options.seperateSections.TradeMenu; +import io.github.moulberry.notenoughupdates.options.seperateSections.WardrobeKeybinds; +import io.github.moulberry.notenoughupdates.options.seperateSections.WorldConfig; import io.github.moulberry.notenoughupdates.overlays.MiningOverlay; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -358,6 +359,13 @@ public class NEUConfig extends Config { ) public AHGraph ahGraph = new AHGraph(); + @Expose + @Category( + name = "Wardrobe Keybinds", + desc = "Keybinds for your wardrobe" + ) + public WardrobeKeybinds wardrobeKeybinds = new WardrobeKeybinds(); + @Expose @Category( name = "Accessory Bag Overlay", diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java new file mode 100644 index 00000000..48d1b434 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/WardrobeKeybinds.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.options.seperateSections; + +import com.google.gson.annotations.Expose; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigAccordionId; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorAccordion; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorKeybind; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; +import org.lwjgl.input.Keyboard; + +public class WardrobeKeybinds { + + @Expose + @ConfigOption( + name = "Enable Wardrobe Keybinds", + desc = "Lets you use your number keys to quickly change your wardrobe" + ) + @ConfigEditorBoolean + public boolean enableWardrobeKeybinds = false; + + @ConfigOption( + name = "Wardrobe Keybinds", + desc = "" + ) + @ConfigEditorAccordion(id = 2) + public boolean wardrobeKeybindAccordion = false; + @Expose + @ConfigOption( + name = "Slot 1", + desc = "Keybind to toggle the first set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_1) + @ConfigAccordionId(id = 2) + public int wardrobeSlot1 = Keyboard.KEY_1; + + @Expose + @ConfigOption( + name = "Slot 2", + desc = "Keybind to toggle the second set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_2) + @ConfigAccordionId(id = 2) + public int wardrobeSlot2 = Keyboard.KEY_2; + + @Expose + @ConfigOption( + name = "Slot 3", + desc = "Keybind to toggle the third set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_3) + @ConfigAccordionId(id = 2) + public int wardrobeSlot3 = Keyboard.KEY_3; + + @Expose + @ConfigOption( + name = "Slot 4", + desc = "Keybind to toggle the fourth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_4) + @ConfigAccordionId(id = 2) + public int wardrobeSlot4 = Keyboard.KEY_4; + + @Expose + @ConfigOption( + name = "Slot 5", + desc = "Keybind to toggle the fifth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_5) + @ConfigAccordionId(id = 2) + public int wardrobeSlot5 = Keyboard.KEY_5; + + @Expose + @ConfigOption( + name = "Slot 6", + desc = "Keybind to toggle the sixth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_6) + @ConfigAccordionId(id = 2) + public int wardrobeSlot6 = Keyboard.KEY_6; + + @Expose + @ConfigOption( + name = "Slot 7", + desc = "Keybind to toggle the seventh set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_7) + @ConfigAccordionId(id = 2) + public int wardrobeSlot7 = Keyboard.KEY_7; + + @Expose + @ConfigOption( + name = "Slot 8", + desc = "Keybind to toggle the eighth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_8) + @ConfigAccordionId(id = 2) + public int wardrobeSlot8 = Keyboard.KEY_8; + + @Expose + @ConfigOption( + name = "Slot 9", + desc = "Keybind to toggle the ninth set in your wardrobe" + ) + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_9) + @ConfigAccordionId(id = 2) + public int wardrobeSlot9 = Keyboard.KEY_9; +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 0ea1dafb..571a43f9 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -2057,4 +2057,11 @@ public class Utils { } } } + + public static void sendLeftMouseClick(int windowId, int slot) { + Minecraft.getMinecraft().playerController.windowClick( + windowId, + slot, 0, 0, Minecraft.getMinecraft().thePlayer + ); + } } -- cgit From c6e0f61c412adc1927ccff21d3e58f83808de215 Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Thu, 5 Jan 2023 23:42:35 +1100 Subject: Replace help button with button to toggle inventory searching (#539) * add button to toggle search mode * Its a bit better Co-authored-by: jani270 --- .../github/moulberry/notenoughupdates/NEUOverlay.java | 18 ++++++++---------- .../options/seperateSections/Toolbar.java | 6 +++--- .../assets/notenoughupdates/search_mode_button.png | Bin 0 -> 644 bytes 3 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/assets/notenoughupdates/search_mode_button.png (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 686f6a27..7159ef89 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -88,7 +88,6 @@ import java.awt.*; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -113,6 +112,7 @@ public class NEUOverlay extends Gui { "notenoughupdates:supersecretassets/lunar.png"); private static final ResourceLocation SEARCH_BAR = new ResourceLocation("notenoughupdates:search_bar.png"); private static final ResourceLocation SEARCH_BAR_GOLD = new ResourceLocation("notenoughupdates:search_bar_gold.png"); + private static final ResourceLocation SEARCH_MODE_BUTTON = new ResourceLocation("notenoughupdates:search_mode_button.png"); private final NEUManager manager; @@ -429,7 +429,7 @@ public class NEUOverlay extends Gui { }; } - private MBGuiElement createHelpButton(NEUOverlay overlay) { + private MBGuiElement createSearchModeButton() { return new MBGuiElement() { @Override public int getWidth() { @@ -446,14 +446,12 @@ public class NEUOverlay extends Gui { @Override public void mouseClick(float x, float y, int mouseX, int mouseY) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableHelpButton) { + if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableSearchModeButton) { return; } if (Mouse.getEventButtonState()) { - //displayInformationPane(HTMLInfoPane.createFromWikiUrl(overlay, manager, "Help", - // "https://moulberry.github.io/files/neu_help.html")); - //Minecraft.getMinecraft().displayGuiScreen(new HelpGUI()); - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neuhelp"); + searchMode = !searchMode; + lastSearchMode = System.currentTimeMillis(); Utils.playPressSound(); } } @@ -466,7 +464,7 @@ public class NEUOverlay extends Gui { int paddingUnscaled = getPaddingUnscaled(); int searchYSize = getSearchBarYSize(); - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableHelpButton) { + if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableSearchModeButton) { return; } @@ -476,7 +474,7 @@ public class NEUOverlay extends Gui { searchYSize + paddingUnscaled * 2, searchYSize + paddingUnscaled * 2, GL11.GL_NEAREST ); - Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.help); + Minecraft.getMinecraft().getTextureManager().bindTexture(SEARCH_MODE_BUTTON); GlStateManager.color(1f, 1f, 1f, 1f); Utils.drawTexturedRect((int) x + paddingUnscaled, (int) y + paddingUnscaled, getSearchBarYSize(), getSearchBarYSize() @@ -621,7 +619,7 @@ public class NEUOverlay extends Gui { List children = Lists.newArrayList( createSettingsButton(this), createSearchBar(), - createHelpButton(this) + createSearchModeButton() ); return new MBGuiGroupAligned(children, false) { public int getPadding() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java index 2d88544e..d8fe91d5 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Toolbar.java @@ -64,12 +64,12 @@ public class Toolbar { @Expose @ConfigOption( - name = "Show a help settings button", - desc = "Show quick settings button in the NEU toolbar" + name = "Show an inventory search button", + desc = "Show button to enable inventory searching in the NEU toolbar" ) @ConfigEditorBoolean @ConfigAccordionId(id = 0) - public boolean enableHelpButton = true; + public boolean enableSearchModeButton = true; @Expose @ConfigOption( diff --git a/src/main/resources/assets/notenoughupdates/search_mode_button.png b/src/main/resources/assets/notenoughupdates/search_mode_button.png new file mode 100644 index 00000000..416d26f7 Binary files /dev/null and b/src/main/resources/assets/notenoughupdates/search_mode_button.png differ -- cgit From 378c22c7cd98fba1f1bf1c2dd53f560deca29619 Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Wed, 11 Jan 2023 19:25:38 +0100 Subject: Fix skin downloads on some older java versions (#537) --- .../hooks/ThreadDownloadImageHook.java | 40 +++++++++++++++++ .../mixins/MixinThreadDownloadImageData.java | 48 +++++++++++++++++++++ .../mixins/MixinThreadDownloadImageDataThread.java | 46 ++++++++++++++++++++ .../options/seperateSections/Misc.java | 8 ++++ .../moulberry/notenoughupdates/util/ApiUtil.java | 7 ++- src/main/resources/mixins.notenoughupdates.json | 4 +- src/main/resources/neukeystore.jks | Bin 101958 -> 104393 bytes src/main/resources/neukeystore.txt | 2 + 8 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageDataThread.java (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java b/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java new file mode 100644 index 00000000..4fa57360 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/hooks/ThreadDownloadImageHook.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.hooks; + +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.ApiUtil; + +import javax.net.ssl.HttpsURLConnection; +import java.net.HttpURLConnection; + +public class ThreadDownloadImageHook { + public static void hookThreadImageConnection(HttpURLConnection connection) { + if ((connection instanceof HttpsURLConnection) && NotEnoughUpdates.INSTANCE.config.misc.fixSteveSkulls) { + ApiUtil.patchHttpsRequest((HttpsURLConnection) connection); + } + } + + public static String hookThreadImageLink(String originalLink) { + if (!NotEnoughUpdates.INSTANCE.config.misc.fixSteveSkulls || originalLink == null) + return originalLink; + return originalLink.replace("http://", "https://"); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java new file mode 100644 index 00000000..c6d25a9e --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageData.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.hooks.ThreadDownloadImageHook; +import net.minecraft.client.renderer.ThreadDownloadImageData; +import org.spongepowered.asm.lib.Opcodes; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ThreadDownloadImageData.class) +public class MixinThreadDownloadImageData { + @Mutable + @Shadow + @Final + private String imageUrl; + + @Redirect( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/renderer/ThreadDownloadImageData;imageUrl:Ljava/lang/String;", + opcode = Opcodes.PUTFIELD)) + public void useHttpsDownloadLinks(ThreadDownloadImageData instance, String value) { + this.imageUrl = ThreadDownloadImageHook.hookThreadImageLink(value); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageDataThread.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageDataThread.java new file mode 100644 index 00000000..aea52378 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinThreadDownloadImageDataThread.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Linnea Gräf + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.mixins; + +import io.github.moulberry.notenoughupdates.hooks.ThreadDownloadImageHook; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.net.HttpURLConnection; + +@Mixin(targets = "net.minecraft.client.renderer.ThreadDownloadImageData$1") +public class MixinThreadDownloadImageDataThread { + + @Inject( + method = "run", + at = @At( + value = "INVOKE", + target = "Ljava/net/HttpURLConnection;setDoOutput(Z)V" + ), + locals = LocalCapture.CAPTURE_FAILSOFT + ) + public void patchHttpConnection(CallbackInfo ci, HttpURLConnection httpURLConnection) { + ThreadDownloadImageHook.hookThreadImageConnection(httpURLConnection); + } + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java index 62f5a81a..b72610b8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Misc.java @@ -55,6 +55,14 @@ public class Misc { @ConfigEditorBoolean public boolean streamerMode = false; + @Expose + @ConfigOption( + name = "Fix Steve skulls", + desc = "Fix some skulls and skins not downloading on old java versions. May require restart." + ) + @ConfigEditorBoolean + public boolean fixSteveSkulls = true; + @ConfigOption( name = "Fairy Soul Waypoints", desc = "" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index e84c1c43..c86ac84f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -162,8 +162,7 @@ public class ApiUtil { try { conn = url.openConnection(); if (conn instanceof HttpsURLConnection && ctx != null) { - HttpsURLConnection sslConn = (HttpsURLConnection) conn; - sslConn.setSSLSocketFactory(ctx.getSocketFactory()); + patchHttpsRequest((HttpsURLConnection) conn); } if (conn instanceof HttpURLConnection) { ((HttpURLConnection) conn).setRequestMethod(method); @@ -221,6 +220,10 @@ public class ApiUtil { } + public static void patchHttpsRequest(HttpsURLConnection connection) { + connection.setSSLSocketFactory(ctx.getSocketFactory()); + } + public Request request() { return new Request(); } diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 028a9e65..d080d7f5 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -54,6 +54,8 @@ "AccessorMinecraft", "MixinEntityChargedCreeper", "MixinGuiEditSign", - "MixinGuiTextField" + "MixinGuiTextField", + "MixinThreadDownloadImageData", + "MixinThreadDownloadImageDataThread" ] } diff --git a/src/main/resources/neukeystore.jks b/src/main/resources/neukeystore.jks index 3a5a23b6..b71185af 100644 Binary files a/src/main/resources/neukeystore.jks and b/src/main/resources/neukeystore.jks differ diff --git a/src/main/resources/neukeystore.txt b/src/main/resources/neukeystore.txt index 5616f69b..a64accd0 100644 --- a/src/main/resources/neukeystore.txt +++ b/src/main/resources/neukeystore.txt @@ -13,5 +13,7 @@ Please keep a list of added aliases below: - ISRGROOTX1 (Let's Encrypt) - ISRGROOTX2 (Let's Encrypt) + - MSRSAROOT (Microsoft Root CA 2017) + - DIGIROOTG2 (DigiCert Global Root G2) -- cgit From 49c9345807ed4d13d035e27a0665e2f7c63b0c9e Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Wed, 11 Jan 2023 22:03:47 +0100 Subject: Optional Oneconfig support (#401) --- build.gradle.kts | 32 +++- gradle.properties | 2 + oneconfigquarantine/build.gradle.kts | 45 +++++ settings.gradle.kts | 1 + .../moulberry/notenoughupdates/BuildFlags.java | 1 + .../notenoughupdates/NotEnoughUpdates.java | 3 + .../notenoughupdates/core/ChromaColour.java | 7 +- .../notenoughupdates/core/GuiElementBoolean.java | 24 +-- .../notenoughupdates/core/GuiElementColour.java | 49 +++-- .../core/config/gui/GuiOptionEditorAccordion.java | 8 +- .../core/config/gui/GuiOptionEditorBoolean.java | 2 +- .../core/config/gui/GuiOptionEditorColour.java | 13 +- .../core/config/gui/GuiOptionEditorKeybind.java | 20 +- .../core/config/gui/GuiOptionEditorSlider.java | 50 ++--- .../core/config/gui/GuiOptionEditorText.java | 2 + .../core/config/struct/ConfigProcessor.java | 2 +- .../dungeons/GuiDungeonMapEditor.java | 4 +- .../loader/NEUDelegatingTweaker.java | 38 ++-- .../notenoughupdates/miscgui/GuiItemCustomize.java | 19 +- .../oneconfig/IOneConfigCompat.java | 52 ++++++ .../notenoughupdates/options/NEUConfig.java | 8 +- .../notenoughupdates/profileviewer/ExtraPage.java | 2 +- .../compat/oneconfig/OneConfigCompat.java | 42 +++++ .../compat/oneconfig/OneFancyColor.java | 113 ++++++++++++ .../compat/oneconfig/OneFancyKeybind.java | 52 ++++++ .../compat/oneconfig/OneMoulConfig.java | 201 +++++++++++++++++++++ .../compat/oneconfig/OneWrappedKeyBind.java | 58 ++++++ .../compat/oneconfig/WrappedConfigSlider.java | 52 ++++++ 28 files changed, 768 insertions(+), 134 deletions(-) create mode 100644 oneconfigquarantine/build.gradle.kts create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneConfigCompat.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyColor.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyKeybind.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneMoulConfig.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneWrappedKeyBind.java create mode 100644 src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/WrappedConfigSlider.java (limited to 'src/main/java/io') diff --git a/build.gradle.kts b/build.gradle.kts index 04207cf2..e9e769a8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -75,6 +75,7 @@ repositories { maven("https://repo.spongepowered.org/maven/") maven("https://pkgs.dev.azure.com/djtheredstoner/DevAuth/_packaging/public/maven/v1") maven("https://jitpack.io") + maven("https://repo.polyfrost.cc/releases") } lombok { @@ -86,8 +87,12 @@ val shadowImplementation by configurations.creating { configurations.implementation.get().extendsFrom(this) } +val shadowOnly by configurations.creating { + +} + val shadowApi by configurations.creating { - configurations.implementation.get().extendsFrom(this) + configurations.api.get().extendsFrom(this) } val devEnv by configurations.creating { @@ -101,6 +106,14 @@ val kotlinDependencies by configurations.creating { configurations.implementation.get().extendsFrom(this) } +val oneconfigQuarantineSourceSet = sourceSets.create("oneconfig") { + java { + srcDir(layout.projectDirectory.dir("src/main/oneconfig")) + } + kotlin { + } +} + dependencies { implementation("org.projectlombok:lombok:1.18.22") minecraft("com.mojang:minecraft:1.8.9") @@ -108,6 +121,16 @@ dependencies { forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + if (project.findProperty("neu.buildflags.oneconfig") == "true") { + shadowOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-alpha+") // Should be included in jar + runtimeOnly("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-alpha+") // Should be included in jar + } + + "oneconfigImplementation"(sourceSets.main.get().output) + "oneconfigImplementation"(sourceSets.main.get().compileClasspath) + "oneconfigCompileOnly"(project(":oneconfigquarantine", configuration = "namedElements")) + "runtimeOnly"(oneconfigQuarantineSourceSet.output) + // Please keep this version in sync with KotlinLoadingTweaker implementation(enforcedPlatform("org.jetbrains.kotlin:kotlin-bom:1.7.21")) kotlinDependencies(kotlin("stdlib")) @@ -141,6 +164,10 @@ tasks.named("test") { useJUnitPlatform() } +tasks.named("jar", Jar::class) { + from(oneconfigQuarantineSourceSet.output) +} + tasks.withType(Jar::class) { archiveBaseName.set("NotEnoughUpdates") manifest.attributes.run { @@ -174,8 +201,8 @@ val kotlinDependencyCollectionJar by tasks.creating(Zip::class) { tasks.shadowJar { archiveClassifier.set("dep-dev") + configurations = listOf(shadowImplementation, shadowApi, shadowOnly) archiveBaseName.set("NotEnoughUpdates") - configurations = listOf(shadowImplementation, shadowApi) exclude("**/module-info.class", "LICENSE.txt") dependencies { exclude { @@ -183,6 +210,7 @@ tasks.shadowJar { listOf("logback-classic", "commons-logging", "commons-codec", "logback-core") } } + from(oneconfigQuarantineSourceSet.output) from(kotlinDependencyCollectionJar) dependsOn(kotlinDependencyCollectionJar) fun relocate(name: String) = relocate(name, "io.github.moulberry.notenoughupdates.deps.$name") diff --git a/gradle.properties b/gradle.properties index f596b2d7..0009739e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,3 +4,5 @@ loom.platform=forge # See BuildFlags.java for usages of these values. # Build with Pronouns in PV by default # neu.buildflags.pronouns=true +# Build with Oneconfig support +# neu.buildflags.oneconfig=true diff --git a/oneconfigquarantine/build.gradle.kts b/oneconfigquarantine/build.gradle.kts new file mode 100644 index 00000000..32bc3b7c --- /dev/null +++ b/oneconfigquarantine/build.gradle.kts @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +/** + * This subproject is a stub project to hold oneconfig dependencies, to prevent those dependencies bleeding over into + * our the normal NEU codebase. Usually this could be done using just another source set, however due to using legacy + * arch loom (for now!!!!) we cannot depend on remapped dependencies from only in one source set. + * */ +plugins { + java + id("gg.essential.loom") + id("dev.architectury.architectury-pack200") +} + +loom.forge.pack200Provider.set(dev.architectury.pack200.java.Pack200Adapter()) + +repositories { + mavenCentral() + maven("https://repo.polyfrost.cc/releases") +} + +dependencies { + minecraft("com.mojang:minecraft:1.8.9") + mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") + forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + + modApi("cc.polyfrost:oneconfig-1.8.9-forge:0.1.0-alpha+") // Don't you just love 0.1.0-alpha+ +} + diff --git a/settings.gradle.kts b/settings.gradle.kts index 408d0f75..a910edd3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,4 +39,5 @@ pluginManagement { } } +include("oneconfigquarantine") rootProject.name = "NotEnoughUpdates" diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java index d997d980..2091496d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java @@ -50,6 +50,7 @@ public class BuildFlags { } public static final boolean ENABLE_PRONOUNS_IN_PV_BY_DEFAULT = getBuildFlag("pronouns"); + public static final boolean ENABLE_ONECONFIG_COMPAT_LAYER = getBuildFlag("oneconfig"); private static class Holder { static Map ALL_FLAGS = new HashMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index f10db528..d6ae6219 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -79,6 +79,7 @@ import io.github.moulberry.notenoughupdates.miscgui.SignCalculator; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; +import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.FuelBar; @@ -294,6 +295,8 @@ public class NotEnoughUpdates { if (config.mining.powderGrindingTrackerResetMode == 2) OverlayManager.powderGrindingOverlay.load(); + IOneConfigCompat.getInstance().ifPresent(it -> it.initConfig(config, this::saveConfig)); + MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(new RecipeGenerator(this)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java index 05a9a65e..fb7b2abe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java @@ -38,7 +38,8 @@ public class ChromaColour { return sb.toString(); } - private static int[] decompose(String csv) { + @Deprecated + public static int[] decompose(String csv) { String[] split = csv.split(":"); int[] arr = new int[split.length]; @@ -68,6 +69,10 @@ public class ChromaColour { return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; } + public static int getSpeedForSeconds(float seconds) { + return (int) (255 - (seconds - MIN_CHROMA_SECS) * 254f / (MAX_CHROMA_SECS - MIN_CHROMA_SECS)); + } + private static final int MIN_CHROMA_SECS = 1; private static final int MAX_CHROMA_SECS = 60; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java index 11547aaa..ab176933 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java @@ -28,11 +28,12 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import java.util.function.Consumer; +import java.util.function.Supplier; public class GuiElementBoolean extends GuiElement { public int x; public int y; - private boolean value; + private Supplier value; private final int clickRadius; private final Consumer toggleCallback; @@ -43,20 +44,20 @@ public class GuiElementBoolean extends GuiElement { private static final int xSize = 48; private static final int ySize = 14; - public GuiElementBoolean(int x, int y, boolean value, Consumer toggleCallback) { + public GuiElementBoolean(int x, int y, Supplier value, Consumer toggleCallback) { this(x, y, value, 0, toggleCallback); } - public GuiElementBoolean(int x, int y, boolean value, int clickRadius, Consumer toggleCallback) { + public GuiElementBoolean(int x, int y, Supplier value, int clickRadius, Consumer toggleCallback) { this.x = x; this.y = y; this.value = value; - this.previewValue = value; + this.previewValue = value.get(); this.clickRadius = clickRadius; this.toggleCallback = toggleCallback; this.lastMillis = System.currentTimeMillis(); - if (value) animation = 36; + if (previewValue) animation = 36; } @Override @@ -70,7 +71,7 @@ public class GuiElementBoolean extends GuiElement { long deltaMillis = currentMillis - lastMillis; lastMillis = currentMillis; boolean passedLimit = false; - if (previewValue != value) { + if (previewValue != value.get()) { if ((previewValue && animation > 12) || (!previewValue && animation < 24)) { passedLimit = true; @@ -83,7 +84,7 @@ public class GuiElementBoolean extends GuiElement { } lastMillis -= deltaMillis % 10; - if (previewValue == value) { + if (previewValue == value.get()) { animation = Math.max(0, Math.min(36, animation)); } else if (!passedLimit) { if (previewValue) { @@ -120,14 +121,13 @@ public class GuiElementBoolean extends GuiElement { mouseY > y - clickRadius && mouseY < y + ySize + clickRadius) { if (Mouse.getEventButton() == 0) { if (Mouse.getEventButtonState()) { - previewValue = !value; - } else if (previewValue == !value) { - value = !value; - toggleCallback.accept(value); + previewValue = !value.get(); + } else if (previewValue == !value.get()) { + toggleCallback.accept(!value.get()); } } } else { - previewValue = value; + previewValue = value.get(); } return false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java index 1f655aaf..1802a1a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java @@ -35,6 +35,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.awt.image.BufferedImage; import java.util.function.Consumer; +import java.util.function.Supplier; public class GuiElementColour extends GuiElement { public static final ResourceLocation colour_selector_dot = new ResourceLocation( @@ -68,20 +69,20 @@ public class GuiElementColour extends GuiElement { private final Consumer colourChangedCallback; private final Runnable closeCallback; - private String colour; + private Supplier colour; private final boolean opacitySlider; private final boolean valueSlider; public GuiElementColour( - int x, int y, String initialColour, Consumer colourChangedCallback, + int x, int y, Supplier colour, Consumer colourChangedCallback, Runnable closeCallback ) { - this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); + this(x, y, colour, colourChangedCallback, closeCallback, true, true); } public GuiElementColour( - int x, int y, String initialColour, Consumer colourChangedCallback, + int x, int y, Supplier colour, Consumer colourChangedCallback, Runnable closeCallback, boolean opacitySlider, boolean valueSlider ) { final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -89,12 +90,12 @@ public class GuiElementColour extends GuiElement { this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight() - ySize - 10, y)); this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth() - xSize - 10, x)); - this.colour = initialColour; + this.colour = colour; this.colourChangedCallback = colourChangedCallback; this.closeCallback = closeCallback; - int colour = ChromaColour.specialToSimpleRGB(initialColour); - Color c = new Color(colour); + int icolour = ChromaColour.specialToSimpleRGB(colour.get()); + Color c = new Color(icolour); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); updateAngleAndRadius(hsv); @@ -113,7 +114,7 @@ public class GuiElementColour extends GuiElement { public void render() { RenderUtils.drawFloatingRectDark(x, y, xSize, ySize); - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); @@ -200,8 +201,8 @@ public class GuiElementColour extends GuiElement { RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); } - int chromaSpeed = ChromaColour.getSpeed(colour); - int currentColourChroma = ChromaColour.specialToChromaRGB(colour); + int chromaSpeed = ChromaColour.getSpeed(colour.get()); + int currentColourChroma = ChromaColour.specialToChromaRGB(colour.get()); Color cChroma = new Color(currentColourChroma, true); float[] hsvChroma = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); @@ -343,7 +344,7 @@ public class GuiElementColour extends GuiElement { } } - int chromaSpeed = ChromaColour.getSpeed(colour); + int chromaSpeed = ChromaColour.getSpeed(colour.get()); int xChroma = mouseX - (x + 5 + 64 + valueOffset + opacityOffset + 5); if (xChroma > 0 && xChroma < 10) { if (chromaSpeed > 0) { @@ -351,10 +352,9 @@ public class GuiElementColour extends GuiElement { clickedComponent = 3; } } else if (mouseY > this.y + 5 + 27 && mouseY < this.y + 5 + 37) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); - colour = ChromaColour.special(200, c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(200, c.getAlpha(), currentColour)); } } } else { @@ -364,7 +364,7 @@ public class GuiElementColour extends GuiElement { } } if (Mouse.isButtonDown(0) && clickedComponent >= 0) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); @@ -381,8 +381,7 @@ public class GuiElementColour extends GuiElement { this.wheelAngle = angle; this.wheelRadius = (float) Math.pow(Math.min(1, radius), 1.5f); int rgb = Color.getHSBColor(angle / 360f, wheelRadius, hsv[2]).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), c.getAlpha(), rgb)); return true; } @@ -392,22 +391,19 @@ public class GuiElementColour extends GuiElement { if (clickedComponent == 1) { int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, 1 - y / 64f).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), c.getAlpha(), rgb)); return true; } if (clickedComponent == 2) { - colour = ChromaColour.special(ChromaColour.getSpeed(colour), + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), 255 - Math.round(y / 64f * 255), currentColour - ); - colourChangedCallback.accept(colour); + )); return true; } if (clickedComponent == 3) { - colour = ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour)); } return true; } @@ -431,9 +427,8 @@ public class GuiElementColour extends GuiElement { String text = hexField.getText().toLowerCase(); int rgb = Integer.parseInt(text, 16); - int alpha = (ChromaColour.specialToSimpleRGB(colour) >> 24) & 0xFF; - colour = ChromaColour.special(ChromaColour.getSpeed(colour), alpha, rgb); - colourChangedCallback.accept(colour); + int alpha = (ChromaColour.specialToSimpleRGB(colour.get()) >> 24) & 0xFF; + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), alpha, rgb)); Color c = new Color(rgb); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java index dc1173ef..91515259 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java @@ -32,11 +32,9 @@ import org.lwjgl.opengl.GL11; public class GuiOptionEditorAccordion extends GuiOptionEditor { private final int accordionId; - private boolean accordionToggled; public GuiOptionEditorAccordion(ConfigProcessor.ProcessedOption option, int accordionId) { super(option); - this.accordionToggled = (boolean) option.get(); this.accordionId = accordionId; } @@ -50,7 +48,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { } public boolean getToggled() { - return accordionToggled; + return (boolean) option.get(); } @Override @@ -65,7 +63,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(1, 1, 1, 1); worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION); - if (accordionToggled) { + if (getToggled()) { worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); worldrenderer.pos((double) x + 9.75f, (double) y + 13.5f, 0.0D).endVertex(); worldrenderer.pos((double) x + 13.5f, (double) y + 6, 0.0D).endVertex(); @@ -87,7 +85,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { if (Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + getHeight()) { - accordionToggled = !accordionToggled; + option.set(!getToggled()); return true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java index d12ec8e7..00907e9e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java @@ -37,7 +37,7 @@ public class GuiOptionEditorBoolean extends GuiOptionEditor { super(option); this.config = config; this.runnableId = runnableId; - bool = new GuiElementBoolean(0, 0, (boolean) option.get(), 10, (value) -> onUpdate(option, value)); + bool = new GuiElementBoolean(0, 0, () -> (boolean) option.get(), 10, (value) -> onUpdate(option, value)); } @Override diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java index ca4087b5..359a3e27 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java @@ -30,13 +30,14 @@ import org.lwjgl.input.Mouse; import static io.github.moulberry.notenoughupdates.util.GuiTextures.button_white; public class GuiOptionEditorColour extends GuiOptionEditor { - private String chromaColour; private GuiElementColour colourElement = null; public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { super(option); + } - this.chromaColour = (String) option.get(); + public String getChromaString() { + return (String) option.get(); } @Override @@ -44,7 +45,7 @@ public class GuiOptionEditorColour extends GuiOptionEditor { super.render(x, y, width); int height = getHeight(); - int argb = ChromaColour.specialToChromaRGB(chromaColour); + int argb = ChromaColour.specialToChromaRGB(getChromaString()); int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; @@ -72,10 +73,8 @@ public class GuiOptionEditorColour extends GuiOptionEditor { if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { - colourElement = new GuiElementColour(mouseX, mouseY, (String) option.get(), (val) -> { - option.set(val); - chromaColour = val; - }, () -> colourElement = null); + colourElement = new GuiElementColour(mouseX, mouseY, () -> (String) option.get(), + option::set, () -> colourElement = null); } return false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java index 6eb71d1e..b7d70db8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java @@ -35,16 +35,18 @@ import static io.github.moulberry.notenoughupdates.util.GuiTextures.button_tex; public class GuiOptionEditorKeybind extends GuiOptionEditor { private static final ResourceLocation RESET = new ResourceLocation("notenoughupdates:itemcustomize/reset.png"); - private int keyCode; private final int defaultKeyCode; private boolean editingKeycode; - public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int keyCode, int defaultKeyCode) { + public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int defaultKeyCode) { super(option); - this.keyCode = keyCode; this.defaultKeyCode = defaultKeyCode; } + public int getKeyCode() { + return (int) option.get(); + } + @Override public void render(int x, int y, int width) { super.render(x, y, width); @@ -55,7 +57,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - String keyName = KeybindHelper.getKeyName(keyCode); + String keyName = KeybindHelper.getKeyName(getKeyCode()); String text = editingKeycode ? "> " + keyName + " <" : keyName; TextRenderUtils.drawStringCenteredScaledMaxWidth(text, Minecraft.getMinecraft().fontRendererObj, @@ -72,8 +74,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1 && editingKeycode) { editingKeycode = false; - keyCode = Mouse.getEventButton() - 100; - option.set(keyCode); + option.set(Mouse.getEventButton() - 100); return true; } @@ -86,8 +87,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { } if (mouseX > x + width / 6 - 24 + 48 + 3 && mouseX < x + width / 6 - 24 + 48 + 13 && mouseY > y + height - 7 - 14 + 3 && mouseY < y + height - 7 - 14 + 3 + 11) { - keyCode = defaultKeyCode; - option.set(keyCode); + option.set(defaultKeyCode); return true; } } @@ -99,13 +99,15 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { public boolean keyboardInput() { if (editingKeycode) { editingKeycode = false; + int keyCode = -1; if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { keyCode = 0; } else if (Keyboard.getEventKey() != 0) { keyCode = Keyboard.getEventKey(); } if (keyCode > 256) keyCode = 0; - option.set(keyCode); + if (keyCode != -1) + option.set(keyCode); return true; } return false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java index 7fceb92d..175dcdc0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java @@ -34,35 +34,35 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { super(option); if (minStep < 0) minStep = 0.01f; - float floatVal = ((Number) option.get()).floatValue(); - { - String strVal; - if (floatVal % 1 == 0) { - strVal = Integer.toString((int) floatVal); - } else { - strVal = Float.toString(floatVal); - } - textField = new GuiElementTextField( - strVal, - GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT - ); - } + float floatVal = getFloatValue(); + textField = new GuiElementTextField( + getStringifiedFloatValue(), + GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT + ); slider = new GuiElementSlider(0, 0, 80, minValue, maxValue, minStep, floatVal, (val) -> { option.set(val); - - String strVal; - if (val % 1 == 0) { - strVal = Integer.toString(val.intValue()); - } else { - strVal = Float.toString(val); - strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); - strVal = strVal.replaceAll("0+$", ""); - } - textField.setText(strVal); + textField.setText(getStringifiedFloatValue()); }); } + public String getStringifiedFloatValue() { + float floatVal = getFloatValue(); + String strVal; + if (floatVal % 1 == 0) { + strVal = Integer.toString((int) floatVal); + } else { + strVal = Float.toString(floatVal); + strVal = strVal.replaceAll("(\\.\\d\\d\\d)\\d+", "$1"); + strVal = strVal.replaceAll("0+$", ""); + } + return strVal; + } + + public float getFloatValue() { + return ((Number) option.get()).floatValue(); + } + @Override public void render(int x, int y, int width) { super.render(x, y, width); @@ -72,6 +72,9 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { int sliderWidth = (fullWidth - 5) * 3 / 4; int textFieldWidth = (fullWidth - 5) / 4; + if (!Mouse.isButtonDown(0)) { + slider.setValue(getFloatValue()); + } slider.x = x + width / 6 - fullWidth / 2; slider.y = y + height - 7 - 14; slider.width = sliderWidth; @@ -84,6 +87,7 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { 16 ); } else { + textField.setText(getStringifiedFloatValue()); textField.setSize(textFieldWidth, 16); textField.setOptions( GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java index ad2fa4db..48072fbe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java @@ -47,6 +47,8 @@ public class GuiOptionEditorText extends GuiOptionEditor { fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10 ); + } else { + textField.setText((String) option.get()); } textField.setSize(fullWidth, 16); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java index efdeab01..9a75ec19 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java @@ -152,7 +152,7 @@ public class ConfigProcessor { if (optionType.isAssignableFrom(int.class) && optionField.isAnnotationPresent(ConfigEditorKeybind.class)) { ConfigEditorKeybind configEditorAnnotation = optionField.getAnnotation(ConfigEditorKeybind.class); - editor = new GuiOptionEditorKeybind(option, (int) option.get(), configEditorAnnotation.defaultKey()); + editor = new GuiOptionEditorKeybind(option, configEditorAnnotation.defaultKey()); } if (optionField.isAnnotationPresent(ConfigEditorButton.class)) { ConfigEditorButton configEditorAnnotation = optionField.getAnnotation(ConfigEditorButton.class); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java index 98d36f2b..025e11b2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java @@ -744,7 +744,7 @@ public class GuiDungeonMapEditor extends GuiScreen { ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft()); mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth; mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1; - activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBackgroundColour, + activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBackgroundColour, (col) -> options.dmBackgroundColour = col, () -> activeColourEditor = null ); } @@ -753,7 +753,7 @@ public class GuiDungeonMapEditor extends GuiScreen { ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft()); mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth; mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1; - activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBorderColour, + activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBorderColour, (col) -> options.dmBorderColour = col, () -> activeColourEditor = null ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java b/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java index 1d91ca76..d7759c9a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java @@ -19,14 +19,15 @@ package io.github.moulberry.notenoughupdates.loader; +import io.github.moulberry.notenoughupdates.BuildFlags; import io.github.moulberry.notenoughupdates.envcheck.EnvironmentScan; import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; import org.spongepowered.asm.launch.MixinTweaker; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -48,7 +49,7 @@ public class NEUDelegatingTweaker implements ITweaker { EnvironmentScan.checkEnvironmentOnce(); } - List delegates = new ArrayList<>(); + List delegates = new ArrayList<>(); public NEUDelegatingTweaker() { discoverTweakers(); @@ -56,45 +57,32 @@ public class NEUDelegatingTweaker implements ITweaker { } private void discoverTweakers() { - delegates.add(new MixinTweaker()); - delegates.add(new ModLoadingTweaker()); - delegates.add(new KotlinLoadingTweaker()); + if (BuildFlags.ENABLE_ONECONFIG_COMPAT_LAYER) { + delegates.add("cc.polyfrost.oneconfigwrapper.OneConfigWrapper"); + } + delegates.add(MixinTweaker.class.getName()); + delegates.add(ModLoadingTweaker.class.getName()); + delegates.add(KotlinLoadingTweaker.class.getName()); } @Override public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - for (ITweaker delegate : delegates) { - delegate.acceptOptions(args, gameDir, assetsDir, profile); - } + List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); + tweakClasses.addAll(delegates); } @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { - for (ITweaker delegate : delegates) { - delegate.injectIntoClassLoader(classLoader); - } } @Override public String getLaunchTarget() { - String target = null; - for (ITweaker delegate : delegates) { - String launchTarget = delegate.getLaunchTarget(); - if (launchTarget != null) - target = launchTarget; - } - return target; + return null; } @Override public String[] getLaunchArguments() { - List launchArguments = new ArrayList<>(); - for (ITweaker delegate : delegates) { - String[] delegateLaunchArguments = delegate.getLaunchArguments(); - if (delegateLaunchArguments != null) - launchArguments.addAll(Arrays.asList(delegateLaunchArguments)); - } - return launchArguments.toArray(new String[0]); + return new String[0]; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java index 674e4068..129699da 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java @@ -92,7 +92,7 @@ public class GuiItemCustomize extends GuiScreen { ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; enchantGlintCustomColourAnimation.setValue(enchantGlint ? 17 : 0); - this.enchantGlintButton = new GuiElementBoolean(0, 0, enchantGlint, (bool) -> { + this.enchantGlintButton = new GuiElementBoolean(0, 0, () -> enchantGlint, (bool) -> { enchantGlint = bool; updateData(); }); @@ -443,7 +443,7 @@ public class GuiItemCustomize extends GuiScreen { editor = new GuiElementColour( mouseX, mouseY, - customGlintColour == null ? ItemCustomizeManager.DEFAULT_GLINT_COLOR : customGlintColour, + () -> customGlintColour == null ? ItemCustomizeManager.DEFAULT_GLINT_COLOR : customGlintColour, (colour) -> { customGlintColour = colour; updateData(); @@ -464,7 +464,7 @@ public class GuiItemCustomize extends GuiScreen { updateData(); } else { editor = new GuiElementColour(mouseX, mouseY, - customLeatherColour == null ? getChromaStrFromLeatherColour() : customLeatherColour, + () -> customLeatherColour == null ? getChromaStrFromLeatherColour() : customLeatherColour, (colour) -> { customLeatherColour = colour; updateData(); @@ -473,19 +473,6 @@ public class GuiItemCustomize extends GuiScreen { } } - /*if(mouseX >= xCenter-90 && mouseX <= xCenter+90 && - mouseY >= belowEnchGlint+65 && mouseY <= belowEnchGlint+80) { - if(true) { - String userName = Minecraft.getMinecraft().thePlayer.getName(); - String serverId = "1872398172739"; - try { - Desktop.getDesktop().browse(new URL("https://moulberry.codes/purchaseitemtag?uniqueId="+serverId+"&username="+userName).toURI()); - } catch(Exception ignored) {} - } else { - - } - }*/ - super.mouseClicked(mouseX, mouseY, mouseButton); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java b/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java new file mode 100644 index 00000000..7afceab9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.oneconfig; + +import io.github.moulberry.notenoughupdates.core.config.Config; +import net.minecraftforge.fml.common.Loader; + +import java.util.Optional; + +public abstract class IOneConfigCompat { + private static final Object sentinelFailure = new Object(); + private static final Object lock = new Object(); + private static Object INSTANCE = null; + + public static Optional getInstance() { + if (INSTANCE == null && Loader.isModLoaded("oneconfig")) { + synchronized (lock) { + if (INSTANCE == null) + try { + Class aClass = Class.forName("io.github.moulberry.notenoughupdates.compat.oneconfig.OneConfigCompat"); + INSTANCE = aClass.newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + System.err.println("Critical failure in OneConfigCompat initialization"); + e.printStackTrace(); + INSTANCE = sentinelFailure; + } + } + } + if (INSTANCE == sentinelFailure) return Optional.empty(); + return Optional.ofNullable((IOneConfigCompat) INSTANCE); + } + + public abstract void initConfig(Config moulConfig, Runnable saveCallback); + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 129f973b..371d657e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -73,6 +73,8 @@ import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.client.ClientCommandHandler; import java.util.ArrayList; @@ -88,10 +90,11 @@ public class NEUConfig extends Config { for (TextOverlay overlay : OverlayManager.textOverlays) { overlayPositions.put(overlay, overlay.getPosition()); } + GuiScreen savedGui = Minecraft.getMinecraft().currentScreen; Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditor(overlayPositions, () -> { }, () -> { }, () -> { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); + NotEnoughUpdates.INSTANCE.openGui = savedGui; })); } @@ -109,8 +112,9 @@ public class NEUConfig extends Config { case -1: return; case 0: + GuiScreen savedGui = Minecraft.getMinecraft().currentScreen; NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(() -> { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); + NotEnoughUpdates.INSTANCE.openGui = savedGui; }); return; case 1: diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index a1b15b82..59c78dda 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -51,7 +51,7 @@ import java.util.TimeZone; import java.util.TreeMap; public class ExtraPage extends GuiProfileViewerPage { - +// Hehe private static final ResourceLocation pv_extra = new ResourceLocation("notenoughupdates:pv_extra.png"); private TreeMap> topKills = null; private TreeMap> topDeaths = null; diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneConfigCompat.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneConfigCompat.java new file mode 100644 index 00000000..b80db70a --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneConfigCompat.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.data.ModType; +import io.github.moulberry.notenoughupdates.core.config.Config; +import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; +import java.util.ArrayList; + +public class OneConfigCompat extends IOneConfigCompat { + + Mod mod = new Mod("NotEnoughUpdates", ModType.SKYBLOCK, "/assets/notenoughupdates/logo.png"); + + OneMoulConfig omc; + + @Override + public void initConfig(Config moulConfig, Runnable saveCallback) { + omc = new OneMoulConfig(mod, moulConfig, saveCallback); + } +} diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyColor.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyColor.java new file mode 100644 index 00000000..3c70f483 --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyColor.java @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigColorElement; +import io.github.moulberry.notenoughupdates.core.ChromaColour; +import lombok.var; + +import java.awt.*; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Field; + +public class OneFancyColor extends ConfigColorElement { + public OneFancyColor( + Field field, + Object parent, + String name, + String description, + String category, + String subcategory, + int size, + boolean allowAlpha + ) { + super(field, parent, name, description, category, subcategory, size, allowAlpha); + } + + @Override + public Object get() throws IllegalAccessException { + String chromaString = (String) super.get(); + + int[] decompose = ChromaColour.decompose(chromaString); + int r = decompose[2]; + int g = decompose[1]; + int b = decompose[0]; + int a = decompose[3]; + int chr = decompose[4]; + + short[] hsba = OneColor.ARGBtoHSBA(new Color(r, g, b, a).getRGB()); + if (chr > 0) { + return new OneColor(hsba[0], hsba[1], hsba[2], hsba[3], (int) ChromaColour.getSecondsForSpeed(chr)); + } + + return new OneColor(r, g, b, a); + } + + private static MethodHandle hsbaAccessor; + private static MethodHandle databitAccessor; + + static { + try { + Field f = OneColor.class.getDeclaredField("hsba"); + Field f2 = OneColor.class.getDeclaredField("dataBit"); + f.setAccessible(true); + f2.setAccessible(true); + var lookup = MethodHandles.lookup(); + hsbaAccessor = lookup.unreflectGetter(f); + databitAccessor = lookup.unreflectGetter(f2); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + private static short[] getHsba(OneColor color) { + try { + return (short[]) hsbaAccessor.invokeExact(color); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + private static int getDataBit(OneColor color) { + try { + return (int) databitAccessor.invokeExact(color); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + @Override + protected void set(Object object) throws IllegalAccessException { + OneColor color = (OneColor) object; + float dataBit = getDataBit(color) / 1000F; + short[] hsba = getHsba(color); + int argb = OneColor.HSBAtoARGB(hsba[0], hsba[1], hsba[2], hsba[3]); + Color color1 = new Color(argb, true); + super.set(ChromaColour.special( + dataBit > 0 ? ChromaColour.getSpeedForSeconds(dataBit) : 0, // TODO chroma still sucks + color1.getAlpha(), + color1.getRed(), + color1.getGreen(), + color1.getBlue() + )); + } +} diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyKeybind.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyKeybind.java new file mode 100644 index 00000000..823d90ea --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneFancyKeybind.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.config.core.OneKeyBind; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigKeyBind; + +import java.lang.reflect.Field; + +public class OneFancyKeybind extends ConfigKeyBind { + public OneFancyKeybind( + Field field, + Object parent, + String name, + String description, + String category, + String subcategory, + int size + ) { + super(field, parent, name, description, category, subcategory, size); + } + + @Override + public Object get() throws IllegalAccessException { + OneWrappedKeyBind owk = new OneWrappedKeyBind(); + owk.value = (int) super.get(); + return owk; + } + + @Override + protected void set(Object object) throws IllegalAccessException { + OneWrappedKeyBind keyBind = (OneWrappedKeyBind) object; + super.set(keyBind.value); + } +} diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneMoulConfig.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneMoulConfig.java new file mode 100644 index 00000000..59aa25d1 --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneMoulConfig.java @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.config.core.ConfigUtils; +import cc.polyfrost.oneconfig.config.data.InfoType; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigButton; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigDropdown; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigInfo; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigSlider; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigSwitch; +import cc.polyfrost.oneconfig.gui.elements.config.ConfigTextBox; +import io.github.moulberry.notenoughupdates.core.config.Config; +import io.github.moulberry.notenoughupdates.core.config.annotations.Category; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorButton; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorColour; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDraggableList; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorDropdown; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorFSR; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorKeybind; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorSlider; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorText; +import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; + +import java.lang.reflect.Field; + +public class OneMoulConfig extends cc.polyfrost.oneconfig.config.Config { + + final Config moulConfig; + private final Runnable saveCallback; + + public OneMoulConfig(Mod modData, Config moulConfig, Runnable saveCallback) { + super(modData, "_SHOULD_NOT_BE_WRITTEN.json"); + if (moulConfig == null) throw new IllegalArgumentException("mfw no moulconfig"); + this.moulConfig = moulConfig; + this.saveCallback = saveCallback; + initialize(); + } + + @Override + public void initialize() { + mod.config = this; + + try { + processMoulConfig(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + cc.polyfrost.oneconfig.config.Config.register(mod); + } + + private void processMoulConfig() throws IllegalAccessException { + for (Field categoryField : moulConfig.getClass().getDeclaredFields()) { + Category annotation = categoryField.getAnnotation(Category.class); + if (annotation == null) continue; + Object categoryInstance = categoryField.get(moulConfig); + OptionSubcategory subCategory = ConfigUtils.getSubCategory(mod.defaultPage, annotation.name(), ""); + createPageForCategory(subCategory, categoryInstance); + } + } + + private void createPageForCategory(OptionSubcategory category, Object categoryInstance) { + for (Field optionField : categoryInstance.getClass().getDeclaredFields()) { + ConfigOption annotation = optionField.getAnnotation(ConfigOption.class); + if (annotation == null) continue; + String cat = category.getName(); + String subcategory = ""; + String annotationName = StringUtils.cleanColour( annotation.name()); + String annotationDesc = StringUtils.cleanColour( annotation.desc()); + ConfigEditorBoolean configEditorBoolean = optionField.getAnnotation(ConfigEditorBoolean.class); + if (configEditorBoolean != null) { + category.options.add(new ConfigSwitch( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, subcategory, 2 + )); + } + ConfigEditorText configEditorText = optionField.getAnnotation(ConfigEditorText.class); + if (configEditorText != null) { + category.options.add(new ConfigTextBox( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, subcategory, 2, + annotationName, false, false + )); + } + ConfigEditorKeybind configEditorKeybind = optionField.getAnnotation(ConfigEditorKeybind.class); + if (configEditorKeybind != null) { + category.options.add(new OneFancyKeybind( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, subcategory, 2 + )); + } + ConfigEditorColour configEditorColour = optionField.getAnnotation(ConfigEditorColour.class); + if (configEditorColour != null) { + category.options.add(new OneFancyColor( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, subcategory, 2, true + )); + } + ConfigEditorSlider configEditorSlider = optionField.getAnnotation(ConfigEditorSlider.class); + if (configEditorSlider != null) { + category.options.add(new WrappedConfigSlider( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, + subcategory, + configEditorSlider.minValue(), + configEditorSlider.maxValue(), + (int) configEditorSlider.minStep() + )); + } + ConfigEditorButton configEditorButton = optionField.getAnnotation(ConfigEditorButton.class); + if (configEditorButton != null) { + category.options.add(new ConfigButton( + () -> moulConfig.executeRunnable(configEditorButton.runnableId()), + categoryInstance, + annotationName, + annotationDesc, + cat, + subcategory, + 2, configEditorButton.buttonText() + )); + } + ConfigEditorDropdown configEditorDropdown = optionField.getAnnotation(ConfigEditorDropdown.class); + if (configEditorDropdown != null) { + category.options.add(new ConfigDropdown( + optionField, + categoryInstance, + annotationName, + annotationDesc, + cat, subcategory, + 2, configEditorDropdown.values() + )); + } + ConfigEditorDraggableList configEditorDraggableList = optionField.getAnnotation(ConfigEditorDraggableList.class); + if (configEditorDraggableList != null) { + category.options.add(new ConfigInfo( + optionField, categoryInstance, + "This option (" + annotationName + ") is not available via the oneconfig gui", + cat, subcategory, 2, InfoType.ERROR + )); + } + ConfigEditorFSR configEditorFSR = optionField.getAnnotation(ConfigEditorFSR.class); + if (configEditorFSR != null) { + category.options.add(new ConfigInfo( + optionField, categoryInstance, + annotationDesc, cat, subcategory, 2, InfoType.WARNING + )); + } + } + } + + @Override + public void save() { + saveCallback.run(); + } + + @Override + public void load() { + } + + @Override + public boolean supportsProfiles() { + return false; + } + +} diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneWrappedKeyBind.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneWrappedKeyBind.java new file mode 100644 index 00000000..fa29eaf8 --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/OneWrappedKeyBind.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.config.core.OneKeyBind; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; +import java.util.Arrays; + +public class OneWrappedKeyBind extends OneKeyBind { + + public int value = Keyboard.KEY_NONE; + + @Override + public String getDisplay() { + keyBinds.clear(); + keyBinds.addAll(getKeyBinds()); + return super.getDisplay(); + } + + @Override + public void addKey(int key) { + value = key; + } + + @Override + public void clearKeys() { + value = Keyboard.KEY_NONE; + } + + @Override + public int getSize() { + return getKeyBinds().size(); + } + + @Override + public ArrayList getKeyBinds() { + return value == Keyboard.KEY_NONE ? new ArrayList<>() : new ArrayList<>(Arrays.asList(value)); + } +} diff --git a/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/WrappedConfigSlider.java b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/WrappedConfigSlider.java new file mode 100644 index 00000000..98b6a289 --- /dev/null +++ b/src/oneconfig/java/io/github/moulberry/notenoughupdates/compat/oneconfig/WrappedConfigSlider.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + +package io.github.moulberry.notenoughupdates.compat.oneconfig; + +import cc.polyfrost.oneconfig.gui.elements.config.ConfigSlider; + +import java.lang.reflect.Field; + +public class WrappedConfigSlider extends ConfigSlider { + public WrappedConfigSlider( + Field field, + Object parent, + String name, + String description, + String category, + String subcategory, + float min, + float max, + int step + ) { + super(field, parent, name, description, category, subcategory, min, max, step); + } + + @Override + public Object get() throws IllegalAccessException { + Object g = super.get(); + if (g instanceof Double) { + return (float) (double) g; + } + if (g instanceof Long) { + return (int) (long) g; + } + return g; + } +} -- cgit From 6caaa18996b52fcbacea7789094e5486bb2ea349 Mon Sep 17 00:00:00 2001 From: Vixid <52578495+Vixid1@users.noreply.github.com> Date: Thu, 12 Jan 2023 06:45:40 +0000 Subject: Bonzo Mask Durability Cooldown (#531) --- .../miscfeatures/ItemCooldowns.java | 183 +++++++++++++++------ .../options/seperateSections/ItemOverlays.java | 16 ++ 2 files changed, 148 insertions(+), 51 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java index ee5eef9e..e5ee40d0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java @@ -37,9 +37,24 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class ItemCooldowns { + + private static final Pattern COOLDOWN_LORE = Pattern.compile("\\u00a78Cooldown: \\u00a7a(\\d+)s"); + + private static final Pattern PICKAXE_ABILITY_ACTIVATION = + Pattern.compile("\\u00a7r\\u00a7aYou used your \\u00a7r\\u00a7..+ \\u00a7r\\u00a7aPickaxe Ability!\\u00a7r"); + + private static final Pattern BONZO_ABILITY_ACTIVATION = + Pattern.compile("\\u00a7r\\u00a7aYour \\u00a7r\\u00a7[9|5](\\u269A )*Bonzo's Mask \\u00a7r\\u00a7asaved your life!\\u00a7r"); + + private static final Pattern SPIRIT_ABILITY_ACTIVATION = + Pattern.compile("\\u00a7r\\u00a76Second Wind Activated\\u00a7r\\u00a7a! \\u00a7r\\u00a7aYour Spirit Mask saved your life!\\u00a7r"); + private static final Map durabilityOverrideMap = new HashMap<>(); + public static long pickaxeUseCooldownMillisRemaining = -1; private static long treecapitatorCooldownMillisRemaining = -1; + private static long bonzomaskCooldownMillisRemaining = -1; + private static long spiritMaskCooldownMillisRemaining = -1; public static boolean firstLoad = true; public static long firstLoadMillis = 0; @@ -47,17 +62,27 @@ public class ItemCooldowns { private static long lastMillis = 0; public static long pickaxeCooldown = -1; + private static long bonzoMaskCooldown = -1; + private static long spiritMaskCooldown = -1; public static TreeMap blocksClicked = new TreeMap<>(); private static int tickCounter = 0; + enum Item { + PICKAXES, + BONZO_MASK, + SPIRIT_MASK + } + @SubscribeEvent public void tick(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.END && NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { if (tickCounter++ >= 20 * 10) { tickCounter = 0; pickaxeCooldown = -1; + bonzoMaskCooldown = -1; + spiritMaskCooldown = -1; } long currentTime = System.currentTimeMillis(); @@ -66,7 +91,6 @@ public class ItemCooldowns { firstLoad = false; } - Long key; while ((key = blocksClicked.floorKey(currentTime - 1500)) != null) { blocksClicked.remove(key); @@ -83,6 +107,12 @@ public class ItemCooldowns { if (treecapitatorCooldownMillisRemaining >= 0) { treecapitatorCooldownMillisRemaining -= millisDelta; } + if (bonzomaskCooldownMillisRemaining >= 0) { + bonzomaskCooldownMillisRemaining -= millisDelta; + } + if (spiritMaskCooldownMillisRemaining >= 0) { + spiritMaskCooldownMillisRemaining -= millisDelta; + } } } @@ -121,14 +151,14 @@ public class ItemCooldowns { if (blocksClicked.containsValue(pos)) { IBlockState oldState = Minecraft.getMinecraft().theWorld.getBlockState(pos); if (oldState.getBlock() != packetIn.getBlockState().getBlock()) { - onBlockMined(pos); + onBlockMined(); } } } - public static void onBlockMined(BlockPos pos) { + public static void onBlockMined() { ItemStack held = Minecraft.getMinecraft().thePlayer.getHeldItem(); - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(held); + String internalname = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(held).resolveInternalName(); if (internalname != null) { if (treecapitatorCooldownMillisRemaining < 0 && (internalname.equals("TREECAPITATOR_AXE") || internalname.equals("JUNGLE_AXE"))) { @@ -137,11 +167,6 @@ public class ItemCooldowns { } } - private static final Pattern PICKAXE_ABILITY_REGEX = Pattern.compile("\\u00a7r\\u00a7aYou used your " + - "\\u00a7r\\u00a7..+ \\u00a7r\\u00a7aPickaxe Ability!\\u00a7r"); - - private static final Pattern PICKAXE_COOLDOWN_LORE_REGEX = Pattern.compile("\\u00a78Cooldown: \\u00a7a(\\d+)s"); - private static boolean isPickaxe(String internalname) { if (internalname == null) return false; @@ -153,36 +178,69 @@ public class ItemCooldowns { } else return internalname.equals("GEMSTONE_GAUNTLET") || internalname.equals("PICKONIMBUS") || internalname.equals("DIVAN_DRILL"); } - private static void updatePickaxeCooldown() { - if (pickaxeCooldown == -1 && NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility) { - for (ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - if (stack != null && stack.hasTagCompound()) { - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); - if (isPickaxe(internalname)) { - for (String line : NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound())) { - Matcher matcher = PICKAXE_COOLDOWN_LORE_REGEX.matcher(line); - if (matcher.find()) { - try { - pickaxeCooldown = Integer.parseInt(matcher.group(1)); - return; - } catch (Exception ignored) { - } - } - } - } + @SubscribeEvent + public void onChatMessage(ClientChatReceivedEvent event) { + if (PICKAXE_ABILITY_ACTIVATION.matcher(event.message.getFormattedText()).matches() && + NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility && pickaxeCooldown != 0) { + findCooldownInTooltip(Item.PICKAXES); + pickaxeUseCooldownMillisRemaining = pickaxeCooldown * 1000; + } + + if (BONZO_ABILITY_ACTIVATION.matcher(event.message.getFormattedText()).matches() && + NotEnoughUpdates.INSTANCE.config.itemOverlays.bonzoAbility && bonzoMaskCooldown != 0) { + findCooldownInTooltip(Item.BONZO_MASK); + bonzomaskCooldownMillisRemaining = bonzoMaskCooldown * 1000; + } + + if (SPIRIT_ABILITY_ACTIVATION.matcher(event.message.getFormattedText()).matches() && + NotEnoughUpdates.INSTANCE.config.itemOverlays.spiritAbility && spiritMaskCooldown != 0) { + findCooldownInTooltip(Item.SPIRIT_MASK); + spiritMaskCooldownMillisRemaining = spiritMaskCooldown * 1000; + } + } + + private static void findCooldownInTooltip(Item item) { + for (ItemStack stack : Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + setSpecificCooldown(stack, item); + } + + // Check helmet slot for items that can also be equipped as a helmet + ItemStack stack = Minecraft.getMinecraft().thePlayer.inventory.armorInventory[3]; + setSpecificCooldown(stack, item); + } + + private static void setSpecificCooldown(ItemStack stack, Item item) { + if (stack != null && stack.hasTagCompound()) { + + String internalname = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(stack).resolveInternalName(); + + if (internalname != null) { + switch (item) { + case PICKAXES: + if (isPickaxe(internalname)) pickaxeCooldown = setCooldown(stack); + break; + case BONZO_MASK: + if (internalname.equals("BONZO_MASK") || internalname.equals("STARRED_BONZO_MASK")) bonzoMaskCooldown = setCooldown(stack); + break; + case SPIRIT_MASK: + if (internalname.equals("SPIRIT_MASK")) spiritMaskCooldown = setCooldown(stack); + break; } } - pickaxeCooldown = 0; } } - @SubscribeEvent - public void onChatMessage(ClientChatReceivedEvent event) { - if (pickaxeCooldown != 0 && PICKAXE_ABILITY_REGEX.matcher(event.message.getFormattedText()).matches() && - NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility) { - updatePickaxeCooldown(); - pickaxeUseCooldownMillisRemaining = pickaxeCooldown * 1000; + private static int setCooldown(ItemStack stack) { + for (String line : NotEnoughUpdates.INSTANCE.manager.getLoreFromNBT(stack.getTagCompound())) { + Matcher matcher = COOLDOWN_LORE.matcher(line); + if (matcher.find()) { + try { + return Integer.parseInt(matcher.group(1)); + } catch (Exception ignored) { + } + } } + return -1; } public static float getDurabilityOverride(ItemStack stack) { @@ -193,27 +251,20 @@ public class ItemCooldowns { return durabilityOverrideMap.get(stack); } - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack); + String internalname = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery().withItemStack(stack).resolveInternalName(); if (internalname == null) { durabilityOverrideMap.put(stack, -1f); return -1; } - if (isPickaxe(internalname)) { - updatePickaxeCooldown(); - - if (pickaxeUseCooldownMillisRemaining < 0) { - durabilityOverrideMap.put(stack, -1f); - return -1; - } + // Pickaxes + if (isPickaxe(internalname) && NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility) { + findCooldownInTooltip(Item.PICKAXES); - if (pickaxeUseCooldownMillisRemaining > pickaxeCooldown * 1000) { - return stack.getItemDamage(); - } - float dura = (float) (pickaxeUseCooldownMillisRemaining / (pickaxeCooldown * 1000.0)); - durabilityOverrideMap.put(stack, dura); - return dura; - } else if (internalname.equals("TREECAPITATOR_AXE") || internalname.equals("JUNGLE_AXE")) { + return durabilityOverride(pickaxeUseCooldownMillisRemaining, pickaxeCooldown, stack); + } + // Treecapitator / Jungle Axe + if (internalname.equals("TREECAPITATOR_AXE") || internalname.equals("JUNGLE_AXE")) { if (treecapitatorCooldownMillisRemaining < 0) { durabilityOverrideMap.put(stack, -1f); return -1; @@ -222,12 +273,42 @@ public class ItemCooldowns { if (treecapitatorCooldownMillisRemaining > getTreecapCooldownWithPet()) { return stack.getItemDamage(); } - float dura = (treecapitatorCooldownMillisRemaining / (float) getTreecapCooldownWithPet()); - durabilityOverrideMap.put(stack, dura); - return dura; + + float durability = treecapitatorCooldownMillisRemaining / (float) getTreecapCooldownWithPet(); + durabilityOverrideMap.put(stack, durability); + + return durability; + } + // Bonzo Mask + if ((internalname.equals("BONZO_MASK") || internalname.equals("STARRED_BONZO_MASK")) && NotEnoughUpdates.INSTANCE.config.itemOverlays.bonzoAbility) { + findCooldownInTooltip(Item.BONZO_MASK); + + return durabilityOverride(bonzomaskCooldownMillisRemaining, bonzoMaskCooldown, stack); + } + // Spirit Mask + if (internalname.equals("SPIRIT_MASK") && NotEnoughUpdates.INSTANCE.config.itemOverlays.spiritAbility) { + findCooldownInTooltip(Item.SPIRIT_MASK); + + return durabilityOverride(spiritMaskCooldownMillisRemaining, spiritMaskCooldown, stack); } durabilityOverrideMap.put(stack, -1f); return -1; } + + private static float durabilityOverride(float millisRemaining, long cooldown, ItemStack stack) { + if (millisRemaining < 0) { + durabilityOverrideMap.put(stack, -1f); + return -1; + } + + if (millisRemaining > cooldown * 1000) { + return stack.getItemDamage(); + } + + float durability = (float) (millisRemaining / (cooldown * 1000.0)); + durabilityOverrideMap.put(stack, durability); + + return durability; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java index d477b62b..081fd4b3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/ItemOverlays.java @@ -468,4 +468,20 @@ public class ItemOverlays { @ConfigEditorBoolean public boolean pickaxeAbility = true; + @Expose + @ConfigOption( + name = "Bonzo Mask Ability Cooldown", + desc = "Show the cooldown duration of a bonzo mask ability as the durability." + ) + @ConfigEditorBoolean + public boolean bonzoAbility = true; + + @Expose + @ConfigOption( + name = "Spirit Mask Ability Cooldown", + desc = "Show the cooldown duration of the spirit mask ability as the durability." + ) + @ConfigEditorBoolean + public boolean spiritAbility = true; + } -- cgit From 4b3aad7142c04071961e8b4a87cb1b4759da38b7 Mon Sep 17 00:00:00 2001 From: jani270 <69345714+jani270@users.noreply.github.com> Date: Thu, 12 Jan 2023 21:13:39 +0100 Subject: Changed Fishing Timer from 30 to 20 seconds (#547) --- .../moulberry/notenoughupdates/miscfeatures/FishingHelper.java | 2 +- .../notenoughupdates/options/seperateSections/Fishing.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java index e3afc73d..a7c22b93 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/FishingHelper.java @@ -148,7 +148,7 @@ public class FishingHelper { int ticksExisted = hook.ticksExisted; float seconds = ticksExisted / 20F; int color; - if (seconds >= 30) { + if (seconds >= 20) { color = ChromaColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.fishing.fishingTimerColor30SecPlus); if (NotEnoughUpdates.INSTANCE.config.fishing.fishingSound30Sec && !playedSound) { ISound sound = new PositionedSound(new ResourceLocation("random.orb")) {{ diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java index 10a4de0e..9d7a0775 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/seperateSections/Fishing.java @@ -263,8 +263,8 @@ public class Fishing { @Expose @ConfigOption( - name = "Fishing timer colour (30s)", - desc = "Colour of the fishing timer after 30 seconds or more have passed", + name = "Fishing timer colour (20s)", + desc = "Colour of the fishing timer after 20 seconds or more have passed", searchTags = "color" ) @ConfigEditorColour @@ -273,8 +273,8 @@ public class Fishing { @Expose @ConfigOption( - name = "Fishing timer ping (30s)", - desc = "Play a sound after 30 seconds passed" + name = "Fishing timer ping (20s)", + desc = "Play a sound after 20 seconds passed" ) @ConfigEditorBoolean @ConfigAccordionId(id = 6) -- cgit From e736097cd2a90c467c84d7fa941aacaea6d5fe7b Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Fri, 13 Jan 2023 19:36:39 +0100 Subject: Add nopos xdg-open link opener to vanilla GUIs (#542) --- .../moulberry/notenoughupdates/mixins/MixinGuiScreen.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java index b978b433..8baa2bef 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiScreen.java @@ -20,16 +20,26 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.gui.GuiScreen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.net.URI; + @Mixin(GuiScreen.class) public class MixinGuiScreen { @Inject(method = "sendChatMessage(Ljava/lang/String;Z)V", at = @At("HEAD")) public void onSendChatMessage(String message, boolean addToChat, CallbackInfo ci) { SBInfo.getInstance().onSendChatMessage(message); } + + @Inject(method = "openWebLink", at = @At("HEAD"), cancellable = true) + public void onOpenWebLink(URI url, CallbackInfo ci) { + if (Utils.openUrl(url.toString())) { + ci.cancel(); + } + } } -- cgit From c20f610853702c0208d301865c015ea8ef973fd4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:37:27 +0100 Subject: No more final changes (#538) prevent offline pv crashes Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../profileviewer/GuiProfileViewer.java | 205 ++++--- .../profileviewer/ProfileViewer.java | 629 ++++++++++----------- 2 files changed, 404 insertions(+), 430 deletions(-) (limited to 'src/main/java/io') 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 de5d384a..4bf65cc6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -171,10 +171,7 @@ public class GuiProfileViewer extends GuiScreen { ); public final GuiElementTextField playerNameTextField; public final GuiElementTextField inventoryTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); - public final GuiElementTextField killDeathSearchTextField = new GuiElementTextField( - "", - GuiElementTextField.SCALE_TEXT - ); + public final GuiElementTextField killDeathSearchTextField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT); private final Map pages = new HashMap<>(); public int sizeX; public int sizeY; @@ -192,7 +189,7 @@ public class GuiProfileViewer extends GuiScreen { private double lastBgBlurFactor = -1; private boolean showBingoPage; - public GuiProfileViewer(final ProfileViewer.Profile profile) { + public GuiProfileViewer(ProfileViewer.Profile profile) { GuiProfileViewer.profile = profile; GuiProfileViewer.profileId = profile.getLatestProfile(); String name = ""; @@ -219,7 +216,7 @@ public class GuiProfileViewer extends GuiScreen { pages.put(ProfileViewerPage.CRIMSON_ISLE, new CrimsonIslePage(this)); } - private static float getMaxLevelXp(final JsonArray levels, final int offset, final int maxLevel) { + private static float getMaxLevelXp(JsonArray levels, int offset, int maxLevel) { float xpTotal = 0; for (int i = offset; i < offset + maxLevel - 1; i++) { @@ -230,7 +227,7 @@ public class GuiProfileViewer extends GuiScreen { } @Deprecated - public static String shortNumberFormat(final double n, final int iteration) { + public static String shortNumberFormat(double n, int iteration) { return StringUtils.shortNumberFormat(n, iteration ); } @@ -252,7 +249,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - public void drawScreen(final int mouseX, final int mouseY, final float partialTicks) { + public void drawScreen(int mouseX, int mouseY, float partialTicks) { currentTime = System.currentTimeMillis(); if (startTime == 0) startTime = currentTime; @@ -275,10 +272,10 @@ public class GuiProfileViewer extends GuiScreen { } } - sizeX = 431; - sizeY = 202; - guiLeft = (width - sizeX) / 2; - guiTop = (height - sizeY) / 2; + this.sizeX = 431; + this.sizeY = 202; + guiLeft = (this.width - this.sizeX) / 2; + guiTop = (this.height - this.sizeY) / 2; JsonObject currProfileInfo = profile != null ? profile.getProfileInformation(profileId) : null; if (NotEnoughUpdates.INSTANCE.config.profileViewer.alwaysShowBingoTab) { @@ -320,7 +317,7 @@ public class GuiProfileViewer extends GuiScreen { if (!(page == ProfileViewerPage.LOADING)) { playerNameTextField.render(guiLeft + sizeX - 100, guiTop + sizeY + 5); - final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); if (profile != null) { //Render Profile chooser button @@ -378,10 +375,8 @@ public class GuiProfileViewer extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_unknown); Utils.drawTexturedRect(guiLeft - 16 - 5, guiTop + sizeY + 5, 16, 16, GL11.GL_NEAREST); } - //Render Open In SkyCrypt button - renderBlurredBackground( - width, - height, guiLeft + 100 + 6 + 2, guiTop + sizeY + 3 + 2, 100 - 4, 20 - 4); + //Render Open In Skycrypt button + renderBlurredBackground(width, height, guiLeft + 100 + 6 + 2, guiTop + sizeY + 3 + 2, 100 - 4, 20 - 4); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); Utils.drawTexturedRect( guiLeft + 100 + 6, @@ -395,7 +390,7 @@ public class GuiProfileViewer extends GuiScreen { GL11.GL_NEAREST ); Utils.drawStringCenteredScaledMaxWidth( - "Open in SkyCrypt", + "Open in Skycrypt", Minecraft.getMinecraft().fontRendererObj, guiLeft + 50 + 100 + 6, guiTop + sizeY + 3 + 10, @@ -404,15 +399,12 @@ public class GuiProfileViewer extends GuiScreen { new Color(63, 224, 208, 255).getRGB() ); - if ( - profileDropdownSelected && !profile.getProfileNames().isEmpty() && scaledResolution.getScaleFactor() < 4) { - final int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; - - final int numProfiles = profile.getProfileNames().size(); - final int sizeYDropdown = numProfiles * dropdownOptionSize; - renderBlurredBackground( - width, - height, guiLeft + 2, guiTop + sizeY + 23, 100 - 4, sizeYDropdown - 2); + if (profileDropdownSelected && !profile.getProfileNames().isEmpty() && scaledResolution.getScaleFactor() < 4) { + int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; + + int numProfiles = profile.getProfileNames().size(); + int sizeYDropdown = numProfiles * dropdownOptionSize; + renderBlurredBackground(width, height, guiLeft + 2, guiTop + sizeY + 23, 100 - 4, sizeYDropdown - 2); Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); Utils.drawTexturedRect(guiLeft, guiTop + sizeY + 23 - 3, 100, 3, 100 / 200f, 1, 0, 3 / 185f, GL11.GL_NEAREST); Utils.drawTexturedRect( @@ -439,7 +431,7 @@ public class GuiProfileViewer extends GuiScreen { ); for (int yIndex = 0; yIndex < profile.getProfileNames().size(); yIndex++) { - final String otherProfileId = profile.getProfileNames().get(yIndex); + String otherProfileId = profile.getProfileNames().get(yIndex); Utils.drawStringCenteredScaledMaxWidth( otherProfileId, Minecraft.getMinecraft().fontRendererObj, @@ -525,7 +517,7 @@ public class GuiProfileViewer extends GuiScreen { switch (page) { case LOADING: String str = EnumChatFormatting.YELLOW + "Loading player profiles."; - final long currentTimeMod = System.currentTimeMillis() % 1000; + long currentTimeMod = System.currentTimeMillis() % 1000; if (currentTimeMod > 333) { if (currentTimeMod < 666) { str += "."; @@ -545,7 +537,7 @@ public class GuiProfileViewer extends GuiScreen { //This is just here to inform the player what to do //like typing /api new or telling them to go find a psychotherapist - final long timeDiff = System.currentTimeMillis() - startTime; + long timeDiff = System.currentTimeMillis() - startTime; if (timeDiff > 20000) { Utils.drawStringCentered( @@ -583,11 +575,11 @@ public class GuiProfileViewer extends GuiScreen { 0 ); if (timeDiff > 360000) { - final long second = (timeDiff / 1000) % 60; - final long minute = (timeDiff / (1000 * 60)) % 60; - final long hour = (timeDiff / (1000 * 60 * 60)) % 24; + long second = (timeDiff / 1000) % 60; + long minute = (timeDiff / (1000 * 60)) % 60; + long hour = (timeDiff / (1000 * 60 * 60)) % 24; - final String time = String.format("%02d:%02d:%02d", hour, minute, second); + String time = String.format("%02d:%02d:%02d", hour, minute, second); Utils.drawStringCentered( EnumChatFormatting.YELLOW + "You've wasted your time here for: " + time, Minecraft.getMinecraft().fontRendererObj, @@ -701,17 +693,17 @@ public class GuiProfileViewer extends GuiScreen { if (currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { int ignoredTabs = 0; - final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - final ProfileViewerPage iPage = ProfileViewerPage.getById(configList.get(i)); + ProfileViewerPage iPage = ProfileViewerPage.getById(configList.get(i)); if (iPage == null) continue; if (iPage.stack == null || (iPage == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - final int i2 = i - ignoredTabs; - final int x = guiLeft + i2 * 28; - final int y = guiTop - 28; + int i2 = i - ignoredTabs; + int x = guiLeft + i2 * 28; + int y = guiTop - 28; if (mouseX > x && mouseX < x + 28) { if (mouseY > y && mouseY < y + 32) { @@ -728,42 +720,41 @@ public class GuiProfileViewer extends GuiScreen { } if (tooltipToDisplay != null) { - final List grayTooltip = new ArrayList<>(tooltipToDisplay.size()); - for (final String line : tooltipToDisplay) { + List grayTooltip = new ArrayList<>(tooltipToDisplay.size()); + for (String line : tooltipToDisplay) { grayTooltip.add(EnumChatFormatting.GRAY + line); } - Utils.drawHoveringText(grayTooltip, mouseX, mouseY, - width, height, -1, Minecraft.getMinecraft().fontRendererObj); + Utils.drawHoveringText(grayTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); tooltipToDisplay = null; } } - private void renderTabs(final boolean renderPressed) { + private void renderTabs(boolean renderPressed) { int ignoredTabs = 0; - final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - final ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); + ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); if (page == null) continue; if (page.stack == null || (page == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - final boolean pressed = page == currentPage; + boolean pressed = page == currentPage; if (pressed == renderPressed) { renderTab(page.stack, i - ignoredTabs, pressed); } } } - private void renderTab(final ItemStack stack, final int xIndex, final boolean pressed) { + private void renderTab(ItemStack stack, int xIndex, boolean pressed) { GlStateManager.disableLighting(); GlStateManager.enableBlend(); GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); GlStateManager.enableAlpha(); GlStateManager.alphaFunc(516, 0.1F); - final int x = guiLeft + xIndex * 28; - final int y = guiTop - 28; + int x = guiLeft + xIndex * 28; + int y = guiTop - 28; float uMin = 0; float uMax = 28 / 256f; @@ -797,20 +788,20 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException { + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { if (currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { int ignoredTabs = 0; - final List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; + List configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout; for (int i = 0; i < configList.size(); i++) { - final ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); + ProfileViewerPage page = ProfileViewerPage.getById(configList.get(i)); if (page == null) continue; if (page.stack == null || (page == ProfileViewerPage.BINGO && !showBingoPage)) { ignoredTabs++; continue; } - final int i2 = i - ignoredTabs; - final int x = guiLeft + i2 * 28; - final int y = guiTop - 28; + int i2 = i - ignoredTabs; + int x = guiLeft + i2 * 28; + int y = guiTop - 28; if (mouseX > x && mouseX < x + 28) { if (mouseY > y && mouseY < y + 32) { @@ -847,9 +838,8 @@ public class GuiProfileViewer extends GuiScreen { profileId != null ) { if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) { - final String url = - "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + - profileId; + String url = "https://sky.shiiyu.moe/stats/" + profile.getHypixelProfile().get("displayname").getAsString() + "/" + + profileId; Utils.openUrl(url); Utils.playPressSound(); return; @@ -857,7 +847,7 @@ public class GuiProfileViewer extends GuiScreen { } if (mouseX > guiLeft && mouseX < guiLeft + 100 && profile != null && !profile.getProfileNames().isEmpty()) { - final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); if (mouseY > guiTop + sizeY + 3 && mouseY < guiTop + sizeY + 23) { if (scaledResolution.getScaleFactor() >= 4) { profileDropdownSelected = false; @@ -876,7 +866,7 @@ public class GuiProfileViewer extends GuiScreen { if (profileNum >= profile.getProfileNames().size()) profileNum = 0; if (profileNum < 0) profileNum = profile.getProfileNames().size() - 1; - final String newProfileId = profile.getProfileNames().get(profileNum); + String newProfileId = profile.getProfileNames().get(profileNum); if (profileId != null && !profileId.equals(newProfileId)) { resetCache(); } @@ -885,11 +875,11 @@ public class GuiProfileViewer extends GuiScreen { profileDropdownSelected = !profileDropdownSelected; } } else if (scaledResolution.getScaleFactor() < 4 && profileDropdownSelected) { - final int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; - final int extraY = mouseY - (guiTop + sizeY + 23); - final int index = extraY / dropdownOptionSize; + int dropdownOptionSize = scaledResolution.getScaleFactor() == 3 ? 10 : 20; + int extraY = mouseY - (guiTop + sizeY + 23); + int index = extraY / dropdownOptionSize; if (index >= 0 && index < profile.getProfileNames().size()) { - final String newProfileId = profile.getProfileNames().get(index); + String newProfileId = profile.getProfileNames().get(index); if (profileId != null && !profileId.equals(newProfileId)) { resetCache(); } @@ -908,7 +898,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void keyTyped(final char typedChar, final int keyCode) throws IOException { + protected void keyTyped(char typedChar, int keyCode) throws IOException { super.keyTyped(typedChar, keyCode); if (pages.containsKey(currentPage)) { @@ -931,7 +921,7 @@ public class GuiProfileViewer extends GuiScreen { } @Override - protected void mouseReleased(final int mouseX, final int mouseY, final int mouseButton) { + protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { super.mouseReleased(mouseX, mouseY, mouseButton); if (pages.containsKey(currentPage)) { @@ -940,17 +930,17 @@ public class GuiProfileViewer extends GuiScreen { } public void renderXpBar( - final String skillName, - final ItemStack stack, - final int x, - final int y, - final int xSize, - final ProfileViewer.Level levelObj, - final int mouseX, - final int mouseY + String skillName, + ItemStack stack, + int x, + int y, + int xSize, + ProfileViewer.Level levelObj, + int mouseX, + int mouseY ) { - final float level = levelObj.level; - final int levelFloored = (int) Math.floor(level); + float level = levelObj.level; + int levelFloored = (int) Math.floor(level); Utils.renderAlignedString(skillName, EnumChatFormatting.WHITE.toString() + levelFloored, x + 14, y - 4, xSize - 20); @@ -966,27 +956,24 @@ public class GuiProfileViewer extends GuiScreen { if (mouseX > x && mouseX < x + 120) { if (mouseY > y - 4 && mouseY < y + 13) { - final String levelStr; + String levelStr; String totalXpStr = null; if (skillName.contains("Catacombs")) { totalXpStr = EnumChatFormatting.GRAY + "Total XP: " + EnumChatFormatting.DARK_PURPLE + - numberFormat.format(levelObj.totalXp) + EnumChatFormatting.DARK_GRAY + " (" + + numberFormat.format(levelObj.totalXp) + EnumChatFormatting.DARK_GRAY + " (" + DECIMAL_FORMAT.format(getPercentage(skillName.toLowerCase(), levelObj)) + "% to 50)"; } - // Adds overflow level to each level object that is maxed, avoids hotm level as there is no overflow xp for it + // Adds overflow level to each level object that is maxed, avoids hotm level as there is no overflow xp for it if (levelObj.maxed) { levelStr = levelObj.maxLevel != 7 ? - EnumChatFormatting.GOLD + "MAXED!" + EnumChatFormatting.GRAY + " (Overflow level: " + String.format( - "%.2f", - levelObj.level - ) + ")" : - EnumChatFormatting.GOLD + "MAXED!"; + EnumChatFormatting.GOLD + "MAXED!" + EnumChatFormatting.GRAY + " (Overflow level: " + String.format("%.2f", levelObj.level) + ")" : + EnumChatFormatting.GOLD + "MAXED!"; } else { if (skillName.contains("Class Average")) { levelStr = "Progress: " + EnumChatFormatting.DARK_PURPLE + String.format("%.1f", (level % 1 * 100)) + "%"; totalXpStr = "Exact Class Average: " + EnumChatFormatting.WHITE + String.format("%.2f", levelObj.level); } else { - final int maxXp = (int) levelObj.maxXpForLevel; + int maxXp = (int) levelObj.maxXpForLevel; levelStr = EnumChatFormatting.DARK_PURPLE + StringUtils.shortNumberFormat(Math.round((level % 1) * maxXp)) + @@ -1006,8 +993,8 @@ public class GuiProfileViewer extends GuiScreen { } } - final NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs - final NBTTagCompound display = new NBTTagCompound(); + NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs + NBTTagCompound display = new NBTTagCompound(); display.setString("Name", skillName); nbt.setTag("display", display); stack.setTagCompound(nbt); @@ -1023,14 +1010,14 @@ public class GuiProfileViewer extends GuiScreen { return ((BasicPage) pages.get(ProfileViewerPage.BASIC)).entityPlayer; } - public void renderGoldBar(final float x, final float y, final float xSize) { + public void renderGoldBar(float x, float y, float xSize) { if (!OpenGlHelper.areShadersSupported()) { renderBar(x, y, xSize, 1); return; } Minecraft.getMinecraft().getTextureManager().bindTexture(icons); - final ShaderManager shaderManager = ShaderManager.getInstance(); + ShaderManager shaderManager = ShaderManager.getInstance(); shaderManager.loadShader("make_gold"); shaderManager.loadData("make_gold", "amount", (startTime - System.currentTimeMillis()) / 10000f); @@ -1050,11 +1037,11 @@ public class GuiProfileViewer extends GuiScreen { GL20.glUseProgram(0); } - public void renderBar(final float x, final float y, final float xSize, float completed) { + public void renderBar(float x, float y, float xSize, float completed) { Minecraft.getMinecraft().getTextureManager().bindTexture(icons); completed = Math.round(completed / 0.05f) * 0.05f; - final float notCompleted = 1 - completed; + float notCompleted = 1 - completed; GlStateManager.color(1, 1, 1, 1); float width; @@ -1118,8 +1105,8 @@ public class GuiProfileViewer extends GuiScreen { * This is so that we can render to and from the framebuffer in a way that is familiar to us, instead of needing to * apply scales and translations manually. */ - private Matrix4f createProjectionMatrix(final int width, final int height) { - final Matrix4f projMatrix = new Matrix4f(); + private Matrix4f createProjectionMatrix(int width, int height) { + Matrix4f projMatrix = new Matrix4f(); projMatrix.setIdentity(); projMatrix.m00 = 2.0F / (float) width; projMatrix.m11 = 2.0F / (float) (-height); @@ -1134,8 +1121,8 @@ public class GuiProfileViewer extends GuiScreen { private void blurBackground() { if (!OpenGlHelper.isFramebufferEnabled()) return; - final int width = Minecraft.getMinecraft().displayWidth; - final int height = Minecraft.getMinecraft().displayHeight; + int width = Minecraft.getMinecraft().displayWidth; + int height = Minecraft.getMinecraft().displayHeight; if (blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); @@ -1167,7 +1154,7 @@ public class GuiProfileViewer extends GuiScreen { ); blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (final Exception ignored) { + } catch (Exception ignored) { } } if (blurShaderVert == null) { @@ -1180,7 +1167,7 @@ public class GuiProfileViewer extends GuiScreen { ); blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch (final Exception ignored) { + } catch (Exception ignored) { } } if (blurShaderHorz != null && blurShaderVert != null) { @@ -1199,7 +1186,7 @@ public class GuiProfileViewer extends GuiScreen { } } - public float getPercentage(final String skillName, final ProfileViewer.Level level) { + public float getPercentage(String skillName, ProfileViewer.Level level) { if (level.maxed) { return 100; } @@ -1222,13 +1209,13 @@ public class GuiProfileViewer extends GuiScreen { * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] */ - public void renderBlurredBackground(final int width, final int height, final int x, final int y, final int blurWidth, final int blurHeight) { + public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { if (!OpenGlHelper.isFramebufferEnabled()) return; - final float uMin = x / (float) width; - final float uMax = (x + blurWidth) / (float) width; - final float vMin = (height - y) / (float) height; - final float vMax = (height - y - blurHeight) / (float) height; + float uMin = x / (float) width; + float uMax = (x + blurWidth) / (float) width; + float vMin = (height - y) / (float) height; + float vMax = (height - y - blurHeight) / (float) height; blurOutputVert.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); @@ -1261,22 +1248,22 @@ public class GuiProfileViewer extends GuiScreen { this(-1, null, null); } - ProfileViewerPage(final int id, final Item item, final String name) { + ProfileViewerPage(int id, Item item, String name) { this.id = id; if (item == null) { stack = null; } else { stack = new ItemStack(item); - final NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs - final NBTTagCompound display = new NBTTagCompound(); + NBTTagCompound nbt = new NBTTagCompound(); //Adding NBT Data for Custom Resource Packs + NBTTagCompound display = new NBTTagCompound(); display.setString("Name", name); nbt.setTag("display", display); stack.setTagCompound(nbt); } } - public static ProfileViewerPage getById(final int id) { - for (final ProfileViewerPage page : values()) { + public static ProfileViewerPage getById(int id) { + for (ProfileViewerPage page : values()) { if (page.id == id) { return page; } 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 8aef917c..63c2435a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -19,7 +19,6 @@ package io.github.moulberry.notenoughupdates.profileviewer; -import com.google.common.collect.ImmutableMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -57,56 +56,47 @@ import java.util.regex.Pattern; public class ProfileViewer { - private static final ImmutableMap petRarityToNumMap = - ImmutableMap.builder() - .put("COMMON", "0") - .put("UNCOMMON", "1") - .put("RARE", "2") - .put("EPIC", "3") - .put("LEGENDARY", "4") - .put("MYTHIC", "5") - .build(); - - private static final ImmutableMap skillToSkillDisplayMap = - ImmutableMap.builder() - .put("taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE + "Taming")) - .put("mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY + "Mining")) - .put( - "foraging", - Utils.createItemStack( - Item.getItemFromBlock(Blocks.sapling), - EnumChatFormatting.DARK_GREEN + "Foraging" - ) - ) - .put( - "enchanting", - Utils.createItemStack( - Item.getItemFromBlock(Blocks.enchanting_table), - EnumChatFormatting.GREEN + "Enchanting" - ) - ) - .put( - "carpentry", - Utils.createItemStack( - Item.getItemFromBlock(Blocks.crafting_table), - EnumChatFormatting.DARK_RED + "Carpentry" - ) - ) - .put("farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming")) - .put("combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED + "Combat")) - .put("fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA + "Fishing")) - .put("alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE + "Alchemy")) - .put( - "runecrafting", - Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE + "Runecrafting") - ) - .put("social", Utils.createItemStack(Items.emerald, EnumChatFormatting.DARK_GREEN + "Social")) - .put("zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD + "Rev Slayer")) - .put("spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD + "Tara Slayer")) - .put("wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD + "Sven Slayer")) - .put("enderman", Utils.createItemStack(Items.ender_pearl, EnumChatFormatting.GOLD + "Ender Slayer")) - .put("blaze", Utils.createItemStack(Items.blaze_rod, EnumChatFormatting.GOLD + "Blaze Slayer")) - .build(); + private static final HashMap petRarityToNumMap = new HashMap() { + { + put("COMMON", "0"); + put("UNCOMMON", "1"); + put("RARE", "2"); + put("EPIC", "3"); + put("LEGENDARY", "4"); + put("MYTHIC", "5"); + } + }; + private static final LinkedHashMap skillToSkillDisplayMap = + new LinkedHashMap() { + { + put("taming", Utils.createItemStack(Items.spawn_egg, EnumChatFormatting.LIGHT_PURPLE + "Taming")); + put("mining", Utils.createItemStack(Items.stone_pickaxe, EnumChatFormatting.GRAY + "Mining")); + put( + "foraging", + Utils.createItemStack(Item.getItemFromBlock(Blocks.sapling), EnumChatFormatting.DARK_GREEN + "Foraging") + ); + put( + "enchanting", + Utils.createItemStack(Item.getItemFromBlock(Blocks.enchanting_table), EnumChatFormatting.GREEN + "Enchanting") + ); + put( + "carpentry", + Utils.createItemStack(Item.getItemFromBlock(Blocks.crafting_table), EnumChatFormatting.DARK_RED + "Carpentry") + ); + put("farming", Utils.createItemStack(Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming")); + put("combat", Utils.createItemStack(Items.stone_sword, EnumChatFormatting.RED + "Combat")); + put("fishing", Utils.createItemStack(Items.fishing_rod, EnumChatFormatting.AQUA + "Fishing")); + put("alchemy", Utils.createItemStack(Items.brewing_stand, EnumChatFormatting.BLUE + "Alchemy")); + put("runecrafting", Utils.createItemStack(Items.magma_cream, EnumChatFormatting.DARK_PURPLE + "Runecrafting")); + put("social", Utils.createItemStack(Items.emerald, EnumChatFormatting.DARK_GREEN + "Social")); + // put("catacombs", Utils.createItemStack(Item.getItemFromBlock(Blocks.deadbush), EnumChatFormatting.GOLD+"Catacombs")); + put("zombie", Utils.createItemStack(Items.rotten_flesh, EnumChatFormatting.GOLD + "Rev Slayer")); + put("spider", Utils.createItemStack(Items.spider_eye, EnumChatFormatting.GOLD + "Tara Slayer")); + put("wolf", Utils.createItemStack(Items.bone, EnumChatFormatting.GOLD + "Sven Slayer")); + put("enderman", Utils.createItemStack(Items.ender_pearl, EnumChatFormatting.GOLD + "Ender Slayer")); + put("blaze", Utils.createItemStack(Items.blaze_rod, EnumChatFormatting.GOLD + "Blaze Slayer")); + } + }; private static final ItemStack CAT_FARMING = Utils.createItemStack( Items.golden_hoe, EnumChatFormatting.YELLOW + "Farming" @@ -461,7 +451,7 @@ public class ProfileViewer { private final HashMap uuidToProfileMap = new HashMap<>(); private final HashMap nameToUuid = new HashMap<>(); - public ProfileViewer(final NEUManager manager) { + public ProfileViewer(NEUManager manager) { this.manager = manager; } @@ -478,20 +468,20 @@ public class ProfileViewer { } public static Map getSkillToSkillDisplayMap() { - return skillToSkillDisplayMap; + return Collections.unmodifiableMap(skillToSkillDisplayMap); } - public static Level getLevel(final JsonArray levelingArray, float xp, final int levelCap, final boolean cumulative) { - final Level levelObj = new Level(); + public static Level getLevel(JsonArray levelingArray, float xp, int levelCap, boolean cumulative) { + Level levelObj = new Level(); levelObj.totalXp = xp; levelObj.maxLevel = levelCap; for (int level = 0; level < levelingArray.size(); level++) { - final float levelXp = levelingArray.get(level).getAsFloat(); + float levelXp = levelingArray.get(level).getAsFloat(); if (levelXp > xp) { if (cumulative) { - final float previous = level > 0 ? levelingArray.get(level - 1).getAsFloat() : 0; + float previous = level > 0 ? levelingArray.get(level - 1).getAsFloat() : 0; levelObj.maxXpForLevel = (levelXp - previous); levelObj.level = 1 + level + (xp - levelXp) / levelObj.maxXpForLevel; } else { @@ -535,8 +525,8 @@ public class ProfileViewer { return null; } - public void getHypixelProfile(final String name, final Consumer callback) { - final String nameF = name.toLowerCase(); + public void getHypixelProfile(String name, Consumer callback) { + String nameF = name.toLowerCase(); manager.apiUtils .newHypixelApiRequest("player") .queryArgument("name", nameF) @@ -561,12 +551,12 @@ public class ProfileViewer { ); } - public void putNameUuid(final String name, final String uuid) { + public void putNameUuid(String name, String uuid) { nameToUuid.put(name, uuid); } - public void getPlayerUUID(final String name, final Consumer uuidCallback) { - final String nameF = name.toLowerCase(); + public void getPlayerUUID(String name, Consumer uuidCallback) { + String nameF = name.toLowerCase(); if (nameToUuid.containsKey(nameF)) { uuidCallback.accept(nameToUuid.get(nameF)); return; @@ -579,7 +569,7 @@ public class ProfileViewer { .thenAccept(jsonObject -> { if (jsonObject.has("id") && jsonObject.get("id").isJsonPrimitive() && ((JsonPrimitive) jsonObject.get("id")).isString()) { - final String uuid = jsonObject.get("id").getAsString(); + String uuid = jsonObject.get("id").getAsString(); nameToUuid.put(nameF, uuid); uuidCallback.accept(uuid); return; @@ -588,8 +578,8 @@ public class ProfileViewer { }); } - public void getProfileByName(final String name, final Consumer callback) { - final String nameF = name.toLowerCase(); + public void getProfileByName(String name, Consumer callback) { + String nameF = name.toLowerCase(); if (nameToUuid.containsKey(nameF) && nameToUuid.get(nameF) == null) { callback.accept(null); @@ -621,8 +611,8 @@ public class ProfileViewer { ); } - public Profile getProfile(final String uuid, final Consumer callback) { - final Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid)); + public Profile getProfile(String uuid, Consumer callback) { + Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid)); if (profile.skyblockProfiles != null) { callback.accept(profile); } else { @@ -631,7 +621,7 @@ public class ProfileViewer { return profile; } - public Profile getProfileReset(final String uuid, final Consumer callback) { + public Profile getProfileReset(String uuid, Consumer callback) { if (uuidToProfileMap.containsKey(uuid)) uuidToProfileMap.get(uuid).resetCache(); return getProfile(uuid, callback); } @@ -677,7 +667,7 @@ public class ProfileViewer { private long lastGuildInfoState = 0; private long lastBingoInfoState = 0; - public Profile(final String uuid) { + public Profile(String uuid) { this.uuid = uuid; } @@ -685,12 +675,12 @@ public class ProfileViewer { if (playerStatus != null) return playerStatus; if (updatingPlayerStatusState.get()) return null; - final long currentTime = System.currentTimeMillis(); + long currentTime = System.currentTimeMillis(); if (currentTime - lastStatusInfoState < 15 * 1000) return null; lastStatusInfoState = currentTime; updatingPlayerStatusState.set(true); - final HashMap args = new HashMap<>(); + HashMap args = new HashMap<>(); args.put("uuid", "" + uuid); manager.apiUtils .newHypixelApiRequest("status") @@ -708,9 +698,8 @@ public class ProfileViewer { } public JsonObject getBingoInformation() { - final long currentTime = System.currentTimeMillis(); - if (bingoInformation != null && currentTime - - lastBingoInfoState < 15 * 1000) return bingoInformation; + long currentTime = System.currentTimeMillis(); + if (bingoInformation != null && currentTime - lastBingoInfoState < 15 * 1000) return bingoInformation; if (updatingBingoInfo.get() && bingoInformation != null) return bingoInformation; if (updatingBingoInfo.get() && bingoInformation == null) return null; @@ -735,11 +724,11 @@ public class ProfileViewer { } public class SoopyNetworthData { - private final HashMap categoryWorth; + private HashMap categoryWorth; private Long totalWorth; - private final String[] keys; + private String[] keys; - SoopyNetworthData(final JsonObject nwData) { + SoopyNetworthData(JsonObject nwData) { categoryWorth = new HashMap<>(); if (nwData == null || nwData.isJsonNull()) { @@ -754,7 +743,7 @@ public class ProfileViewer { } totalWorth = nwData.get("total").getAsLong(); - for (final Map.Entry entry : nwData.get("categories").getAsJsonObject().entrySet()) { + for (Map.Entry entry : nwData.get("categories").getAsJsonObject().entrySet()) { if (entry.getValue().isJsonNull()) { continue; } @@ -778,7 +767,7 @@ public class ProfileViewer { return totalWorth; } - public long getCategory(final String name) { + public long getCategory(String name) { if (categoryWorth.containsKey(name)) return categoryWorth.get(name); return 0; } @@ -802,16 +791,16 @@ public class ProfileViewer { return soopyWeightLeaderboardPosition; } - public boolean isProfileMaxSoopyWeight(final ProfileViewer.Profile profile, final String profileName) { + public boolean isProfileMaxSoopyWeight(ProfileViewer.Profile profile, String profileName) { String highestProfileName = ""; double largestProfileWeight = 0; for (int yIndex = 0; yIndex < profileNames.size(); yIndex++) { - final String otherProfileId = profileNames.get(yIndex); - final Map skyblockInfo = profile.getSkyblockInfo(otherProfileId); + String otherProfileId = profileNames.get(yIndex); + Map skyblockInfo = profile.getSkyblockInfo(otherProfileId); if (skyblockInfo == null) continue; - final SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); - final double weightValue = senitherWeight.getTotalWeight().getRaw(); + SenitherWeight senitherWeight = new SenitherWeight(skyblockInfo); + double weightValue = senitherWeight.getTotalWeight().getRaw(); if (weightValue > largestProfileWeight) { largestProfileWeight = weightValue; @@ -826,14 +815,14 @@ public class ProfileViewer { * Returns SoopyNetworthData with total = -1 if error * Returns null if still loading */ - public SoopyNetworthData getSoopyNetworth(String profileName, final Runnable callback) { + public SoopyNetworthData getSoopyNetworth(String profileName, Runnable callback) { if (profileName == null) profileName = latestProfile; if (soopyNetworth.get(profileName) != null) { callback.run(); return soopyNetworth.get(profileName); } - final JsonArray playerInfo = getSkyblockProfiles(() -> {}); + JsonArray playerInfo = getSkyblockProfiles(() -> {}); if (playerInfo == null) return null; //Not sure how to support the callback in these cases if (updatingSoopyNetworth.get()) @@ -843,7 +832,7 @@ public class ProfileViewer { soopyNetworthLeaderboardPosition = -2; //loading manager.apiUtils .request() - .url("https://soopy.dev/api/v2/leaderboard/networth/user/" + uuid) + .url("https://soopy.dev/api/v2/leaderboard/networth/user/" + this.uuid) .requestJson() .handle((jsonObject, throwable) -> { if (throwable != null) throwable.printStackTrace(); @@ -864,7 +853,7 @@ public class ProfileViewer { soopyWeightLeaderboardPosition = -2; //loading manager.apiUtils .request() - .url("https://soopy.dev/api/v2/leaderboard/weight/user/" + uuid) + .url("https://soopy.dev/api/v2/leaderboard/weight/user/" + this.uuid) .requestJson() .handle((jsonObject, throwable) -> { if (throwable != null) throwable.printStackTrace(); @@ -884,7 +873,7 @@ public class ProfileViewer { manager.apiUtils .request() - .url("https://soopy.dev/api/v2/player_networth/" + uuid) + .url("https://soopy.dev/api/v2/player_networth/" + this.uuid) .method("POST") .postData("application/json", skyblockProfiles.toString()) .requestJson() @@ -897,9 +886,9 @@ public class ProfileViewer { if (!skyblockProfiles.get(i).isJsonObject()) { return null; } - final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - final String cuteName = profile.get("cute_name").getAsString(); + String cuteName = profile.get("cute_name").getAsString(); soopyNetworth.put(cuteName, new SoopyNetworthData(null)); } @@ -913,22 +902,19 @@ public class ProfileViewer { if (!skyblockProfiles.get(i).isJsonObject()) { return null; } - final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); - final String cuteName = profile.get("cute_name").getAsString(); - final String profileId = profile.get("profile_id").getAsString(); + String cuteName = profile.get("cute_name").getAsString(); + String profileId = profile.get("profile_id").getAsString(); - final SoopyNetworthData soopyNetworthData; + SoopyNetworthData networth; if (jsonObject.getAsJsonObject("data").get(profileId).isJsonNull()) { - soopyNetworthData = new SoopyNetworthData(null); + networth = new SoopyNetworthData(null); } else { - soopyNetworthData = new SoopyNetworthData(jsonObject - .getAsJsonObject("data") - .get(profileId) - .getAsJsonObject()); + networth = new SoopyNetworthData(jsonObject.getAsJsonObject("data").get(profileId).getAsJsonObject()); } - soopyNetworth.put(cuteName, soopyNetworthData); + soopyNetworth.put(cuteName, networth); } updatingSoopyNetworth.set(false); @@ -944,53 +930,73 @@ public class ProfileViewer { if (getProfileInformation(profileName) == null) return -1; if (getInventoryInfo(profileName) == null) return -1; - final JsonObject inventoryInfo = getInventoryInfo(profileName); - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject inventoryInfo = getInventoryInfo(profileName); + JsonObject profileInfo = getProfileInformation(profileName); - final HashMap mostExpensiveInternal = new HashMap<>(); + HashMap mostExpensiveInternal = new HashMap<>(); - long playerNetworth = 0; - for (final Map.Entry entry : inventoryInfo.entrySet()) { + long networth = 0; + for (Map.Entry entry : inventoryInfo.entrySet()) { if (entry.getValue().isJsonArray()) { - for (final JsonElement element : entry.getValue().getAsJsonArray()) { + for (JsonElement element : entry.getValue().getAsJsonArray()) { if (element != null && element.isJsonObject()) { - final JsonObject item = element.getAsJsonObject(); - final String internalname = item.get("internalname").getAsString(); + JsonObject item = element.getAsJsonObject(); + String internalname = item.get("internalname").getAsString(); if (manager.auctionManager.isVanillaItem(internalname)) continue; - final long auctionPrice = getAuctionPriceHelper(internalname); + JsonObject bzInfo = manager.auctionManager.getBazaarInfo(internalname); + + long auctionPrice; + if (bzInfo != null && bzInfo.has("curr_sell")) { + auctionPrice = (int) bzInfo.get("curr_sell").getAsFloat(); + } else { + auctionPrice = (long) manager.auctionManager.getItemAvgBin(internalname); + if (auctionPrice <= 0) { + auctionPrice = manager.auctionManager.getLowestBin(internalname); + } + } try { if (item.has("item_contents")) { - final JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); - final byte[] bytes = new byte[bytesArr.size()]; + JsonArray bytesArr = item.get("item_contents").getAsJsonArray(); + byte[] bytes = new byte[bytesArr.size()]; for (int bytesArrI = 0; bytesArrI < bytesArr.size(); bytesArrI++) { bytes[bytesArrI] = bytesArr.get(bytesArrI).getAsByte(); } - final NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream( - bytes)); - final NBTTagList items = contents_nbt.getTagList("i", 10); + NBTTagCompound contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(bytes)); + NBTTagList items = contents_nbt.getTagList("i", 10); for (int j = 0; j < items.tagCount(); j++) { - if (!items.getCompoundTagAt(j).getKeySet().isEmpty()) { - final NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); - final String internalname2 = manager.getInternalnameFromNBT(nbt); + if (items.getCompoundTagAt(j).getKeySet().size() > 0) { + NBTTagCompound nbt = items.getCompoundTagAt(j).getCompoundTag("tag"); + String internalname2 = manager.getInternalnameFromNBT(nbt); if (internalname2 != null) { if (manager.auctionManager.isVanillaItem(internalname2)) continue; - final long auctionPrice2 = getAuctionPriceHelper(internalname2); - final int count2 = items.getCompoundTagAt(j).getByte("Count"); + JsonObject bzInfo2 = manager.auctionManager.getBazaarInfo(internalname2); + + long auctionPrice2; + if (bzInfo2 != null && bzInfo2.has("curr_sell")) { + auctionPrice2 = (int) bzInfo2.get("curr_sell").getAsFloat(); + } else { + auctionPrice2 = (long) manager.auctionManager.getItemAvgBin(internalname2); + if (auctionPrice2 <= 0) { + auctionPrice2 = manager.auctionManager.getLowestBin(internalname2); + } + } + + int count2 = items.getCompoundTagAt(j).getByte("Count"); mostExpensiveInternal.put( internalname2, auctionPrice2 * count2 + mostExpensiveInternal.getOrDefault(internalname2, 0L) ); - playerNetworth += auctionPrice2 * count2; + networth += auctionPrice2 * count2; } } } } - } catch (final IOException ignored) { + } catch (IOException ignored) { } int count = 1; @@ -1001,68 +1007,56 @@ public class ProfileViewer { internalname, auctionPrice * count + mostExpensiveInternal.getOrDefault(internalname, 0L) ); - playerNetworth += auctionPrice * count; + networth += auctionPrice * count; } } } } - if (playerNetworth == 0) return -1; - - playerNetworth = (int) (playerNetworth * 1.3f); - - final JsonObject petsInfo = getPetsInfo(profileName); - if (petsInfo != null && petsInfo.has("pets") && petsInfo.get("pets").isJsonArray()) { - final JsonArray pets = petsInfo.get("pets").getAsJsonArray(); - for (final JsonElement element : pets) { - if (element.isJsonObject()) { - final JsonObject pet = element.getAsJsonObject(); - - final String petname = pet.get("type").getAsString(); - final String tier = pet.get("tier").getAsString(); - final String tierNum = petRarityToNumMap.get(tier); - if (tierNum != null) { - final String internalname2 = petname + ";" + tierNum; - final JsonObject info2 = manager.auctionManager.getItemAuctionInfo(internalname2); - if (info2 == null || !info2.has("price") || !info2.has("count")) continue; - final int auctionPrice2 = (int) (info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); - - playerNetworth += auctionPrice2; + if (networth == 0) return -1; + + networth = (int) (networth * 1.3f); + + JsonObject petsInfo = getPetsInfo(profileName); + if (petsInfo != null && petsInfo.has("pets")) { + if (petsInfo.get("pets").isJsonArray()) { + JsonArray pets = petsInfo.get("pets").getAsJsonArray(); + for (JsonElement element : pets) { + if (element.isJsonObject()) { + JsonObject pet = element.getAsJsonObject(); + + String petname = pet.get("type").getAsString(); + String tier = pet.get("tier").getAsString(); + String tierNum = petRarityToNumMap.get(tier); + if (tierNum != null) { + String internalname2 = petname + ";" + tierNum; + JsonObject info2 = manager.auctionManager.getItemAuctionInfo(internalname2); + if (info2 == null || !info2.has("price") || !info2.has("count")) continue; + int auctionPrice2 = (int) (info2.get("price").getAsFloat() / info2.get("count").getAsFloat()); + + networth += auctionPrice2; + } } } } } - final float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), 0); - final float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); + float bankBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "banking.balance"), 0); + float purseBalance = Utils.getElementAsFloat(Utils.getElement(profileInfo, "coin_purse"), 0); - playerNetworth += bankBalance + purseBalance; + networth += bankBalance + purseBalance; - networth.put(profileName, playerNetworth); - return playerNetworth; - } - - private long getAuctionPriceHelper(final String internalname) { - final JsonObject bzInfo = manager.auctionManager.getBazaarInfo(internalname); - - if (bzInfo != null && bzInfo.has("curr_sell")) { - return (int) bzInfo.get("curr_sell").getAsFloat(); - } else { - final long auctionPrice = (long) manager.auctionManager.getItemAvgBin(internalname); - if (auctionPrice <= 0) { - return manager.auctionManager.getLowestBin(internalname); - } - return auctionPrice; - } + this.networth.put(profileName, networth); + return networth; } public String getLatestProfile() { return latestProfile; } - public JsonArray getSkyblockProfiles(final Runnable runnable) { + public JsonArray getSkyblockProfiles(Runnable runnable) { if (skyblockProfiles != null) return skyblockProfiles; - final long currentTime = System.currentTimeMillis(); + long currentTime = System.currentTimeMillis(); if (currentTime - lastPlayerInfoState < 15 * 1000 && updatingSkyblockProfilesState.get()) return null; lastPlayerInfoState = currentTime; @@ -1083,21 +1077,22 @@ public class ProfileViewer { profileNames.clear(); - for (final JsonElement profileEle : skyblockProfiles) { - final JsonObject profile = profileEle.getAsJsonObject(); + for (JsonElement profileEle : skyblockProfiles) { + JsonObject profile = profileEle.getAsJsonObject(); if (!profile.has("members")) continue; - final JsonObject members = profile.get("members").getAsJsonObject(); + JsonObject members = profile.get("members").getAsJsonObject(); if (members.has(uuid)) { - final JsonObject member = members.get(uuid).getAsJsonObject(); + JsonObject member = members.get(uuid).getAsJsonObject(); - if (member.has("coop_invitation") && - !member.get("coop_invitation").getAsJsonObject().get("confirmed").getAsBoolean()) { - continue; + if (member.has("coop_invitation")) { + if (!member.get("coop_invitation").getAsJsonObject().get("confirmed").getAsBoolean()) { + continue; + } } - final String cuteName = profile.get("cute_name").getAsString(); + String cuteName = profile.get("cute_name").getAsString(); profileNames.add(cuteName); if (profile.has("selected") && profile.get("selected").getAsBoolean()) { lastCuteName = cuteName; @@ -1113,10 +1108,10 @@ public class ProfileViewer { return null; } - public JsonObject getGuildInformation(final Runnable runnable) { + public JsonObject getGuildInformation(Runnable runnable) { if (guildInformation != null) return guildInformation; - final long currentTime = System.currentTimeMillis(); + long currentTime = System.currentTimeMillis(); if (currentTime - lastGuildInfoState < 15 * 1000 && updatingGuildInfoState.get()) return null; lastGuildInfoState = currentTime; @@ -1146,7 +1141,7 @@ public class ProfileViewer { } public JsonObject getProfileInformation(String profileName) { - final JsonArray playerInfo = getSkyblockProfiles(() -> {}); + JsonArray playerInfo = getSkyblockProfiles(() -> {}); if (playerInfo == null) return null; if (profileName == null) profileName = latestProfile; if (profileMap.containsKey(profileName)) return profileMap.get(profileName); @@ -1156,12 +1151,12 @@ public class ProfileViewer { skyblockProfiles = null; return null; } - final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { if (!profile.has("members")) return null; - final JsonObject members = profile.get("members").getAsJsonObject(); + JsonObject members = profile.get("members").getAsJsonObject(); if (!members.has(uuid)) continue; - final JsonObject profileInfo = members.get(uuid).getAsJsonObject(); + JsonObject profileInfo = members.get(uuid).getAsJsonObject(); if (profile.has("banking")) { profileInfo.add("banking", profile.get("banking").getAsJsonObject()); } @@ -1177,25 +1172,25 @@ public class ProfileViewer { } public List getCoopProfileInformation(String profileName) { - final JsonArray playerInfo = getSkyblockProfiles(() -> {}); - if (playerInfo == null) return Collections.emptyList(); + JsonArray playerInfo = getSkyblockProfiles(() -> {}); + if (playerInfo == null) return null; if (profileName == null) profileName = latestProfile; if (coopProfileMap.containsKey(profileName)) return coopProfileMap.get(profileName); for (int i = 0; i < skyblockProfiles.size(); i++) { if (!skyblockProfiles.get(i).isJsonObject()) { skyblockProfiles = null; - return Collections.emptyList(); + return null; } - final JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); + JsonObject profile = skyblockProfiles.get(i).getAsJsonObject(); if (profile.get("cute_name").getAsString().equalsIgnoreCase(profileName)) { - if (!profile.has("members")) return Collections.emptyList(); - final JsonObject members = profile.get("members").getAsJsonObject(); - if (!members.has(uuid)) return Collections.emptyList(); - final List coopList = new ArrayList<>(); - for (final Map.Entry islandMember : members.entrySet()) { + if (!profile.has("members")) return null; + JsonObject members = profile.get("members").getAsJsonObject(); + if (!members.has(uuid)) return null; + List coopList = new ArrayList<>(); + for (Map.Entry islandMember : members.entrySet()) { if (!islandMember.getKey().equals(uuid)) { - final JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); + JsonObject coopProfileInfo = islandMember.getValue().getAsJsonObject(); coopList.add(coopProfileInfo); } } @@ -1204,7 +1199,7 @@ public class ProfileViewer { } } - return Collections.emptyList(); + return null; } public void resetCache() { @@ -1223,30 +1218,30 @@ public class ProfileViewer { networth.clear(); } - public int getCap(final JsonObject leveling, final String skillName) { - final JsonElement capsElement = Utils.getElement(leveling, "leveling_caps"); + public int getCap(JsonObject leveling, String skillName) { + JsonElement capsElement = Utils.getElement(leveling, "leveling_caps"); return capsElement != null && capsElement.isJsonObject() && capsElement.getAsJsonObject().has(skillName) ? capsElement.getAsJsonObject().get(skillName).getAsInt() : 50; } public Map getSkyblockInfo(String profileName) { - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject profileInfo = getProfileInformation(profileName); - if (profileInfo == null) return Collections.emptyMap(); + if (profileInfo == null) return null; if (profileName == null) profileName = latestProfile; - final List coopProfileInfo = getCoopProfileInformation(profileName); + List coopProfileInfo = getCoopProfileInformation(profileName); if (skyblockInfoCache.containsKey(profileName)) return skyblockInfoCache.get(profileName); - final JsonObject leveling = Constants.LEVELING; + JsonObject leveling = Constants.LEVELING; if (leveling == null || !leveling.has("social")) { Utils.showOutdatedRepoNotification(); - return Collections.emptyMap(); + return null; } - final Map out = new HashMap<>(); + Map out = new HashMap<>(); - final List skills = Arrays.asList( + List skills = Arrays.asList( "taming", "mining", "foraging", @@ -1260,14 +1255,14 @@ public class ProfileViewer { "social" ); float totalSkillXP = 0; - for (final String skillName : skills) { + for (String skillName : skills) { float skillExperience = Utils.getElementAsFloat( Utils.getElement(profileInfo, "experience_skill_" + (skillName.equals("social") ? "social2" : skillName)), 0 ); // Get the coop's social skill experience since social is a shared skill if (skillName.equals("social")) { - for (final JsonObject coopProfile : coopProfileInfo) { + for (JsonObject coopProfile : coopProfileInfo) { skillExperience += Utils.getElementAsFloat( Utils.getElement(coopProfile, "experience_skill_social2"), 0 @@ -1283,7 +1278,7 @@ public class ProfileViewer { levelingArray = Utils.getElement(leveling, "social").getAsJsonArray(); } - final int maxLevel = + int maxLevel = getCap(leveling, skillName) + ( skillName.equals("farming") @@ -1295,7 +1290,7 @@ public class ProfileViewer { // Skills API disabled? if (totalSkillXP <= 0) { - return Collections.emptyMap(); + return null; } out.put( @@ -1318,9 +1313,9 @@ public class ProfileViewer { ) ); - final List dungeonClasses = Arrays.asList("healer", "tank", "mage", "archer", "berserk"); - for (final String className : dungeonClasses) { - final float classExperience = Utils.getElementAsFloat( + List dungeonClasses = Arrays.asList("healer", "tank", "mage", "archer", "berserk"); + for (String className : dungeonClasses) { + float classExperience = Utils.getElementAsFloat( Utils.getElement(profileInfo, "dungeons.player_classes." + className + ".experience"), 0 ); @@ -1335,9 +1330,9 @@ public class ProfileViewer { ); } - final List slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze"); - for (final String slayerName : slayers) { - final float slayerExperience = Utils.getElementAsFloat(Utils.getElement( + List slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze"); + for (String slayerName : slayers) { + float slayerExperience = Utils.getElementAsFloat(Utils.getElement( profileInfo, "slayer_bosses." + slayerName + ".xp" ), 0); @@ -1353,64 +1348,64 @@ public class ProfileViewer { } public JsonObject getInventoryInfo(String profileName) { - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; if (profileName == null) profileName = latestProfile; if (inventoryCacheMap.containsKey(profileName)) return inventoryCacheMap.get(profileName); - final String inv_armor_bytes = Utils.getElementAsString( + String inv_armor_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "inv_armor.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String fishing_bag_bytes = Utils.getElementAsString( + String fishing_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "fishing_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String quiver_bytes = Utils.getElementAsString( + String quiver_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "quiver.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String ender_chest_contents_bytes = Utils.getElementAsString( + String ender_chest_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "ender_chest_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); //Todo clean this up //Fake string is so for I loop works the same - final String backpack_contents_json_fake = "fake should fix later"; - final JsonObject backpack_contents_json = (JsonObject) Utils.getElement(profileInfo, "backpack_contents"); - final JsonObject backpack_icons = (JsonObject) Utils.getElement(profileInfo, "backpack_icons"); - final String personal_vault_contents_bytes = Utils.getElementAsString( + String backpack_contents_json_fake = "fake should fix later"; + JsonObject backpack_contents_json = (JsonObject) Utils.getElement(profileInfo, "backpack_contents"); + JsonObject backpack_icons = (JsonObject) Utils.getElement(profileInfo, "backpack_icons"); + String personal_vault_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "personal_vault_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String wardrobe_contents_bytes = Utils.getElementAsString( + String wardrobe_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "wardrobe_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String potion_bag_bytes = Utils.getElementAsString( + String potion_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "potion_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String inv_contents_bytes = Utils.getElementAsString( + String inv_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "inv_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String talisman_bag_bytes = Utils.getElementAsString( + String talisman_bag_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "talisman_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String candy_inventory_contents_bytes = Utils.getElementAsString( + String candy_inventory_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "candy_inventory_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final String equipment_contents_bytes = Utils.getElementAsString( + String equipment_contents_bytes = Utils.getElementAsString( Utils.getElement(profileInfo, "equippment_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" ); - final JsonObject inventoryInfo = new JsonObject(); + JsonObject inventoryInfo = new JsonObject(); - final String[] inv_names = new String[]{ + String[] inv_names = new String[]{ "inv_armor", "fishing_bag", "quiver", @@ -1424,7 +1419,7 @@ public class ProfileViewer { "candy_inventory_contents", "equippment_contents", }; - final String[] inv_bytes = new String[]{ + String[] inv_bytes = new String[]{ inv_armor_bytes, fishing_bag_bytes, quiver_bytes, @@ -1440,26 +1435,26 @@ public class ProfileViewer { }; for (int i = 0; i < inv_bytes.length; i++) { try { - final String bytes = inv_bytes[i]; + String bytes = inv_bytes[i]; JsonArray contents = new JsonArray(); if (inv_names[i].equals("backpack_contents")) { - final JsonObject temp = getBackpackData(backpack_contents_json, backpack_icons); + JsonObject temp = getBackpackData(backpack_contents_json, backpack_icons); contents = (JsonArray) temp.get("contents"); inventoryInfo.add("backpack_sizes", temp.get("backpack_sizes")); } else { - final NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( + NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( new ByteArrayInputStream(Base64.getDecoder().decode(bytes)) ); - final NBTTagList items = inv_contents_nbt.getTagList("i", 10); + NBTTagList items = inv_contents_nbt.getTagList("i", 10); for (int j = 0; j < items.tagCount(); j++) { - final JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); contents.add(item); } } inventoryInfo.add(inv_names[i], contents); - } catch (final IOException e) { + } catch (IOException e) { inventoryInfo.add(inv_names[i], new JsonArray()); } } @@ -1469,9 +1464,9 @@ public class ProfileViewer { return inventoryInfo; } - public JsonObject getBackpackData(final JsonObject backpackContentsJson, final JsonObject backpackIcons) { + public JsonObject getBackpackData(JsonObject backpackContentsJson, JsonObject backpackIcons) { if (backpackContentsJson == null || backpackIcons == null) { - final JsonObject bundledReturn = new JsonObject(); + JsonObject bundledReturn = new JsonObject(); bundledReturn.add("contents", new JsonArray()); bundledReturn.add("backpack_sizes", new JsonArray()); @@ -1481,13 +1476,10 @@ public class ProfileViewer { String[] backpackArray = new String[0]; //Create backpack array which sizes up - for (final Map.Entry backpackIcon : backpackIcons.entrySet()) { + for (Map.Entry backpackIcon : backpackIcons.entrySet()) { if (backpackIcon.getValue() instanceof JsonObject) { - final JsonObject backpackData = (JsonObject) backpackContentsJson.get(backpackIcon.getKey()); - final String bytes = Utils.getElementAsString( - backpackData.get("data"), - "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=" - ); + JsonObject backpackData = (JsonObject) backpackContentsJson.get(backpackIcon.getKey()); + String bytes = Utils.getElementAsString(backpackData.get("data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); backpackArray = growArray(bytes, Integer.parseInt(backpackIcon.getKey()), backpackArray); } } @@ -1495,9 +1487,9 @@ public class ProfileViewer { //reduce backpack array to filter out not existent backpacks { String[] tempBackpackArray = new String[0]; - for (final String s : backpackArray) { + for (String s : backpackArray) { if (s != null) { - final String[] veryTempBackpackArray = new String[tempBackpackArray.length + 1]; + String[] veryTempBackpackArray = new String[tempBackpackArray.length + 1]; System.arraycopy(tempBackpackArray, 0, veryTempBackpackArray, 0, tempBackpackArray.length); veryTempBackpackArray[veryTempBackpackArray.length - 1] = s; @@ -1507,54 +1499,54 @@ public class ProfileViewer { backpackArray = tempBackpackArray; } - final JsonArray backpackSizes = new JsonArray(); - final JsonArray contents = new JsonArray(); + JsonArray backpackSizes = new JsonArray(); + JsonArray contents = new JsonArray(); - for (final String backpack : backpackArray) { + for (String backpack : backpackArray) { try { - final NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( + NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed( new ByteArrayInputStream(Base64.getDecoder().decode(backpack)) ); - final NBTTagList items = inv_contents_nbt.getTagList("i", 10); + NBTTagList items = inv_contents_nbt.getTagList("i", 10); backpackSizes.add(new JsonPrimitive(items.tagCount())); for (int j = 0; j < items.tagCount(); j++) { - final JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); contents.add(item); } - } catch (final IOException ignored) { + } catch (IOException ignored) { } } - final JsonObject bundledReturn = new JsonObject(); + JsonObject bundledReturn = new JsonObject(); bundledReturn.add("contents", contents); bundledReturn.add("backpack_sizes", backpackSizes); return bundledReturn; } - public String[] growArray(final String bytes, final int index, final String[] oldArray) { - final int newSize = Math.max(index + 1, oldArray.length); + public String[] growArray(String bytes, int index, String[] oldArray) { + int newSize = Math.max(index + 1, oldArray.length); - final String[] newArray = new String[newSize]; + String[] newArray = new String[newSize]; System.arraycopy(oldArray, 0, newArray, 0, oldArray.length); newArray[index] = bytes; return newArray; } - public JsonObject getPetsInfo(final String profileName) { - final JsonObject profileInfo = getProfileInformation(profileName); + public JsonObject getPetsInfo(String profileName) { + JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; if (petsInfoMap.containsKey(profileName)) return petsInfoMap.get(profileName); - final JsonObject petsInfo = new JsonObject(); - final JsonElement petsElement = profileInfo.get("pets"); + JsonObject petsInfo = new JsonObject(); + JsonElement petsElement = profileInfo.get("pets"); if (petsElement != null && petsElement.isJsonArray()) { JsonObject activePet = null; - final JsonArray pets = petsElement.getAsJsonArray(); + JsonArray pets = petsElement.getAsJsonArray(); for (int i = 0; i < pets.size(); i++) { - final JsonObject pet = pets.get(i).getAsJsonObject(); + JsonObject pet = pets.get(i).getAsJsonObject(); if (pet.has("active") && pet.get("active").getAsBoolean()) { activePet = pet; break; @@ -1569,46 +1561,46 @@ public class ProfileViewer { } public JsonObject getCollectionInfo(String profileName) { - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; - final JsonObject resourceCollectionInfo = getResourceCollectionInformation(); + JsonObject resourceCollectionInfo = getResourceCollectionInformation(); if (resourceCollectionInfo == null) return null; if (profileName == null) profileName = latestProfile; if (collectionInfoMap.containsKey(profileName)) return collectionInfoMap.get(profileName); - final List coopMembers = getCoopProfileInformation(profileName); - final JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); - final JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); - final JsonObject fakeMember = new JsonObject(); + List coopMembers = getCoopProfileInformation(profileName); + JsonElement unlocked_coll_tiers_element = Utils.getElement(profileInfo, "unlocked_coll_tiers"); + JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); + JsonObject fakeMember = new JsonObject(); fakeMember.add("crafted_generators", crafted_generators_element); coopMembers.add(coopMembers.size(), fakeMember); - final JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); + JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); if (unlocked_coll_tiers_element == null || collectionInfoElement == null) { return null; } - final JsonObject collectionInfo = new JsonObject(); - final JsonObject collectionTiers = new JsonObject(); - final JsonObject minionTiers = new JsonObject(); + JsonObject collectionInfo = new JsonObject(); + JsonObject collectionTiers = new JsonObject(); + JsonObject minionTiers = new JsonObject(); JsonObject personalAmounts = new JsonObject(); - final JsonObject totalAmounts = new JsonObject(); + JsonObject totalAmounts = new JsonObject(); if (collectionInfoElement.isJsonObject()) { personalAmounts = collectionInfoElement.getAsJsonObject(); } - for (final Map.Entry entry : personalAmounts.entrySet()) { + for (Map.Entry entry : personalAmounts.entrySet()) { totalAmounts.addProperty(entry.getKey(), entry.getValue().getAsLong()); } - final List coopProfiles = getCoopProfileInformation(profileName); + List coopProfiles = getCoopProfileInformation(profileName); if (coopProfiles != null) { - for (final JsonObject coopProfile : coopProfiles) { - final JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); + for (JsonObject coopProfile : coopProfiles) { + JsonElement coopCollectionInfoElement = Utils.getElement(coopProfile, "collection"); if (coopCollectionInfoElement != null && coopCollectionInfoElement.isJsonObject()) { - for (final Map.Entry entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { - final float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); + for (Map.Entry entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) { + float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0); totalAmounts.addProperty(entry.getKey(), existing + entry.getValue().getAsLong()); } } @@ -1616,36 +1608,34 @@ public class ProfileViewer { } if (unlocked_coll_tiers_element.isJsonArray()) { - final JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); + JsonArray unlocked_coll_tiers = unlocked_coll_tiers_element.getAsJsonArray(); for (int i = 0; i < unlocked_coll_tiers.size(); i++) { - final String unlocked = unlocked_coll_tiers.get(i).getAsString(); + String unlocked = unlocked_coll_tiers.get(i).getAsString(); - final Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); if (matcher.find()) { - final String tier_str = matcher.group(1); - final int tier = Integer.parseInt(tier_str); - final String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); + String tier_str = matcher.group(1); + int tier = Integer.parseInt(tier_str); + String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); if (!collectionTiers.has(coll) || collectionTiers.get(coll).getAsInt() < tier) { collectionTiers.addProperty(coll, tier); } } } } - for (final JsonObject current_member_info : coopMembers) { + for (JsonObject current_member_info : coopMembers) { if ( !current_member_info.has("crafted_generators") || !current_member_info.get("crafted_generators").isJsonArray() ) continue; - final JsonArray crafted_generators = Utils - .getElement(current_member_info, "crafted_generators") - .getAsJsonArray(); + JsonArray crafted_generators = Utils.getElement(current_member_info, "crafted_generators").getAsJsonArray(); for (int j = 0; j < crafted_generators.size(); j++) { - final String unlocked = crafted_generators.get(j).getAsString(); - final Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); + String unlocked = crafted_generators.get(j).getAsString(); + Matcher matcher = COLL_TIER_PATTERN.matcher(unlocked); if (matcher.find()) { - final String tierString = matcher.group(1); - final int tier = Integer.parseInt(tierString); - final String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); + String tierString = matcher.group(1); + int tier = Integer.parseInt(tierString); + String coll = unlocked.substring(0, unlocked.length() - (matcher.group().length())); if (!minionTiers.has(coll) || minionTiers.get(coll).getAsInt() < tier) { minionTiers.addProperty(coll, tier); } @@ -1653,24 +1643,24 @@ public class ProfileViewer { } } - final JsonObject maxAmount = new JsonObject(); - final JsonObject updatedCollectionTiers = new JsonObject(); - for (final Map.Entry totalAmountsEntry : totalAmounts.entrySet()) { - final String collName = totalAmountsEntry.getKey(); - final int collTier = (int) Utils.getElementAsFloat(collectionTiers.get(collName), 0); + JsonObject maxAmount = new JsonObject(); + JsonObject updatedCollectionTiers = new JsonObject(); + for (Map.Entry totalAmountsEntry : totalAmounts.entrySet()) { + String collName = totalAmountsEntry.getKey(); + int collTier = (int) Utils.getElementAsFloat(collectionTiers.get(collName), 0); - final int currentAmount = (int) Utils.getElementAsFloat(totalAmounts.get(collName), 0); + int currentAmount = (int) Utils.getElementAsFloat(totalAmounts.get(collName), 0); if (currentAmount > 0) { - for (final Map.Entry resourceEntry : resourceCollectionInfo.entrySet()) { - final JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers"); + for (Map.Entry resourceEntry : resourceCollectionInfo.entrySet()) { + JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers"); if (tiersElement != null && tiersElement.isJsonArray()) { - final JsonArray tiers = tiersElement.getAsJsonArray(); + JsonArray tiers = tiersElement.getAsJsonArray(); int maxTierAcquired = -1; int maxAmountRequired = -1; for (int i = 0; i < tiers.size(); i++) { - final JsonObject tierInfo = tiers.get(i).getAsJsonObject(); - final int tier = tierInfo.get("tier").getAsInt(); - final int amountRequired = tierInfo.get("amountRequired").getAsInt(); + JsonObject tierInfo = tiers.get(i).getAsJsonObject(); + int tier = tierInfo.get("tier").getAsInt(); + int amountRequired = tierInfo.get("amountRequired").getAsInt(); if (currentAmount >= amountRequired) { maxTierAcquired = tier; } @@ -1685,7 +1675,7 @@ public class ProfileViewer { } } - for (final Map.Entry collectionTiersEntry : updatedCollectionTiers.entrySet()) { + for (Map.Entry collectionTiersEntry : updatedCollectionTiers.entrySet()) { collectionTiers.add(collectionTiersEntry.getKey(), collectionTiersEntry.getValue()); } @@ -1700,42 +1690,39 @@ public class ProfileViewer { return collectionInfo; } - public PlayerStats.Stats getPassiveStats(final String profileName) { + public PlayerStats.Stats getPassiveStats(String profileName) { if (passiveStats.get(profileName) != null) return passiveStats.get(profileName); - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) return null; - final PlayerStats.Stats passivePlayerStats = PlayerStats.getPassiveBonuses( - getSkyblockInfo(profileName), - profileInfo - ); + PlayerStats.Stats passiveStats = PlayerStats.getPassiveBonuses(getSkyblockInfo(profileName), profileInfo); - if (passivePlayerStats != null) { - passivePlayerStats.add(PlayerStats.getBaseStats()); + if (passiveStats != null) { + passiveStats.add(PlayerStats.getBaseStats()); } - passiveStats.put(profileName, passivePlayerStats); + this.passiveStats.put(profileName, passiveStats); - return passivePlayerStats; + return passiveStats; } - public PlayerStats.Stats getStats(final String profileName) { + public PlayerStats.Stats getStats(String profileName) { if (stats.get(profileName) != null) return stats.get(profileName); - final JsonObject profileInfo = getProfileInformation(profileName); + JsonObject profileInfo = getProfileInformation(profileName); if (profileInfo == null) { return null; } - final PlayerStats.Stats playerStats = PlayerStats.getStats( + PlayerStats.Stats stats = PlayerStats.getStats( getSkyblockInfo(profileName), getInventoryInfo(profileName), getCollectionInfo(profileName), getPetsInfo(profileName), profileInfo ); - if (playerStats == null) return null; - stats.put(profileName, playerStats); - return playerStats; + if (stats == null) return null; + this.stats.put(profileName, stats); + return stats; } public String getUuid() { -- cgit