diff options
Diffstat (limited to 'src/main/java')
8 files changed, 539 insertions, 148 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java index 680094af..f78c7e96 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java @@ -1359,6 +1359,103 @@ public class NEUManager { return itemMap; } + public String removeUnusedDecimal(double num) { + if(num % 1 == 0) { + return String.valueOf((int)num); + } else { + return String.valueOf(num); + } + } + + public HashMap<String, String> getLoreReplacements(String petname, String tier, int level) { + JsonObject petnums = null; + if(petname != null && tier != null) { + petnums = Utils.getConstant("petnums"); + } + + HashMap<String, String> replacements = new HashMap<>(); + if(level < 1) { + replacements.put("LVL", "1\u27A1100"); + } else { + replacements.put("LVL", ""+level); + } + if(petnums != null) { + if(petnums.has(petname)) { + JsonObject petInfo = petnums.get(petname).getAsJsonObject(); + if(petInfo.has(tier)) { + JsonObject petInfoTier = petInfo.get(tier).getAsJsonObject(); + JsonObject min = petInfoTier.get("1").getAsJsonObject(); + JsonObject max = petInfoTier.get("100").getAsJsonObject(); + + if(level < 1) { + JsonArray otherNumsMin = min.get("otherNums").getAsJsonArray(); + JsonArray otherNumsMax = max.get("otherNums").getAsJsonArray(); + for(int i=0; i<otherNumsMax.size(); i++) { + replacements.put(""+i, removeUnusedDecimal(Math.floor(otherNumsMin.get(i).getAsFloat()*10)/10f)+ + "\u27A1"+removeUnusedDecimal(Math.floor(otherNumsMax.get(i).getAsFloat()*10)/10f)); + } + + for(Map.Entry<String, JsonElement> entry : max.get("statNums").getAsJsonObject().entrySet()) { + int statMax = (int)Math.floor(entry.getValue().getAsFloat()); + int statMin = (int)Math.floor(min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat()); + String statStr = "+"+statMin+"\u27A1"+statMax; + replacements.put(entry.getKey(), statStr); + } + } else { + + } + } + } + } + + return replacements; + } + + public HashMap<String, String> getLoreReplacements(NBTTagCompound tag, int level) { + String petname = null; + String tier = null; + if(tag != null && tag.hasKey("ExtraAttributes")) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + if(ea.hasKey("petInfo")) { + String petInfoStr = ea.getString("petInfo"); + JsonObject petInfo = gson.fromJson(petInfoStr, JsonObject.class); + petname = petInfo.get("type").getAsString(); + tier = petInfo.get("tier").getAsString(); + if(petInfo.has("heldItem")) { + String heldItem = petInfo.get("heldItem").getAsString(); + if(heldItem.equals("PET_ITEM_TIER_BOOST")) { + switch(tier) { + case "COMMON": + tier = "UNCOMMON"; break; + case "UNCOMMON": + tier = "RARE"; break; + case "RARE": + tier = "EPIC"; break; + case "EPIC": + tier = "LEGENDARY"; break; + } + } + } + } + } + return getLoreReplacements(petname, tier, level); + } + + public NBTTagList processLore(JsonArray lore, HashMap<String, String> replacements) { + NBTTagList nbtLore = new NBTTagList(); + for(JsonElement line : lore) { + String lineStr = line.getAsString(); + if(!lineStr.contains("Click to view recipes!") && + !lineStr.contains("Click to view recipe!")) { + for(Map.Entry<String, String> entry : replacements.entrySet()) { + lineStr = lineStr.replace("{"+entry.getKey()+"}", entry.getValue()); + } + nbtLore.appendTag(new NBTTagString(lineStr)); + } + } + return nbtLore; + } + public ItemStack jsonToStack(JsonObject json) { return jsonToStack(json, true); } @@ -1387,24 +1484,23 @@ public class NEUManager { NBTTagCompound tag = JsonToNBT.getTagFromJson(json.get("nbttag").getAsString()); stack.setTagCompound(tag); } catch(NBTException e) { - if(json.get("internalname").getAsString().equalsIgnoreCase("ROCK;0")) e.printStackTrace(); } } + HashMap<String, String> replacements = getLoreReplacements(stack.getTagCompound(), -1); + + String displayname = json.get("displayname").getAsString(); + for(Map.Entry<String, String> entry : replacements.entrySet()) { + displayname = displayname.replace("{"+entry.getKey()+"}", entry.getValue()); + } + stack.setStackDisplayName(displayname); + if(json.has("lore")) { NBTTagCompound display = new NBTTagCompound(); if(stack.getTagCompound() != null && stack.getTagCompound().hasKey("display")) { display = stack.getTagCompound().getCompoundTag("display"); } - NBTTagList lore = new NBTTagList(); - for(JsonElement line : json.get("lore").getAsJsonArray()) { - String lineStr = line.getAsString(); - if(!lineStr.contains("Click to view recipes!") && - !lineStr.contains("Click to view recipe!")) { - lore.appendTag(new NBTTagString(lineStr)); - } - } - display.setTag("Lore", lore); + display.setTag("Lore", processLore(json.get("lore").getAsJsonArray(), replacements)); NBTTagCompound tag = stack.getTagCompound() != null ? stack.getTagCompound() : new NBTTagCompound(); tag.setTag("display", display); stack.setTagCompound(tag); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 7db8875d..a234ca8a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1803,12 +1803,7 @@ public class NEUOverlay extends Gui { //Render tooltip JsonObject json = tooltipToDisplay.get(); if(json != null) { - List<String> text = new ArrayList<>(); - text.add(json.get("displayname").getAsString()); - JsonArray lore = json.get("lore").getAsJsonArray(); - for(int i=0; i<lore.size(); i++) { - text.add(lore.get(i).getAsString()); - } + List<String> text = manager.jsonToStack(json).getTooltip(Minecraft.getMinecraft().thePlayer, false); String internalname = json.get("internalname").getAsString(); JsonObject auctionInfo = manager.getItemAuctionInfo(internalname); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index efd38c55..169b6b9f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -19,6 +19,7 @@ import io.github.moulberry.notenoughupdates.questing.SBScoreboardData; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.*; @@ -38,10 +39,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.Matrix4f; -import net.minecraft.util.Session; +import net.minecraft.util.*; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.*; import net.minecraftforge.common.MinecraftForge; @@ -140,7 +138,7 @@ public class NotEnoughUpdates { } }); - private static ProfileViewer profileViewer; + public static ProfileViewer profileViewer; SimpleCommand viewProfileCommand = new SimpleCommand("neuprofile", new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { @@ -148,16 +146,34 @@ public class NotEnoughUpdates { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "This feature requires FBOs to work. Try disabling Optifine's 'Fast Render'.")); } else*/ - if(args.length != 1) { + if (manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + - "idiot.")); + "Can't view profile, apikey is not set. Run /api new and put the result in settings.")); + } else if (args.length == 0) { + profileViewer.getProfileByName(Minecraft.getMinecraft().thePlayer.getName(), profile -> { + if (profile != null) profile.resetCache(); + openGui = new GuiProfileViewer(profile); + }); + } else if (args.length > 1) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + + "Too many arguments. Usage: /neuprofile [name]")); } else { profileViewer.getProfileByName(args[0], profile -> { - profile.resetCache(); + if (profile != null) profile.resetCache(); openGui = new GuiProfileViewer(profile); }); } - //openGui = new GuiProfileViewer(null); + } + }, new SimpleCommand.TabCompleteRunnable() { + @Override + public List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos) { + /*if(args.length) { + + }*/ + for(String arg : args) { + System.out.println(arg); + } + return null; } }); @@ -200,7 +216,7 @@ public class NotEnoughUpdates { "You must be on Skyblock to use this feature.")); } else if(manager.config.apiKey.value == null || manager.config.apiKey.value.trim().isEmpty()) { Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(EnumChatFormatting.RED+ - "Can't open NeuAH, Api Key is not set. Run /api new and put the result in settings.")); + "Can't open NeuAH, apikey is not set. Run /api new and put the result in settings.")); } else { openGui = new CustomAHGui(); manager.auctionManager.customAH.lastOpen = System.currentTimeMillis(); @@ -228,7 +244,6 @@ public class NotEnoughUpdates { ClientCommandHandler.instance.registerCommand(viewProfileCommand); ClientCommandHandler.instance.registerCommand(overlayPlacementsCommand); ClientCommandHandler.instance.registerCommand(enchantColourCommand); - //ClientCommandHandler.instance.registerCommand(questingCommand); ClientCommandHandler.instance.registerCommand(neuAhCommand); neuio = new NEUIO(getAccessToken()); @@ -712,7 +727,7 @@ public class NotEnoughUpdates { */ @SubscribeEvent public void onGuiBackgroundDraw(GuiScreenEvent.BackgroundDrawnEvent event) { - if((event.gui instanceof GuiContainer || event.gui instanceof CustomAHGui || event.gui instanceof GuiItemRecipe) && isOnSkyblock()) { + if((shouldRenderOverlay(event.gui) || event.gui instanceof CustomAHGui) && isOnSkyblock()) { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledresolution.getScaledWidth(); @@ -771,6 +786,19 @@ public class NotEnoughUpdates { } } + private static boolean shouldRenderOverlay(Gui gui) { + boolean validGui = gui instanceof GuiContainer || gui instanceof GuiItemRecipe; + if(gui instanceof GuiChest) { + GuiChest eventGui = (GuiChest) gui; + ContainerChest cc = (ContainerChest) eventGui.inventorySlots; + String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText(); + if(containerName.trim().equals("Fast Travel")) { + validGui = false; + } + } + return validGui; + } + /** * Will draw the NEUOverlay over the inventory if focusInv == false. (z-translation of 300 is so that NEUOverlay * will draw over Items in the inventory (which render at a z value of about 250)) @@ -779,7 +807,7 @@ public class NotEnoughUpdates { @SubscribeEvent public void onGuiScreenDrawPost(GuiScreenEvent.DrawScreenEvent.Post event) { if(!(event.gui instanceof CustomAHGui || manager.auctionManager.customAH.isRenderOverAuctionView())) { - if((event.gui instanceof GuiContainer || event.gui instanceof GuiItemRecipe) && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && isOnSkyblock()) { renderDungeonChestOverlay(event.gui); @@ -889,7 +917,7 @@ public class NotEnoughUpdates { overlay.mouseInput(); return; } - if(event.gui instanceof GuiContainer && !(hoverInv && focusInv) && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && !(hoverInv && focusInv) && isOnSkyblock()) { if(overlay.mouseInput()) { event.setCanceled(true); } @@ -914,7 +942,7 @@ public class NotEnoughUpdates { return; } - if(event.gui instanceof GuiContainer && isOnSkyblock()) { + if(shouldRenderOverlay(event.gui) && isOnSkyblock()) { if(overlay.keyboardInput(focusInv)) { event.setCanceled(true); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index 4d30cf3e..72baf3a7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -365,6 +365,9 @@ public class APIManager { return -1; } + private String[] romans = new String[]{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI", + "XII","XIII","XIV","XV","XVI","XVII","XIX","XX"}; + private void getPageFromAPI(int page) { //System.out.println("Trying to update page: " + page); HashMap<String, String> args = new HashMap<>(); @@ -411,7 +414,7 @@ public class APIManager { bin = auction.get("bin").getAsBoolean(); } String sbCategory = auction.get("category").getAsString(); - String extras = auction.get("extra").getAsString(); + String extras = auction.get("extra").getAsString().toLowerCase(); String item_name = auction.get("item_name").getAsString(); String item_lore = Utils.fixBrokenAPIColour(auction.get("item_lore").getAsString()); String item_bytes = auction.get("item_bytes").getAsString(); @@ -437,6 +440,8 @@ public class APIManager { String displayNormal = ""; if(manager.getItemInformation().containsKey(internalname)) { displayNormal = Utils.cleanColour(manager.getItemInformation().get(internalname).get("displayname").getAsString()); + } else { + } String[] lore = new String[0]; @@ -451,6 +456,25 @@ public class APIManager { tag.setTag("display", display); item_tag.getTagList("i", 10).getCompoundTagAt(0).setTag("tag", tag); + if(tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + + if(ea.hasKey("enchantments", 10)) { + NBTTagCompound enchantments = ea.getCompoundTag("enchantments"); + for(String key : enchantments.getKeySet()) { + String enchantname = key.toLowerCase().replace("_", " "); + int enchantlevel = enchantments.getInteger(key); + String enchantLevelStr; + if(enchantlevel >= 1 && enchantlevel <= 20) { + enchantLevelStr = romans[enchantlevel-1]; + } else { + enchantLevelStr = String.valueOf(enchantlevel); + } + extras = extras.replace(enchantname, enchantname + " " + enchantLevelStr); + } + } + } + int index=0; for(String str : extras.split(" ")) { str = Utils.cleanColour(str).toLowerCase(); @@ -491,7 +515,7 @@ public class APIManager { if(itemType >= 0 && itemType < categoryItemType.length) { category = categoryItemType[itemType]; } - if(extras.startsWith("Enchanted Book")) category = "ebook"; + if(internalname.equals("ENCHANTED_BOOK")) category = "ebook"; if(extras.endsWith("Potion")) category = "potion"; if(extras.contains("Rune")) category = "rune"; if(item_lore.split("\n")[0].endsWith("Furniture")) category = "furniture"; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java index ae27be46..029e24db 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/SimpleCommand.java @@ -3,21 +3,36 @@ package io.github.moulberry.notenoughupdates.commands; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; + +import java.util.ArrayList; +import java.util.List; public class SimpleCommand extends CommandBase { private String commandName; private ProcessCommandRunnable runnable; + private TabCompleteRunnable tabRunnable; public SimpleCommand(String commandName, ProcessCommandRunnable runnable) { this.commandName = commandName; this.runnable = runnable; } + public SimpleCommand(String commandName, ProcessCommandRunnable runnable, TabCompleteRunnable tabRunnable) { + this.commandName = commandName; + this.runnable = runnable; + this.tabRunnable = tabRunnable; + } + public abstract static class ProcessCommandRunnable { public abstract void processCommand(ICommandSender sender, String[] args); } + public abstract static class TabCompleteRunnable { + public abstract List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos); + } + public boolean canCommandSenderUseCommand(ICommandSender sender) { return true; } @@ -33,4 +48,9 @@ public class SimpleCommand extends CommandBase { public void processCommand(ICommandSender sender, String[] args) throws CommandException { runnable.processCommand(sender, args); } + + public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { + if(tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); + return null; + } } 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 2b3eb2d1..6aa2a1ab 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -66,6 +66,7 @@ public class GuiProfileViewer extends GuiScreen { public static final ResourceLocation pv_invs = new ResourceLocation("notenoughupdates:pv_invs.png"); public static final ResourceLocation pv_cols = new ResourceLocation("notenoughupdates:pv_cols.png"); public static final ResourceLocation pv_pets = new ResourceLocation("notenoughupdates:pv_pets.png"); + public static final ResourceLocation pv_dropdown = new ResourceLocation("notenoughupdates:pv_dropdown.png"); public static final ResourceLocation pv_bg = new ResourceLocation("notenoughupdates:pv_bg.png"); public static final ResourceLocation pv_elements = new ResourceLocation("notenoughupdates:pv_elements.png"); public static final ResourceLocation resource_packs = new ResourceLocation("minecraft:textures/gui/resource_packs.png"); @@ -89,11 +90,16 @@ public class GuiProfileViewer extends GuiScreen { private List<String> tooltipToDisplay = null; + private String profileId = null; + private boolean profileDropdownSelected = false; + public enum ProfileViewerPage { + LOADING(null), + INVALID_NAME(null), BASIC(new ItemStack(Items.paper)), INVS(new ItemStack(Item.getItemFromBlock(Blocks.ender_chest))), - COLS(new ItemStack(Items.painting)), - PETS(new ItemStack(Items.bone)); + COLS(new ItemStack(Items.painting)); + //PETS(new ItemStack(Items.bone)); public final ItemStack stack; @@ -105,13 +111,27 @@ public class GuiProfileViewer extends GuiScreen { public GuiProfileViewer(ProfileViewer.Profile profile) { this.profile = profile; + String name = ""; + if(profile != null) { + name = profile.getHypixelProfile().get("displayname").getAsString(); + } + playerNameTextField = new GuiElementTextField(name, + GuiElementTextField.SCALE_TEXT); + playerNameTextField.setSize(100, 20); } + private GuiElementTextField playerNameTextField; + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { currentTime = System.currentTimeMillis(); if(startTime == 0) startTime = currentTime; + if(profile == null) currentPage = ProfileViewerPage.INVALID_NAME; + if(profileId == null && profile != null && profile.getLatestProfile() != null) { + profileId = profile.getLatestProfile(); + } + this.sizeX = 431; this.sizeY = 202; this.guiLeft = (this.width-this.sizeX)/2; @@ -121,7 +141,7 @@ public class GuiProfileViewer extends GuiScreen { drawDefaultBackground(); blurBackground(); - renderBlurredBackground(width, height, guiLeft, guiTop, sizeX, sizeY); + renderBlurredBackground(width, height, guiLeft+2, guiTop+2, sizeX-4, sizeY-4); GlStateManager.translate(0, 0, 5); renderTabs(true); @@ -151,13 +171,56 @@ public class GuiProfileViewer extends GuiScreen { case COLS: drawColsPage(mouseX, mouseY, partialTicks); break; - case PETS: - drawPetsPage(mouseX, mouseY, partialTicks); + case LOADING: + Utils.drawStringCentered(EnumChatFormatting.YELLOW+"Loading player profiles...", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); + break; + case INVALID_NAME: + Utils.drawStringCentered(EnumChatFormatting.RED+"Invalid name or API is down!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+sizeX/2f, guiTop+101, true, 0); break; + //case PETS: + // drawPetsPage(mouseX, mouseY, partialTicks); + // break; } lastTime = currentTime; + if(!(currentPage == ProfileViewerPage.LOADING)) { + playerNameTextField.render(guiLeft+sizeX-100, guiTop+sizeY+5); + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + if(profile != null) { + renderBlurredBackground(width, height, guiLeft+2, guiTop+sizeY+3+2, 100-4, 20-4); + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_dropdown); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+3, 100, 20, + 0, 100/200f, 0, 20/185f, GL11.GL_NEAREST); + Utils.drawStringCenteredScaledMaxWidth(profileId, Minecraft.getMinecraft().fontRendererObj, guiLeft+50, + guiTop+sizeY+3+10, true, 90, new Color(63, 224, 208, 255).getRGB()); + + if(profileDropdownSelected && !profile.getProfileIds().isEmpty() && scaledResolution.getScaleFactor() != 4) { + int dropdownOptionSize = scaledResolution.getScaleFactor()==3?10:20; + + int numProfiles = profile.getProfileIds().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(guiLeft, guiTop+sizeY+23+sizeYDropdown-4, 100, 4, + 100/200f, 1, 181/185f, 1, GL11.GL_NEAREST); + Utils.drawTexturedRect(guiLeft, guiTop+sizeY+23, 100, sizeYDropdown-4, + 100/200f, 1, (181-sizeYDropdown)/185f, 181/185f, GL11.GL_NEAREST); + + for(int yIndex=0; yIndex<profile.getProfileIds().size(); yIndex++) { + String otherProfileId = profile.getProfileIds().get(yIndex); + Utils.drawStringCenteredScaledMaxWidth(otherProfileId, Minecraft.getMinecraft().fontRendererObj, guiLeft+50, + guiTop+sizeY+23+dropdownOptionSize/2f+dropdownOptionSize*yIndex, true, 90, new Color(33, 112, 104, 255).getRGB()); + } + + } + } + } if(tooltipToDisplay != null) { List<String> grayTooltip = new ArrayList<>(tooltipToDisplay.size()); @@ -169,12 +232,33 @@ public class GuiProfileViewer extends GuiScreen { } } + private boolean isLoadedProfile() { + return profile.getProfileInformation(profileId) != null; + } + + private boolean isCollectionApiEnabled() { + return profile.getCollectionInfo(profileId) != null; + } + + private boolean isInventoryApiEnabled() { + return profile.getInventoryInfo(profileId) != null; + } + + private boolean isSkillsApiEnabled() { + return profile.getSkillInfo(profileId) != null; + } + private void renderTabs(boolean renderPressed) { + int ignoredTabs = 0; for(int i=0; i<ProfileViewerPage.values().length; i++) { ProfileViewerPage page = ProfileViewerPage.values()[i]; + if(page.stack == null) { + ignoredTabs++; + continue; + } boolean pressed = page == currentPage; if(pressed == renderPressed) { - renderTab(page.stack, i, pressed); + renderTab(page.stack, i-ignoredTabs, pressed); } } } @@ -203,9 +287,9 @@ public class GuiProfileViewer extends GuiScreen { uMax = 56/256f; } - //if(!Keyboard.isKeyDown(Keyboard.KEY_A)) renderBlurredBackground(width, height, x, y, 28, 28); + renderBlurredBackground(width, height, x+2, y+2, 28-4, 28-4); } else { - //renderBlurredBackground(width, height, x, y+2, 28, 28); + renderBlurredBackground(width, height, x+2, y+4, 28-4, 28-4); } GlStateManager.disableLighting(); @@ -222,17 +306,26 @@ public class GuiProfileViewer extends GuiScreen { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - for(int i=0; i<ProfileViewerPage.values().length; i++) { - ProfileViewerPage page = ProfileViewerPage.values()[i]; - int x = guiLeft+i*28; - int y = guiTop-28; - - if(mouseX > x && mouseX < x+28) { - if(mouseY > y && mouseY < y+32) { - if(currentPage != page) Utils.playPressSound(); - currentPage = page; - inventoryTextField.otherComponentClick(); - return; + if(currentPage != ProfileViewerPage.LOADING && currentPage != ProfileViewerPage.INVALID_NAME) { + int ignoredTabs = 0; + for(int i=0; i<ProfileViewerPage.values().length; i++) { + ProfileViewerPage page = ProfileViewerPage.values()[i]; + if(page.stack == null) { + ignoredTabs++; + continue; + } + 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) { + if(currentPage != page) Utils.playPressSound(); + currentPage = page; + inventoryTextField.otherComponentClick(); + playerNameTextField.otherComponentClick(); + return; + } } } } @@ -242,10 +335,64 @@ public class GuiProfileViewer extends GuiScreen { if(mouseX > guiLeft+19 && mouseX < guiLeft+19+88) { if(mouseY > guiTop+sizeY-26-20 && mouseY < guiTop+sizeY-26) { inventoryTextField.mouseClicked(mouseX, mouseY, mouseButton); + playerNameTextField.otherComponentClick(); return; } } } + if(mouseX > guiLeft+sizeX-100 && mouseX < guiLeft+sizeX) { + if(mouseY > guiTop+sizeY+5 && mouseY < guiTop+sizeY+25) { + playerNameTextField.mouseClicked(mouseX, mouseY, mouseButton); + inventoryTextField.otherComponentClick(); + return; + } + } + if(mouseX > guiLeft && mouseX < guiLeft+100 && profile != null && !profile.getProfileIds().isEmpty()) { + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + if(mouseY > guiTop+sizeY+3 && mouseY < guiTop+sizeY+23) { + if(scaledResolution.getScaleFactor() == 4) { + profileDropdownSelected = false; + int profileNum = 0; + for(int index=0; index<profile.getProfileIds().size(); index++) { + if(profile.getProfileIds().get(index).equals(profileId)) { + profileNum = index; + break; + } + } + if(mouseButton == 0) { + profileNum++; + } else { + profileNum--; + } + if(profileNum >= profile.getProfileIds().size()) profileNum = 0; + if(profileNum < 0) profileNum = profile.getProfileIds().size()-1; + + String newProfileId = profile.getProfileIds().get(profileNum); + if(profileId != null && !profileId.equals(newProfileId)) { + resetCache(); + } + profileId = newProfileId; + } else { + profileDropdownSelected = !profileDropdownSelected; + } + } else if(scaledResolution.getScaleFactor() != 4) { + int dropdownOptionSize = scaledResolution.getScaleFactor()==3?10:20; + int extraY = mouseY - (guiTop+sizeY+23); + int index = extraY/dropdownOptionSize; + if(index >= 0 && index < profile.getProfileIds().size()) { + String newProfileId = profile.getProfileIds().get(index); + if(profileId != null && !profileId.equals(newProfileId)) { + resetCache(); + } + profileId = newProfileId; + } + } + playerNameTextField.otherComponentClick(); + inventoryTextField.otherComponentClick(); + return; + } + profileDropdownSelected = false; + playerNameTextField.otherComponentClick(); inventoryTextField.otherComponentClick(); } @@ -261,6 +408,16 @@ public class GuiProfileViewer extends GuiScreen { keyTypedCols(typedChar, keyCode); break; } + if(playerNameTextField.getFocus() && !(currentPage == ProfileViewerPage.LOADING)) { + if(keyCode == Keyboard.KEY_RETURN) { + currentPage = ProfileViewerPage.LOADING; + NotEnoughUpdates.profileViewer.getProfileByName(playerNameTextField.getText(), profile -> { //todo: invalid name + if(profile != null) profile.resetCache(); + Minecraft.getMinecraft().displayGuiScreen(new GuiProfileViewer(profile)); + }); + } + playerNameTextField.keyTyped(typedChar, keyCode); + } } @Override @@ -347,9 +504,9 @@ public class GuiProfileViewer extends GuiScreen { i++; } - JsonObject inventoryInfo = profile.getInventoryInfo(null); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(inventoryInfo == null) return; - JsonObject collectionInfo = profile.getCollectionInfo(null); + JsonObject collectionInfo = profile.getCollectionInfo(profileId); if(collectionInfo == null) return; ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); @@ -394,11 +551,19 @@ public class GuiProfileViewer extends GuiScreen { } } + private static HashMap<String, String> minionRarityToNumMap = new HashMap<>(); + static { + minionRarityToNumMap.put("COMMON", "0"); + minionRarityToNumMap.put("UNCOMMON", "1"); + minionRarityToNumMap.put("RARE", "2"); + minionRarityToNumMap.put("EPIC", "3"); + minionRarityToNumMap.put("LEGENDARY", "4"); + } private void drawPetsPage(int mouseX, int mouseY, float partialTicks) { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_pets); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - JsonObject petsInfo = profile.getPetsInfo(null); + JsonObject petsInfo = profile.getPetsInfo(profileId); if(petsInfo == null) return; JsonArray pets = petsInfo.get("pets").getAsJsonArray(); @@ -407,7 +572,7 @@ public class GuiProfileViewer extends GuiScreen { } - if(minions != null) { + /*if(minions != null) { for (int i = 0; i < minions.size(); i++) { String minion = minions.get(i); if (minion != null) { @@ -421,7 +586,7 @@ public class GuiProfileViewer extends GuiScreen { } } } - } + }*/ } private String[] romans = new String[]{"I","II","III","IV","V","VI","VII","VIII","IX","X","XI", @@ -436,8 +601,12 @@ public class GuiProfileViewer extends GuiScreen { Minecraft.getMinecraft().getTextureManager().bindTexture(pv_cols); Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); - JsonObject collectionInfo = profile.getCollectionInfo(null); - if(collectionInfo == null) return; + JsonObject collectionInfo = profile.getCollectionInfo(profileId); + if(collectionInfo == null) { + Utils.drawStringCentered(EnumChatFormatting.RED+"Collection API not enabled!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+134, guiTop+101, true, 0); + return; + } JsonObject resourceCollectionInfo = ProfileViewer.getResourceCollectionInformation(); if(resourceCollectionInfo == null) return; @@ -694,6 +863,7 @@ public class GuiProfileViewer extends GuiScreen { } private int getAvailableSlotsForInventory(JsonObject inventoryInfo, JsonObject collectionInfo, String invName) { + if(collectionInfo == null) return -1; JsonObject misc = Utils.getConstant("misc"); if(misc == null) return -1; JsonElement sizesElement = Utils.getElement(misc, "bag_size."+invName+".sizes"); @@ -793,10 +963,52 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawTexturedRect(guiLeft, guiTop, sizeX, sizeY, GL11.GL_NEAREST); inventoryTextField.setSize(88, 20); - JsonObject inventoryInfo = profile.getInventoryInfo(null); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(inventoryInfo == null) return; - JsonObject collectionInfo = profile.getCollectionInfo(null); - if(collectionInfo == null) return; + JsonObject collectionInfo = profile.getCollectionInfo(profileId); + + int invNameIndex=0; + for(Map.Entry<String, ItemStack> entry : invNameToDisplayMap.entrySet()) { + int xIndex = invNameIndex%3; + int yIndex = invNameIndex/3; + + int x = 19+34*xIndex; + int y = 26+34*yIndex; + + Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); + if(entry.getKey().equals(selectedInventory)) { + Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 20/256f, 0, + 20/256f, 0, GL11.GL_NEAREST); + x++; + y++; + } else { + Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 0, 20/256f, + 0, 20/256f, GL11.GL_NEAREST); + } + + Utils.drawItemStackWithText(entry.getValue(), guiLeft+x, guiTop+y, ""+(invNameIndex+1)); + + if(mouseX >= guiLeft+x && mouseX <= guiLeft+x+16) { + if(mouseY >= guiTop+y && mouseY <= guiTop+y+16) { + tooltipToDisplay = entry.getValue().getTooltip(Minecraft.getMinecraft().thePlayer, false); + } + } + + invNameIndex++; + } + + inventoryTextField.render(guiLeft+19, guiTop+sizeY-26-20); + + ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); + if(currentInventoryIndex >= inventories.length) currentInventoryIndex = inventories.length-1; + if(currentInventoryIndex < 0) currentInventoryIndex = 0; + + ItemStack[][] inventory = inventories[currentInventoryIndex]; + if(inventory == null) { + Utils.drawStringCentered(EnumChatFormatting.RED+"Inventory API not enabled!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+317, guiTop+101, true, 0); + return; + } if(bestWeapons == null) { bestWeapons = findBestItems(inventoryInfo, 6, new String[]{"inv_contents", "ender_chest_contents"}, @@ -881,45 +1093,6 @@ public class GuiProfileViewer extends GuiScreen { } } - inventoryTextField.render(guiLeft+19, guiTop+sizeY-26-20); - - int i=0; - for(Map.Entry<String, ItemStack> entry : invNameToDisplayMap.entrySet()) { - int xIndex = i%3; - int yIndex = i/3; - - int x = 19+34*xIndex; - int y = 26+34*yIndex; - - Minecraft.getMinecraft().getTextureManager().bindTexture(pv_elements); - if(entry.getKey().equals(selectedInventory)) { - Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 20/256f, 0, - 20/256f, 0, GL11.GL_NEAREST); - x++; - y++; - } else { - Utils.drawTexturedRect(guiLeft+x-2, guiTop+y-2, 20, 20, 0, 20/256f, - 0, 20/256f, GL11.GL_NEAREST); - } - - Utils.drawItemStackWithText(entry.getValue(), guiLeft+x, guiTop+y, ""+(i+1)); - - if(mouseX >= guiLeft+x && mouseX <= guiLeft+x+16) { - if(mouseY >= guiTop+y && mouseY <= guiTop+y+16) { - tooltipToDisplay = entry.getValue().getTooltip(Minecraft.getMinecraft().thePlayer, false); - } - } - - i++; - } - - ItemStack[][][] inventories = getItemsForInventory(inventoryInfo, collectionInfo, selectedInventory); - if(currentInventoryIndex >= inventories.length) currentInventoryIndex = inventories.length-1; - if(currentInventoryIndex < 0) currentInventoryIndex = 0; - - ItemStack[][] inventory = inventories[currentInventoryIndex]; - if(inventory == null) return; - int inventoryRows = inventory.length; GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); @@ -1236,7 +1409,7 @@ public class GuiProfileViewer extends GuiScreen { Utils.drawStringCentered(statusStr, fr, guiLeft+63, guiTop+160, true, 0); } - if(profile.getPlayerInformation(null) == null) { + if(!isLoadedProfile()) { //TODO: "Downloading player information" return; } @@ -1268,12 +1441,11 @@ public class GuiProfileViewer extends GuiScreen { entityPlayer.getDataWatcher().updateObject(10, b); } - JsonObject profileInfo = profile.getProfileInformation(null); + JsonObject profileInfo = profile.getProfileInformation(profileId); if(profileInfo == null) return; - JsonObject skillInfo = profile.getSkillInfo(null); - JsonObject inventoryInfo = profile.getInventoryInfo(null); - JsonObject collectionInfo = profile.getCollectionInfo(null); + JsonObject skillInfo = profile.getSkillInfo(profileId); + JsonObject inventoryInfo = profile.getInventoryInfo(profileId); if(backgroundClickedX != -1 && Mouse.isButtonDown(1)) { for(int i=0; i<entityPlayer.inventory.armorInventory.length; i++) { @@ -1314,7 +1486,7 @@ public class GuiProfileViewer extends GuiScreen { } GlStateManager.color(1, 1, 1, 1); - JsonObject petsInfo = profile.getPetsInfo(null); + JsonObject petsInfo = profile.getPetsInfo(profileId); if(petsInfo != null) { JsonElement activePetElement = petsInfo.get("active_pet"); if(activePetElement != null && activePetElement.isJsonObject()) { @@ -1322,22 +1494,25 @@ public class GuiProfileViewer extends GuiScreen { String type = activePet.get("type").getAsString(); - JsonObject item = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(type+";0"); - if(item != null) { - int x = guiLeft+50; - float y = guiTop+82+15*(float)Math.sin(((currentTime-startTime)/800f)%(2*Math.PI)); - GlStateManager.translate(x, y, 0); - ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item); - GlStateManager.scale(-1.5f, 1.5f, 1); - Utils.drawItemStack(stack, 0, 0); - GlStateManager.scale(-1/1.5f, 1/1.5f, 1); - GlStateManager.translate(-x, -y, 0); + for(int i=0; i<4; i++) { + JsonObject item = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(type+";"+i); + if(item != null) { + int x = guiLeft+50; + float y = guiTop+82+15*(float)Math.sin(((currentTime-startTime)/800f)%(2*Math.PI)); + GlStateManager.translate(x, y, 0); + ItemStack stack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(item); + GlStateManager.scale(-1.5f, 1.5f, 1); + Utils.drawItemStack(stack, 0, 0); + GlStateManager.scale(-1/1.5f, 1/1.5f, 1); + GlStateManager.translate(-x, -y, 0); + break; + } } } } drawEntityOnScreen(guiLeft+63, guiTop+128+7, 36, guiLeft+63-mouseX, guiTop+129-mouseY, entityPlayer); - PlayerStats.Stats stats = profile.getStats(null); + PlayerStats.Stats stats = profile.getStats(profileId); if(stats != null) { Splitter splitter = Splitter.on(" ").omitEmptyStrings().limit(2); @@ -1360,9 +1535,9 @@ public class GuiProfileViewer extends GuiScreen { tooltipToDisplay.add(statNamePretty); int base = Math.round(baseStats.get(statName)); tooltipToDisplay.add(EnumChatFormatting.GRAY+"Base "+split.get(1)+": "+EnumChatFormatting.GREEN+base+" "+split.get(0)); - int passive = Math.round(profile.getPassiveStats(null).get(statName)-baseStats.get(statName)); + int passive = Math.round(profile.getPassiveStats(profileId).get(statName)-baseStats.get(statName)); tooltipToDisplay.add(EnumChatFormatting.GRAY+"Passive "+split.get(1)+" Bonus: +"+EnumChatFormatting.YELLOW+passive+" "+split.get(0)); - int itemBonus = Math.round(stats.get(statName)-profile.getPassiveStats(null).get(statName)); + int itemBonus = Math.round(stats.get(statName)-profile.getPassiveStats(profileId).get(statName)); tooltipToDisplay.add(EnumChatFormatting.GRAY+"Item "+split.get(1)+" Bonus: +"+EnumChatFormatting.DARK_PURPLE+itemBonus+" "+split.get(0)); int finalStat = Math.round(stats.get(statName)); tooltipToDisplay.add(EnumChatFormatting.GRAY+"Final "+split.get(1)+": +"+EnumChatFormatting.RED+finalStat+" "+split.get(0)); @@ -1370,7 +1545,12 @@ public class GuiProfileViewer extends GuiScreen { } } } else { - //"stats not enabled in api" + Utils.drawStringCentered(EnumChatFormatting.RED+"Skill/Inv/Coll", Minecraft.getMinecraft().fontRendererObj, + guiLeft+172, guiTop+101-10, true, 0); + Utils.drawStringCentered(EnumChatFormatting.RED+"APIs not", Minecraft.getMinecraft().fontRendererObj, + guiLeft+172, guiTop+101, true, 0); + Utils.drawStringCentered(EnumChatFormatting.RED+"enabled!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+172, guiTop+101+10, true, 0); } if(skillInfo != null) { @@ -1423,7 +1603,8 @@ public class GuiProfileViewer extends GuiScreen { position++; } } else { - //api not enabled + Utils.drawStringCentered(EnumChatFormatting.RED+"Skills API not enabled!", Minecraft.getMinecraft().fontRendererObj, + guiLeft+322, guiTop+101, true, 0); } } @@ -1549,6 +1730,21 @@ public class GuiProfileViewer extends GuiScreen { GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); } + public void resetCache() { + bestWeapons = null; + bestRods = null; + armorItems = null; + inventoryItems = new HashMap<>(); + currentInventoryIndex = 0; + arrowCount = -1; + greenCandyCount = -1; + purpleCandyCount = -1; + entityPlayer = null; + playerLocationSkin = null; + playerLocationCape = null; + skinType = null; + } + Shader blurShaderHorz = null; Framebuffer blurOutputHorz = null; Shader blurShaderVert = null; @@ -1643,13 +1839,13 @@ public class GuiProfileViewer extends GuiScreen { public void renderBlurredBackground(int width, int height, int x, int y, int blurWidth, int blurHeight) { float uMin = x/(float)width; float uMax = (x+blurWidth)/(float)width; - float vMin = y/(float)height; - float vMax = (y+blurHeight)/(float)height; + float vMin = (height-y)/(float)height; + float vMax = (height-y-blurHeight)/(float)height; blurOutputVert.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); //Utils.setScreen(width*f, height*f, f); - Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMax, vMin); + Utils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); //Utils.setScreen(width, height, f); blurOutputVert.unbindFramebufferTexture(); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java index 2cbb09d1..d45fd82b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/PlayerStats.java @@ -316,15 +316,15 @@ public class PlayerStats { return bonuses; } - private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: \\+([0-9]+)"); - private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: \\+([0-9]+)"); - private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: \\+([0-9]+)"); - private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: \\+([0-9]+)"); - private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: \\+([0-9]+)"); - private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: \\+([0-9]+)"); - private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: \\+([0-9]+)"); - private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: \\+([0-9]+)"); - private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: \\+([0-9]+)"); + private static final Pattern HEALTH_PATTERN = Pattern.compile("^Health: ((?:\\+|-)[0-9]+)"); + private static final Pattern DEFENCE_PATTERN = Pattern.compile("^Defense: ((?:\\+|-)[0-9]+)"); + private static final Pattern STRENGTH_PATTERN = Pattern.compile("^Strength: ((?:\\+|-)[0-9]+)"); + private static final Pattern SPEED_PATTERN = Pattern.compile("^Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern CC_PATTERN = Pattern.compile("^Crit Chance: ((?:\\+|-)[0-9]+)"); + private static final Pattern CD_PATTERN = Pattern.compile("^Crit Damage: ((?:\\+|-)[0-9]+)"); + private static final Pattern ATKSPEED_PATTERN = Pattern.compile("^Bonus Attack Speed: ((?:\\+|-)[0-9]+)"); + private static final Pattern INTELLIGENCE_PATTERN = Pattern.compile("^Intelligence: ((?:\\+|-)[0-9]+)"); + private static final Pattern SCC_PATTERN = Pattern.compile("^Sea Creature Chance: ((?:\\+|-)[0-9]+)"); private static final HashMap<String, Pattern> STAT_PATTERN_MAP = new HashMap<>(); static { STAT_PATTERN_MAP.put("health", HEALTH_PATTERN); @@ -472,6 +472,9 @@ public class PlayerStats { } for(Map.Entry<String, JsonElement> statEntry : stats.statsJson.entrySet()) { + if(statEntry.getKey().equals(CRIT_DAMAGE) || + statEntry.getKey().equals(INTELLIGENCE) || + statEntry.getKey().equals(BONUS_ATTACK_SPEED)) continue; stats.statsJson.add(statEntry.getKey(), new JsonPrimitive(Math.max(0, statEntry.getValue().getAsFloat()))); } } 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 f79b4767..c703bc9e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -261,9 +261,10 @@ public class ProfileViewer { private final HashMap<String, JsonObject> skillInfoMap = new HashMap<>(); private final HashMap<String, JsonObject> inventoryInfoMap = new HashMap<>(); private final HashMap<String, JsonObject> collectionInfoMap = new HashMap<>(); + private List<String> profileIds = new ArrayList<>(); private JsonObject playerStatus = null; - private PlayerStats.Stats stats = null; - private PlayerStats.Stats passiveStats = null; + private HashMap<String, PlayerStats.Stats> stats = new HashMap<>(); + private HashMap<String, PlayerStats.Stats> passiveStats = new HashMap<>(); public Profile(String uuid) { this.uuid = uuid; @@ -294,6 +295,10 @@ public class ProfileViewer { return null; } + public String getLatestProfile() { + return latestProfile; + } + public JsonArray getPlayerInformation(Runnable runnable) { if (playerInformation != null) return playerInformation; if (updatingPlayerInfoState.get()) return null; @@ -312,10 +317,15 @@ public class ProfileViewer { if (playerInformation == null) return; String backup = null; long backupLastSave = 0; + + profileIds.clear(); + for (int i = 0; i < playerInformation.size(); i++) { JsonObject profile = playerInformation.get(i).getAsJsonObject(); String cute_name = profile.get("cute_name").getAsString(); + profileIds.add(cute_name); + if (backup == null) backup = cute_name; if (!profile.has("members")) continue; @@ -343,6 +353,10 @@ public class ProfileViewer { return null; } + public List<String> getProfileIds() { + return profileIds; + } + public JsonObject getProfileInformation(String profileId) { JsonArray playerInfo = getPlayerInformation(() -> {}); if(playerInfo == null) return null; @@ -358,7 +372,7 @@ public class ProfileViewer { if(profile.get("cute_name").getAsString().equalsIgnoreCase(profileId)) { if(!profile.has("members")) return null; JsonObject members = profile.get("members").getAsJsonObject(); - if(!members.has(uuid)) return null; + if(!members.has(uuid)) continue; JsonObject profileInfo = members.get(uuid).getAsJsonObject(); if(profile.has("banking")) { profileInfo.add("banking", profile.get("banking").getAsJsonObject()); @@ -406,8 +420,9 @@ public class ProfileViewer { playerInformation = null; basicInfo = null; playerStatus = null; - stats = null; - passiveStats = null; + stats.clear(); + passiveStats.clear(); + profileIds.clear(); profileMap.clear(); coopProfileMap.clear(); petsInfoMap.clear(); @@ -638,13 +653,17 @@ public class ProfileViewer { JsonElement crafted_generators_element = Utils.getElement(profileInfo, "crafted_generators"); JsonElement collectionInfoElement = Utils.getElement(profileInfo, "collection"); + if(unlocked_coll_tiers_element == null || crafted_generators_element == null || collectionInfoElement == null) { + return null; + } + JsonObject collectionInfo = new JsonObject(); JsonObject collectionTiers = new JsonObject(); JsonObject minionTiers = new JsonObject(); JsonObject personalAmounts = new JsonObject(); JsonObject totalAmounts = new JsonObject(); - if(collectionInfoElement != null && collectionInfoElement.isJsonObject()) { + if(collectionInfoElement.isJsonObject()) { personalAmounts = collectionInfoElement.getAsJsonObject(); } @@ -747,25 +766,28 @@ public class ProfileViewer { } public PlayerStats.Stats getPassiveStats(String profileId) { - if(passiveStats != null) return passiveStats; + if(passiveStats.get(profileId) != null) return passiveStats.get(profileId); JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; - passiveStats = PlayerStats.getPassiveBonuses(getSkillInfo(profileId), profileInfo); + PlayerStats.Stats passiveStats = PlayerStats.getPassiveBonuses(getSkillInfo(profileId), profileInfo); if(passiveStats != null) { passiveStats.add(PlayerStats.getBaseStats()); } + this.passiveStats.put(profileId, passiveStats); + return passiveStats; } public PlayerStats.Stats getStats(String profileId) { - if(stats != null) return stats; + if(stats.get(profileId) != null) return stats.get(profileId); JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; - stats = PlayerStats.getStats(getSkillInfo(profileId), getInventoryInfo(profileId), getCollectionInfo(profileId), profileInfo); + PlayerStats.Stats stats = PlayerStats.getStats(getSkillInfo(profileId), getInventoryInfo(profileId), getCollectionInfo(profileId), profileInfo); + this.stats.put(profileId, stats); return stats; } @@ -788,12 +810,14 @@ public class ProfileViewer { args.put("name", ""+name); manager.hypixelApi.getHypixelApiAsync(manager.config.apiKey.value, "player", args, jsonObject -> { - if(jsonObject == null) return; - - if(jsonObject.has("success") && jsonObject.get("success").getAsBoolean()) { + if(jsonObject != null && jsonObject.has("success") && jsonObject.get("success").getAsBoolean() + && jsonObject.get("player").isJsonObject()) { nameToHypixelProfile.put(name, jsonObject.get("player").getAsJsonObject()); uuidToHypixelProfile.put(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), jsonObject.get("player").getAsJsonObject()); if(callback != null) callback.accept(jsonObject); + } else { + if(callback != null) callback.accept(null); + return; } } ); @@ -806,7 +830,12 @@ public class ProfileViewer { return profile; } else { getHypixelProfile(name, jsonObject -> { - callback.accept(getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), ignored -> {})); + if(jsonObject == null) { + callback.accept(null); + } else { + callback.accept(getProfileReset(jsonObject.get("player").getAsJsonObject().get("uuid").getAsString(), ignored -> {})); + } + }); } return null; |