aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-01-01 10:41:51 -0800
committerGitHub <noreply@github.com>2023-01-01 19:41:51 +0100
commitadc3222fae3dc66c56ccede50c62ff741929be16 (patch)
tree8dff352e8b6cc925b8ecf54d834fa70eabab640e /src
parentf05b6fdfd1b699d84fb04018b707d1485052f718 (diff)
downloadNotEnoughUpdates-adc3222fae3dc66c56ccede50c62ff741929be16.tar.gz
NotEnoughUpdates-adc3222fae3dc66c56ccede50c62ff741929be16.tar.bz2
NotEnoughUpdates-adc3222fae3dc66c56ccede50c62ff741929be16.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java205
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java630
2 files changed, 430 insertions, 405 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java
index 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<ProfileViewerPage, GuiProfileViewerPage> 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<Integer> configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout;
+ final List<Integer> 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<String> grayTooltip = new ArrayList<>(tooltipToDisplay.size());
- for (String line : tooltipToDisplay) {
+ final List<String> 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<Integer> configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout;
+ final List<Integer> 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<Integer> configList = NotEnoughUpdates.INSTANCE.config.profileViewer.pageLayout;
+ final List<Integer> 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<String, String> petRarityToNumMap = new HashMap<String, String>() {
- {
- put("COMMON", "0");
- put("UNCOMMON", "1");
- put("RARE", "2");
- put("EPIC", "3");
- put("LEGENDARY", "4");
- put("MYTHIC", "5");
- }
- };
- private static final LinkedHashMap<String, ItemStack> skillToSkillDisplayMap =
- new LinkedHashMap<String, ItemStack>() {
- {
- 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<String, String> petRarityToNumMap =
+ ImmutableMap.<String, String>builder()
+ .put("COMMON", "0")
+ .put("UNCOMMON", "1")
+ .put("RARE", "2")
+ .put("EPIC", "3")
+ .put("LEGENDARY", "4")
+ .put("MYTHIC", "5")
+ .build();
+
+ private static final ImmutableMap<String, ItemStack> skillToSkillDisplayMap =
+ ImmutableMap.<String, ItemStack>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<String, Profile> uuidToProfileMap = new HashMap<>();
private final HashMap<String, String> 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<String, ItemStack> 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<JsonObject> callback) {
- String nameF = name.toLowerCase();
+ public void getHypixelProfile(final String name, final Consumer<JsonObject> 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<String> uuidCallback) {
- String nameF = name.toLowerCase();
+ public void getPlayerUUID(final String name, final Consumer<String> 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<Profile> callback) {
- String nameF = name.toLowerCase();
+ public void getProfileByName(final String name, final Consumer<Profile> 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<Profile> callback) {
- Profile profile = uuidToProfileMap.computeIfAbsent(uuid, k -> new Profile(uuid));
+ public Profile getProfile(final String uuid, final Consumer<Profile> 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<Profile> callback) {
+ public Profile getProfileReset(final String uuid, final Consumer<Profile> 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<String, String> args = new HashMap<>();
+ final HashMap<String, String> 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<String, Long> categoryWorth;
+ private final HashMap<String, Long> 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<String, JsonElement> entry : nwData.get("categories").getAsJsonObject().entrySet()) {
+ for (final Map.Entry<String, JsonElement> 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<String, ProfileViewer.Level> skyblockInfo = profile.getSkyblockInfo(otherProfileId);
+ final String otherProfileId = profileNames.get(yIndex);
+ final Map<String, ProfileViewer.Level> 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<String, Long> mostExpensiveInternal = new HashMap<>();
+ final HashMap<String, Long> mostExpensiveInternal = new HashMap<>();
- long networth = 0;
- for (Map.Entry<String, JsonElement> entry : inventoryInfo.entrySet()) {
+ long playerNetworth = 0;
+ for (final Map.Entry<String, JsonElement> 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<JsonObject> 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<JsonObject> coopList = new ArrayList<>();
- for (Map.Entry<String, JsonElement> 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<JsonObject> coopList = new ArrayList<>();
+ for (final Map.Entry<String, JsonElement> 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<String, Level> 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<JsonObject> coopProfileInfo = getCoopProfileInformation(profileName);
+ final List<JsonObject> 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<String, Level> out = new HashMap<>();
+ final Map<String, Level> out = new HashMap<>();
- List<String> skills = Arrays.asList(
+ final List<String> 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<String> dungeonClasses = Arrays.asList("healer", "tank", "mage", "archer", "berserk");
- for (String className : dungeonClasses) {
- float classExperience = Utils.getElementAsFloat(
+ final List<String> 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<String> slayers = Arrays.asList("zombie", "spider", "wolf", "enderman", "blaze");
- for (String slayerName : slayers) {
- float slayerExperience = Utils.getElementAsFloat(Utils.getElement(
+ final List<String> 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<String, JsonElement> backpackIcon : backpackIcons.entrySet()) {
+ for (final Map.Entry<String, JsonElement> 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<JsonObject> 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<JsonObject> 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<String, JsonElement> entry : personalAmounts.entrySet()) {
+ for (final Map.Entry<String, JsonElement> entry : personalAmounts.entrySet()) {
totalAmounts.addProperty(entry.getKey(), entry.getValue().getAsLong());
}
- List<JsonObject> coopProfiles = getCoopProfileInformation(profileName);
+ final List<JsonObject> 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<String, JsonElement> entry : coopCollectionInfoElement.getAsJsonObject().entrySet()) {
- float existing = Utils.getElementAsFloat(totalAmounts.get(entry.getKey()), 0);
+ for (final Map.Entry<String, JsonElement> 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<String, JsonElement> 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<String, JsonElement> 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<String, JsonElement> resourceEntry : resourceCollectionInfo.entrySet()) {
- JsonElement tiersElement = Utils.getElement(resourceEntry.getValue(), "items." + collName + ".tiers");
+ for (final Map.Entry<String, JsonElement> 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<String, JsonElement> collectionTiersEntry : updatedCollectionTiers.entrySet()) {
+ for (final Map.Entry<String, JsonElement> 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() {