diff options
Diffstat (limited to 'src')
15 files changed, 268 insertions, 154 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java index 86430804..1e70db7f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/util/ArrowPagesUtils.java @@ -173,7 +173,7 @@ public class ArrowPagesUtils { BUTTON_WIDTH, BUTTON_HEIGHT ) && - currentPage < totalPages) { + currentPage < totalPages - 1) { int newPage = currentPage + 1; pageChange.accept(MathHelper.clamp_int(newPage, 0, totalPages - 1)); Utils.playPressSound(); 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 5651a6ed..2253ca4a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCooldowns.java @@ -182,8 +182,7 @@ public class ItemCooldowns { @SubscribeEvent public void onChatMessage(ClientChatReceivedEvent event) { - if (PICKAXE_ABILITY_ACTIVATION.matcher(event.message.getFormattedText()).matches() && - NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility && pickaxeCooldown != 0) { + if (PICKAXE_ABILITY_ACTIVATION.matcher(event.message.getFormattedText()).matches() && pickaxeCooldown != 0) { findCooldownInTooltip(Item.PICKAXES); pickaxeUseCooldownMillisRemaining = pickaxeCooldown * 1000; } @@ -260,10 +259,12 @@ public class ItemCooldowns { } // Pickaxes - if (isPickaxe(internalname) && NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility) { + if (isPickaxe(internalname)) { findCooldownInTooltip(Item.PICKAXES); - return durabilityOverride(pickaxeUseCooldownMillisRemaining, pickaxeCooldown, stack); + if (NotEnoughUpdates.INSTANCE.config.itemOverlays.pickaxeAbility) { + return durabilityOverride(pickaxeUseCooldownMillisRemaining, pickaxeCooldown, stack); + } else return -1; } // Treecapitator / Jungle Axe if (internalname.equals("TREECAPITATOR_AXE") || internalname.equals("JUNGLE_AXE")) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java index 31dd71eb..907f0f0d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PowerStoneStatsDisplay.java @@ -19,10 +19,13 @@ package io.github.moulberry.notenoughupdates.miscfeatures; +import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.util.StringUtils; +import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent; import io.github.moulberry.notenoughupdates.options.NEUConfig; +import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewerUtils; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -54,13 +57,25 @@ public class PowerStoneStatsDisplay { } @SubscribeEvent + public void onProfileDataLoaded(ProfileDataLoadedEvent event) { + JsonObject profileInfo = event.getProfileInfo(); + + if (profileInfo == null) return; + + JsonObject inventoryInfo = ProfileViewerUtils.readInventoryInfo(profileInfo, "talisman_bag"); + if (inventoryInfo == null) return; + + NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); + if (configProfileSpecific == null) return; + int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); + configProfileSpecific.magicalPower = powerAmount; + } + + @SubscribeEvent public void onTick(TickEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.powerStoneStats) return; if (!dirty) return; - - if (!Utils.getOpenChestName().equals("SkyBlock Menu")) { - dirty = false; - return; - } + if (!Utils.getOpenChestName().equals("Your Bags")) return; EntityPlayerSP p = Minecraft.getMinecraft().thePlayer; Container openContainer = p.openContainer; @@ -70,14 +85,15 @@ public class PowerStoneStatsDisplay { String displayName = stack.getDisplayName(); if (!"§aAccessory Bag".equals(displayName)) continue; + dirty = false; for (String line : ItemUtils.getLore(stack)) { if (line.startsWith("§7Magical Power: ")) { String rawNumber = line.split("§6")[1].replace(",", ""); NEUConfig.HiddenProfileSpecific configProfileSpecific = NotEnoughUpdates.INSTANCE.config.getProfileSpecific(); if (configProfileSpecific == null) return; - configProfileSpecific.magicalPower = Integer.parseInt(rawNumber); - dirty = false; + int magicalPower = Integer.parseInt(rawNumber); + configProfileSpecific.magicalPower = magicalPower; } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 371d657e..a289ca51 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -438,6 +438,8 @@ public class NEUConfig extends Config { @Expose public int compareMode = 0; @Expose + public String customUserAgent = null; + @Expose public int sortMode = 0; @Expose public ArrayList<Boolean> compareAscending = Lists.newArrayList(true, true, true); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java index 8a48dd2c..265177fc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/BasicPage.java @@ -572,7 +572,7 @@ public class BasicPage extends GuiProfileViewerPage { ); } - // sb lvlL + // sb lvl int sbLevelX = guiLeft + 162; int sbLevelY = guiTop + 90; @@ -585,8 +585,8 @@ public class BasicPage extends GuiProfileViewerPage { GlStateManager.scale(1.5f, 1.5f, 1); Utils.drawItemStack(skull, 0, 0); GlStateManager.popMatrix(); - Utils.drawStringScaled(skyblockLevelColour.toString() + (int) skyblockLevel, fr, - sbLevelX - 2, sbLevelY - 15, true, 0, 1.5f + Utils.drawStringCenteredScaled(skyblockLevelColour.toString() + (int) skyblockLevel, fr, + sbLevelX + 9, sbLevelY - 12, true, 1.5f ); float progress = (float) (skyblockLevel - (long) skyblockLevel); @@ -596,6 +596,12 @@ public class BasicPage extends GuiProfileViewerPage { sbLevelX - 30, sbLevelY + 20, true, 0, 0.9f ); + if (mouseX >= guiLeft + 128 && mouseX <= guiLeft + 216) { + if (mouseY >= guiTop + 69 && mouseY <= guiTop + 131) { + if (Mouse.isButtonDown(0)) onSecondPage = true; + } + } + if (skyblockInfo != null) { int position = 0; for (Map.Entry<String, ItemStack> entry : ProfileViewer.getSkillToSkillDisplayMap().entrySet()) { @@ -623,12 +629,6 @@ public class BasicPage extends GuiProfileViewerPage { getInstance().renderBar(x, y + 6, 80, level.level % 1); } - if (mouseX >= guiLeft + 128 && mouseX <= guiLeft + 216) { - if (mouseY >= guiTop + 69 && mouseY <= guiTop + 131) { - if (Mouse.isButtonDown(0)) onSecondPage = true; - } - } - if (mouseX > x && mouseX < x + 80) { if (mouseY > y - 4 && mouseY < y + 13) { getInstance().tooltipToDisplay = new ArrayList<>(); 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 610e4090..17a14d1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -28,7 +28,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.profileviewer.bestiary.BestiaryData; import io.github.moulberry.notenoughupdates.profileviewer.weight.senither.SenitherWeight; import io.github.moulberry.notenoughupdates.util.Constants; -import io.github.moulberry.notenoughupdates.util.JsonUtils; import io.github.moulberry.notenoughupdates.util.Utils; import io.github.moulberry.notenoughupdates.util.hypixelapi.ProfileCollectionInfo; import net.minecraft.init.Blocks; @@ -36,7 +35,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; @@ -44,25 +42,20 @@ import net.minecraft.util.EnumChatFormatting; import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.regex.Pattern; -import java.util.stream.Collectors; public class ProfileViewer { @@ -703,98 +696,7 @@ public class ProfileViewer { return -1; } - Map<String, Integer> accessories = JsonUtils.getJsonArrayAsStream(inventoryInfo - .get("talisman_bag") - .getAsJsonArray()).map(o -> { - try { - return JsonToNBT.getTagFromJson(o - .getAsJsonObject() - .get("nbttag") - .getAsString()); - } catch (Exception ignored) { - return null; - } - }).filter(Objects::nonNull).map(tag -> { - NBTTagList loreTagList = tag.getCompoundTag("display").getTagList("Lore", 8); - String lastElement = loreTagList.getStringTagAt(loreTagList.tagCount() - 1); - if (lastElement.contains(EnumChatFormatting.OBFUSCATED.toString())) { - lastElement = lastElement.substring(lastElement.indexOf(' ')).trim().substring(4); - } - JsonArray lastElementJsonArray = new JsonArray(); - lastElementJsonArray.add(new JsonPrimitive(lastElement)); - return new AbstractMap.SimpleEntry<>( - tag.getCompoundTag("ExtraAttributes").getString("id"), - Utils.getRarityFromLore(lastElementJsonArray) - ); - }).sorted(Comparator.comparingInt(e -> -e.getValue())).collect(Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, - (v1, v2) -> v1, - LinkedHashMap::new - )); - - Set<String> ignoredTalismans = new HashSet<>(); - int powerAmount = 0; - for (Map.Entry<String, Integer> entry : accessories.entrySet()) { - if (ignoredTalismans.contains(entry.getKey())) { - continue; - } - - JsonArray children = Utils - .getElementOrDefault(Constants.PARENTS, entry.getKey(), new JsonArray()) - .getAsJsonArray(); - for (JsonElement child : children) { - ignoredTalismans.add(child.getAsString()); - } - - if (entry.getKey().equals("HEGEMONY_ARTIFACT")) { - switch (entry.getValue()) { - case 4: - powerAmount += 16; - break; - case 5: - powerAmount += 22; - break; - } - } - if (entry.getKey().equals("ABICASE")) { - if (profileInfo != null && profileInfo.has("nether_island_player_data") && - profileInfo.get("nether_island_player_data").getAsJsonObject().has("abiphone") && profileInfo - .get( - "nether_island_player_data") - .getAsJsonObject() - .get("abiphone") - .getAsJsonObject() - .has("active_contacts")) { // BatChest - int contact = - profileInfo.get("nether_island_player_data").getAsJsonObject().get("abiphone").getAsJsonObject().get( - "active_contacts").getAsJsonArray().size(); - powerAmount += Math.floor(contact / 2); - } - } - switch (entry.getValue()) { - case 0: - case 6: - powerAmount += 3; - break; - case 1: - case 7: - powerAmount += 5; - break; - case 2: - powerAmount += 8; - break; - case 3: - powerAmount += 12; - break; - case 4: - powerAmount += 16; - break; - case 5: - powerAmount += 22; - break; - } - } + int powerAmount = ProfileViewerUtils.getMagicalPower(inventoryInfo, profileInfo); magicalPower.put(profileId, powerAmount); return powerAmount; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java new file mode 100644 index 00000000..66164688 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerUtils.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2023 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.profileviewer; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import io.github.moulberry.notenoughupdates.NEUManager; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.JsonUtils; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.EnumChatFormatting; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.AbstractMap; +import java.util.Base64; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; + +public class ProfileViewerUtils { + + public static JsonObject readInventoryInfo(JsonObject profileInfo, String bagName) { + JsonObject inventoryInfo = new JsonObject(); + JsonElement element = Utils.getElement(profileInfo, bagName + ".data"); + + String bytes = Utils.getElementAsString(element, "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); + NBTTagCompound inv_contents_nbt; + try { + inv_contents_nbt = CompressedStreamTools.readCompressed( + new ByteArrayInputStream(Base64.getDecoder().decode(bytes)) + ); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + NBTTagList items = inv_contents_nbt.getTagList("i", 10); + JsonArray contents = new JsonArray(); + NEUManager manager = NotEnoughUpdates.INSTANCE.manager; + for (int j = 0; j < items.tagCount(); j++) { + JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + contents.add(item); + } + + inventoryInfo.add(bagName, contents); + return inventoryInfo; + } + + public static int getMagicalPower(JsonObject inventoryInfo, JsonObject profileInfo) { + JsonArray talismanBag = inventoryInfo.get("talisman_bag").getAsJsonArray(); + Map<String, Integer> accessories = JsonUtils.getJsonArrayAsStream(talismanBag).map(o -> { + try { + return JsonToNBT.getTagFromJson(o.getAsJsonObject().get("nbttag").getAsString()); + } catch (Exception ignored) { + return null; + } + }).filter(Objects::nonNull).map(tag -> { + NBTTagList loreTagList = tag.getCompoundTag("display").getTagList("Lore", 8); + String lastElement = loreTagList.getStringTagAt(loreTagList.tagCount() - 1); + if (lastElement.contains(EnumChatFormatting.OBFUSCATED.toString())) { + lastElement = lastElement.substring(lastElement.indexOf(' ')).trim().substring(4); + } + JsonArray lastElementJsonArray = new JsonArray(); + lastElementJsonArray.add(new JsonPrimitive(lastElement)); + return new AbstractMap.SimpleEntry<>(tag.getCompoundTag("ExtraAttributes").getString("id"), + Utils.getRarityFromLore(lastElementJsonArray) + ); + }).sorted(Comparator.comparingInt(e -> -e.getValue())).collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, LinkedHashMap::new + )); + + Set<String> ignoredTalismans = new HashSet<>(); + int powerAmount = 0; + for (Map.Entry<String, Integer> entry : accessories.entrySet()) { + if (ignoredTalismans.contains(entry.getKey())) continue; + + JsonArray children = Utils + .getElementOrDefault(Constants.PARENTS, entry.getKey(), new JsonArray()) + .getAsJsonArray(); + for (JsonElement child : children) { + ignoredTalismans.add(child.getAsString()); + } + + if (entry.getKey().equals("HEGEMONY_ARTIFACT")) { + switch (entry.getValue()) { + case 4: + powerAmount += 16; + break; + case 5: + powerAmount += 22; + break; + } + } + if (entry.getKey().equals("ABICASE")) { + if (profileInfo != null && profileInfo.has("nether_island_player_data")) { + JsonObject data = profileInfo.get("nether_island_player_data").getAsJsonObject(); + if (data.has("abiphone") && data.get("abiphone").getAsJsonObject().has("active_contacts")) { // BatChest + int contact = data.get("abiphone").getAsJsonObject().get("active_contacts").getAsJsonArray().size(); + powerAmount += Math.floor(contact / 2); + } + } + } + switch (entry.getValue()) { + case 0: + case 6: + powerAmount += 3; + break; + case 1: + case 7: + powerAmount += 5; + break; + case 2: + powerAmount += 8; + break; + case 3: + powerAmount += 12; + break; + case 4: + powerAmount += 16; + break; + case 5: + powerAmount += 22; + break; + } + } + return powerAmount; + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/DungeonTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/DungeonTaskLevel.java index 157c8362..6f0a029f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/DungeonTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/DungeonTaskLevel.java @@ -106,7 +106,7 @@ public class DungeonTaskLevel { lore.add(levelPage.buildLore("Complete Dungeons", sbLevelGainedFloor, completeDungeon, false)); levelPage.renderLevelBar( - "Dungeon", + "Dungeon Task", NotEnoughUpdates.INSTANCE.manager .createItemResolutionQuery() .withKnownInternalName("WITHER_RELIC") diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EssenceTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EssenceTaskLevel.java index d64f54c1..11e291b0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EssenceTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/EssenceTaskLevel.java @@ -94,7 +94,9 @@ public class EssenceTaskLevel { .resolveToItemListJson() .get("displayname") .getAsString(); - value.max = essenceShopTask.get(key.toLowerCase() + "_shop").getAsInt(); + String name = key.toLowerCase() + "_shop"; + if (!essenceShopTask.has(name)) continue; + value.max = essenceShopTask.get(name).getAsInt(); lore.add(levelPage.buildLore( EnumChatFormatting.getTextWithoutFormattingCodes(value.name), value.current, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java index a717664d..e0ea89b3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/level/task/MiscTaskLevel.java @@ -116,17 +116,18 @@ public class MiscTaskLevel { JsonObject communityShopUpgradesMax = miscellaneousTask.getAsJsonObject("community_shop_upgrades_max"); int communityShopUpgradesXp = miscellaneousTask.get("community_shop_upgrades_xp").getAsInt(); - - for ( - JsonElement upgradeState : upgradeStates) { - if (!upgradeState.isJsonObject()) continue; - JsonObject value = upgradeState.getAsJsonObject(); - String upgrade = value.get("upgrade").getAsString(); - int tier = value.get("tier").getAsInt(); - if (communityShopUpgradesMax.has(upgrade)) { - int max = communityShopUpgradesMax.get(upgrade).getAsInt(); - if (max >= tier) { - sbXpCommunityUpgrade += communityShopUpgradesXp; + if (upgradeStates != null) { + for ( + JsonElement upgradeState : upgradeStates) { + if (!upgradeState.isJsonObject()) continue; + JsonObject value = upgradeState.getAsJsonObject(); + String upgrade = value.get("upgrade").getAsString(); + int tier = value.get("tier").getAsInt(); + if (communityShopUpgradesMax.has(upgrade)) { + int max = communityShopUpgradesMax.get(upgrade).getAsInt(); + if (max >= tier) { + sbXpCommunityUpgrade += communityShopUpgradesXp; + } } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java index c86ac84f..023be060 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ApiUtil.java @@ -61,7 +61,12 @@ import java.util.zip.GZIPInputStream; public class ApiUtil { private static final Gson gson = new Gson(); private static final ExecutorService executorService = Executors.newFixedThreadPool(3); - private static final String USER_AGENT = "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; + private static String getUserAgent() { + if (NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent != null) { + return NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent; + } + return "NotEnoughUpdates/" + NotEnoughUpdates.VERSION; + } private static SSLContext ctx; private final Map<String, CompletableFuture<Void>> updateTasks = new HashMap<>(); @@ -89,11 +94,12 @@ public class ApiUtil { public void updateProfileData(String playerUuid) { if (!updateTasks.getOrDefault(playerUuid, CompletableFuture.completedFuture(null)).isDone()) return; + String uuid = Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", ""); updateTasks.put(playerUuid, newHypixelApiRequest("skyblock/profiles") - .queryArgument("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")) + .queryArgument("uuid", uuid) .requestJson() .handle((jsonObject, throwable) -> { - new ProfileDataLoadedEvent(jsonObject).post(); + new ProfileDataLoadedEvent(uuid, jsonObject).post(); return null; })); @@ -169,7 +175,7 @@ public class ApiUtil { } conn.setConnectTimeout(10000); conn.setReadTimeout(10000); - conn.setRequestProperty("User-Agent", USER_AGENT); + conn.setRequestProperty("User-Agent", getUserAgent()); if (this.postContentType != null) { conn.setRequestProperty("Content-Type", this.postContentType); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 952eb50f..d5abcb77 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -186,7 +186,7 @@ public class Utils { } int newScale = guiScales.size() > 0 - ? Math.max(0, Math.min(4, guiScales.peek())) + ? Math.max(0, guiScales.peek()) : Minecraft.getMinecraft().gameSettings.guiScale; if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; @@ -1229,6 +1229,22 @@ public class Utils { drawStringScaled(str, fr, x - len / 2, y - fontHeight / 2, shadow, colour, factor); } + public static void drawStringCenteredScaled( + String str, + FontRenderer fr, + float x, + float y, + boolean shadow, + float factor + ) { + int strLen = fr.getStringWidth(str); + + float x2 = x - strLen / 2f; + float y2 = y - fr.FONT_HEIGHT / 2f; + + drawStringScaled(str, fr, x2, y2, shadow, 0, factor); + } + public static void drawStringCenteredYScaled( String str, FontRenderer fr, diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt index 7647ca2c..805ff114 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -212,6 +212,16 @@ class DevTestCommand { MiscUtils.copyToClipboard(tabList) reply("Copied tablist to clipboard!") }.withHelp("Copy the tab list") + thenLiteralExecute("useragent") { + thenArgumentExecute("newuseragent", RestArgumentType) { userAgent -> + reply("Setting your user agent to ${this[userAgent]}") + NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = this[userAgent] + }.withHelp("Set a custom user agent for all HTTP requests") + thenExecute { + reply("Resetting your user agent.") + NotEnoughUpdates.INSTANCE.config.hidden.customUserAgent = null + } + }.withHelp("Reset the custom user agent") } hook.beforeCommand = Predicate { if (!canPlayerExecute(it.context.source)) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.kt index 956acfe0..00a535c6 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.java +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/events/ProfileDataLoadedEvent.kt @@ -16,25 +16,27 @@ * You should have received a copy of the GNU Lesser General Public License * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. */ +package io.github.moulberry.notenoughupdates.events -package io.github.moulberry.notenoughupdates.events; - -import com.google.gson.JsonObject; - -import javax.annotation.Nullable; +import com.google.gson.JsonObject //TODO extend the usage of this event (accessory bag and storage data) -public class ProfileDataLoadedEvent extends NEUEvent { - - @Nullable - private final JsonObject data; +class ProfileDataLoadedEvent(val uuid: String, val data: JsonObject?) : NEUEvent() { + val profileInfo: JsonObject? by lazy { readProfileInfo() } - public ProfileDataLoadedEvent(@Nullable JsonObject entireApiResponse) { - this.data = entireApiResponse; - } + private fun readProfileInfo(): JsonObject? { + if (data == null) return null - @Nullable - public JsonObject getData() { - return data; - } + val skyblockProfiles = data["profiles"].asJsonArray + for (profileEle in skyblockProfiles) { + val profile = profileEle.asJsonObject + if (!profile.has("members")) continue + val members = profile["members"].asJsonObject + if (!members.has(uuid)) continue + if (profile.has("selected") && profile["selected"].asBoolean) { + return members[uuid].asJsonObject + } + } + return null + } } diff --git a/src/main/resources/assets/notenoughupdates/pv_levels.png b/src/main/resources/assets/notenoughupdates/pv_levels.png Binary files differindex 21810476..0b6bb093 100644 --- a/src/main/resources/assets/notenoughupdates/pv_levels.png +++ b/src/main/resources/assets/notenoughupdates/pv_levels.png |