diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-16 15:50:41 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-16 15:50:41 -0400 |
| commit | 7c00af18febf6c0b833c7633b4fb60a9a1bb93af (patch) | |
| tree | f02de145362d6a1399651ade4a130d565d7f0ba3 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java | |
| parent | b11742988dec635b5c5da7c2363803cbfafb37b1 (diff) | |
| download | notenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.tar.gz notenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.tar.bz2 notenoughupdates-7c00af18febf6c0b833c7633b4fb60a9a1bb93af.zip | |
Code Clean Up (#2)
* intellij code clean up
* optimize imports
* format
* intellij suggestions
* fix empty catch issues
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java | 102 |
1 files changed, 50 insertions, 52 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java index fc2eaf61..6f8a9a3e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java @@ -26,6 +26,7 @@ import java.util.regex.Pattern; public class AuctionBINWarning extends GuiElement { private static final AuctionBINWarning INSTANCE = new AuctionBINWarning(); + public static AuctionBINWarning getInstance() { return INSTANCE; } @@ -39,14 +40,14 @@ public class AuctionBINWarning extends GuiElement { private int lowestPrice; private boolean shouldPerformCheck() { - if(!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableBINWarning || + if (!NotEnoughUpdates.INSTANCE.config.ahTweaks.enableBINWarning || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { sellingTooltip = null; showWarning = false; return false; } - if(Minecraft.getMinecraft().currentScreen instanceof GuiChest && + if (Minecraft.getMinecraft().currentScreen instanceof GuiChest && SBInfo.getInstance().lastOpenContainerName.startsWith("Create BIN Auction")) { return true; } else { @@ -61,35 +62,34 @@ public class AuctionBINWarning extends GuiElement { } public boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - if(!shouldPerformCheck()) return false; + if (!shouldPerformCheck()) return false; - if(slotId == 29) { + if (slotId == 29) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; sellingPrice = -1; ItemStack priceStack = chest.inventorySlots.getSlot(31).getStack(); - if(priceStack != null) { + if (priceStack != null) { String displayName = priceStack.getDisplayName(); Matcher priceMatcher = ITEM_PRICE_REGEX.matcher(displayName); - if(priceMatcher.matches()) { + if (priceMatcher.matches()) { try { sellingPrice = Integer.parseInt(priceMatcher.group(1).replace(",", "")); - } catch(NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } } ItemStack sellStack = chest.inventorySlots.getSlot(13).getStack(); String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(sellStack); - if(internalname == null) { + if (internalname == null) { return false; } JsonObject itemInfo = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(internalname); - if(itemInfo == null || !itemInfo.has("displayname")) { + if (itemInfo == null || !itemInfo.has("displayname")) { sellingName = internalname; } else { sellingName = itemInfo.get("displayname").getAsString(); @@ -99,17 +99,17 @@ public class AuctionBINWarning extends GuiElement { Minecraft.getMinecraft().gameSettings.advancedItemTooltips); lowestPrice = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); - if(lowestPrice <= 0) { - lowestPrice = (int)NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); + if (lowestPrice <= 0) { + lowestPrice = (int) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); } //TODO: Add option for warning if lowest price does not exist - float factor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.warningThreshold/100; - if(factor < 0) factor = 0; - if(factor > 1) factor = 1; + float factor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.warningThreshold / 100; + if (factor < 0) factor = 0; + if (factor > 1) factor = 1; - if(sellingPrice > 0 && lowestPrice > 0 && sellingPrice < lowestPrice*factor) { + if (sellingPrice > 0 && lowestPrice > 0 && sellingPrice < lowestPrice * factor) { showWarning = true; return true; } else { @@ -120,7 +120,7 @@ public class AuctionBINWarning extends GuiElement { } public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { - if(shouldShow()) { + if (shouldShow()) { cir.setReturnValue(false); } } @@ -138,60 +138,60 @@ public class AuctionBINWarning extends GuiElement { Gui.drawRect(0, 0, width, height, 0x80000000); - RenderUtils.drawFloatingRectDark(width/2-90, height/2-45, 180, 90); + RenderUtils.drawFloatingRectDark(width / 2 - 90, height / 2 - 45, 180, 90); int neuLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth("\u00a7lNEU"); - Minecraft.getMinecraft().fontRendererObj.drawString("\u00a7lNEU", width/2+90-neuLength-3, height/2-45+4, 0xff000000); + Minecraft.getMinecraft().fontRendererObj.drawString("\u00a7lNEU", width / 2 + 90 - neuLength - 3, height / 2 - 45 + 4, 0xff000000); TextRenderUtils.drawStringCenteredScaledMaxWidth("Are you SURE?", Minecraft.getMinecraft().fontRendererObj, - width/2, height/2-45+10, false, 170, 0xffff4040); + width / 2, height / 2 - 45 + 10, false, 170, 0xffff4040); String lowestPriceStr; - if(lowestPrice > 999) { + if (lowestPrice > 999) { lowestPriceStr = Utils.shortNumberFormat(lowestPrice, 0); } else { - lowestPriceStr = ""+lowestPrice; + lowestPriceStr = "" + lowestPrice; } String sellingPriceStr; - if(sellingPrice > 999) { + if (sellingPrice > 999) { sellingPriceStr = Utils.shortNumberFormat(sellingPrice, 0); } else { - sellingPriceStr = ""+sellingPrice; + sellingPriceStr = "" + sellingPrice; } - String sellLine = "\u00a77[ \u00a7r"+sellingName+"\u00a77 ]"; + String sellLine = "\u00a77[ \u00a7r" + sellingName + "\u00a77 ]"; TextRenderUtils.drawStringCenteredScaledMaxWidth(sellLine, Minecraft.getMinecraft().fontRendererObj, - width/2, height/2-45+25, false, 170, 0xffffffff); - TextRenderUtils.drawStringCenteredScaledMaxWidth("has a lowest BIN of \u00a76"+lowestPriceStr+"\u00a7r coins", Minecraft.getMinecraft().fontRendererObj, - width/2, height/2-45+34, false, 170, 0xffa0a0a0); + width / 2, height / 2 - 45 + 25, false, 170, 0xffffffff); + TextRenderUtils.drawStringCenteredScaledMaxWidth("has a lowest BIN of \u00a76" + lowestPriceStr + "\u00a7r coins", Minecraft.getMinecraft().fontRendererObj, + width / 2, height / 2 - 45 + 34, false, 170, 0xffa0a0a0); - int buyPercentage = 100 - sellingPrice*100/lowestPrice; - if(buyPercentage <= 0) buyPercentage = 1; + int buyPercentage = 100 - sellingPrice * 100 / lowestPrice; + if (buyPercentage <= 0) buyPercentage = 1; TextRenderUtils.drawStringCenteredScaledMaxWidth("Continue selling it for", Minecraft.getMinecraft().fontRendererObj, - width/2, height/2-45+50, false, 170, 0xffa0a0a0); - TextRenderUtils.drawStringCenteredScaledMaxWidth("\u00a76"+sellingPriceStr+"\u00a7r coins? (\u00a7c-"+buyPercentage+"%\u00a7r)", + width / 2, height / 2 - 45 + 50, false, 170, 0xffa0a0a0); + TextRenderUtils.drawStringCenteredScaledMaxWidth("\u00a76" + sellingPriceStr + "\u00a7r coins? (\u00a7c-" + buyPercentage + "%\u00a7r)", Minecraft.getMinecraft().fontRendererObj, - width/2, height/2-45+59, false, 170, 0xffa0a0a0); + width / 2, height / 2 - 45 + 59, false, 170, 0xffa0a0a0); - RenderUtils.drawFloatingRectDark(width/2-43, height/2+23, 40, 16, false); - RenderUtils.drawFloatingRectDark(width/2+3, height/2+23, 40, 16, false); + RenderUtils.drawFloatingRectDark(width / 2 - 43, height / 2 + 23, 40, 16, false); + RenderUtils.drawFloatingRectDark(width / 2 + 3, height / 2 + 23, 40, 16, false); - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GREEN+"[Y]es", Minecraft.getMinecraft().fontRendererObj, - width/2-23, height/2+31, true, 36, 0xff00ff00); - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.RED+"[n]o", Minecraft.getMinecraft().fontRendererObj, - width/2+23, height/2+31, true, 36, 0xffff0000); + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GREEN + "[Y]es", Minecraft.getMinecraft().fontRendererObj, + width / 2 - 23, height / 2 + 31, true, 36, 0xff00ff00); + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.RED + "[n]o", Minecraft.getMinecraft().fontRendererObj, + width / 2 + 23, height / 2 + 31, true, 36, 0xffff0000); - if(sellingTooltip != null) { + if (sellingTooltip != null) { int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; int sellLineLength = Minecraft.getMinecraft().fontRendererObj.getStringWidth(sellLine); - if(mouseX >= width/2-sellLineLength/2 && mouseX <= width/2+sellLineLength/2 && - mouseY >= height/2-45+20 && mouseY <= height/2-45+30) { + if (mouseX >= width / 2 - sellLineLength / 2 && mouseX <= width / 2 + sellLineLength / 2 && + mouseY >= height / 2 - 45 + 20 && mouseY <= height / 2 - 45 + 30) { Utils.drawHoveringText(sellingTooltip, mouseX, mouseY, width, height, -1, Minecraft.getMinecraft().fontRendererObj); } } @@ -205,20 +205,18 @@ public class AuctionBINWarning extends GuiElement { final int width = scaledResolution.getScaledWidth(); final int height = scaledResolution.getScaledHeight(); - if(Mouse.getEventButtonState()) { - if(mouseY >= height/2+23 && mouseY <= height/2+23+16) { - if(mouseX >= width/2-43 && mouseX <= width/2-3) { + if (Mouse.getEventButtonState()) { + if (mouseY >= height / 2 + 23 && mouseY <= height / 2 + 23 + 16) { + if (mouseX >= width / 2 - 43 && mouseX <= width / 2 - 3) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId, 29, 0, 0, Minecraft.getMinecraft().thePlayer); - showWarning = false; - } else { - showWarning = false; } + showWarning = false; } - if(mouseX < width/2-90 || mouseX > width/2+90 || - mouseY < height/2-45 || mouseY > height/2+45) { + if (mouseX < width / 2 - 90 || mouseX > width / 2 + 90 || + mouseY < height / 2 - 45 || mouseY > height / 2 + 45) { showWarning = false; } } @@ -228,8 +226,8 @@ public class AuctionBINWarning extends GuiElement { @Override public boolean keyboardInput() { - if(!Keyboard.getEventKeyState()) { - if(Keyboard.getEventKey() == Keyboard.KEY_Y || Keyboard.getEventKey() == Keyboard.KEY_RETURN) { + if (!Keyboard.getEventKeyState()) { + if (Keyboard.getEventKey() == Keyboard.KEY_Y || Keyboard.getEventKey() == Keyboard.KEY_RETURN) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; Minecraft.getMinecraft().playerController.windowClick(chest.inventorySlots.windowId, 29, 0, 0, Minecraft.getMinecraft().thePlayer); |
