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') 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') 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') 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') 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 auctionPr