From 343d5d9cea12beaf7a8dfabda2f61ad940be592a Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Fri, 29 Sep 2023 11:30:27 -0700 Subject: Random Code Cleanup (#516) Sonar Lint for the win #516 --- .../skyhanni/features/garden/GardenAPI.kt | 5 +- .../features/garden/GardenCropMilestoneFix.kt | 6 +-- .../skyhanni/features/garden/GardenLevelDisplay.kt | 16 +++--- .../features/garden/composter/ComposterDisplay.kt | 12 ++--- .../features/garden/composter/ComposterOverlay.kt | 11 ++-- .../garden/contest/JacobContestStatsSummary.kt | 6 +-- .../contest/JacobFarmingContestsInventory.kt | 12 ++--- .../garden/farming/FarmingWeightDisplay.kt | 6 +-- .../garden/farming/GardenCropMilestoneDisplay.kt | 6 +-- .../features/garden/farming/GardenCropSpeed.kt | 2 +- .../garden/farming/WrongFungiCutterWarning.kt | 12 ++--- .../garden/fortuneguide/CaptureFarmingGear.kt | 34 +++++-------- .../features/garden/fortuneguide/FFGuideGUI.kt | 16 ++---- .../garden/visitor/GardenVisitorFeatures.kt | 59 ++++++++-------------- 14 files changed, 75 insertions(+), 128 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden') diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 76c5666c9..da588c2be 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -185,9 +185,8 @@ object GardenAPI { val blockState = event.getBlockState val cropBroken = blockState.getCropType() ?: return - if (cropBroken.multiplier == 1) { - if (blockState.isBabyCrop()) return - } + if (cropBroken.multiplier == 1 && blockState.isBabyCrop()) return + val position = event.position if (lastLocation == position) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt index 39ca5e7af..c60fd5086 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt @@ -66,10 +66,8 @@ class GardenCropMilestoneFix { val tabListValue = baseCrops + progress - smallestPercentage val newValue = tabListValue.toLong() - if (tabListCropProgress[crop] != newValue) { - if (tabListCropProgress.containsKey(crop)) { - changedValue(crop, newValue, "tab list", smallestPercentage.toInt()) - } + if (tabListCropProgress[crop] != newValue && tabListCropProgress.containsKey(crop)) { + changedValue(crop, newValue, "tab list", smallestPercentage.toInt()) } tabListCropProgress[crop] = newValue } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index 09b86deba..e479bc2ac 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -43,15 +43,13 @@ class GardenLevelDisplay { val oldLevel = GardenAPI.getGardenLevel() GardenAPI.gardenExp = gardenExp + moreExp val newLevel = GardenAPI.getGardenLevel() - if (newLevel == oldLevel + 1) { - if (newLevel > 15) { - LorenzUtils.runDelayed(50.milliseconds) { - LorenzUtils.clickableChat( - " \n§b§lGARDEN LEVEL UP §8$oldLevel ➜ §b$newLevel\n" + - " §8+§aRespect from Elite Farmers and SkyHanni members :)\n ", - "/gardenlevels" - ) - } + if (newLevel == oldLevel + 1 && newLevel > 15) { + LorenzUtils.runDelayed(50.milliseconds) { + LorenzUtils.clickableChat( + " \n§b§lGARDEN LEVEL UP §8$oldLevel ➜ §b$newLevel\n" + + " §8+§aRespect from Elite Farmers and SkyHanni members :)\n ", + "/gardenlevels" + ) } } update() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index 6cd1b5658..a69a812d7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -141,14 +141,12 @@ class ComposterDisplay { if (!config.composterNotifyLowEnabled) return val hidden = hidden ?: return - if (ComposterAPI.getOrganicMatter() <= config.composterNotifyLowOrganicMatter) { - if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) { - if (config.composterNotifyLowTitle) { - TitleUtils.sendTitle("§cYour Organic Matter is low", 4.seconds) - } - LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!") - hidden.informedAboutLowMatter = System.currentTimeMillis() + 60_000 * 5 + if (ComposterAPI.getOrganicMatter() <= config.composterNotifyLowOrganicMatter && System.currentTimeMillis() >= hidden.informedAboutLowMatter) { + if (config.composterNotifyLowTitle) { + TitleUtils.sendTitle("§cYour Organic Matter is low", 4.seconds) } + LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!") + hidden.informedAboutLowMatter = System.currentTimeMillis() + 60_000 * 5 } if (ComposterAPI.getFuel() <= config.composterNotifyLowFuel && diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 0e30451f0..3fb00194a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -101,14 +101,9 @@ class ComposterOverlay { @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!GardenAPI.inGarden()) return - if (inComposterUpgrades) { - if (extraComposterUpgrade != null) { -// if (System.currentTimeMillis() > lastHovered + 30) { - if (System.currentTimeMillis() > lastHovered + 200) { - extraComposterUpgrade = null - update() - } - } + if (inComposterUpgrades && extraComposterUpgrade != null && System.currentTimeMillis() > lastHovered + 200) { + extraComposterUpgrade = null + update() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt index 1a7cbcbda..43953feee 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobContestStatsSummary.kt @@ -21,10 +21,8 @@ class JacobContestStatsSummary { if (!isEnabled()) return if (event.clickType != ClickType.LEFT_CLICK) return - if (FarmingContestAPI.inContest) { - if (event.crop == FarmingContestAPI.contestCrop) { - blocksBroken++ - } + if (FarmingContestAPI.inContest && event.crop == FarmingContestAPI.contestCrop) { + blocksBroken++ } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt index 0334cf114..3137fac42 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/contest/JacobFarmingContestsInventory.kt @@ -126,13 +126,11 @@ class JacobFarmingContestsInventory { if (!InventoryUtils.openInventoryName().contains("Your Contests")) return val slot = event.slot.slotNumber - if (config.jacobFarmingContestHideDuplicates) { - if (duplicateSlots.contains(slot)) { - event.toolTip.clear() - event.toolTip.add("§7Duplicate contest") - event.toolTip.add("§7hidden by SkyHanni!") - return - } + if (config.jacobFarmingContestHideDuplicates && duplicateSlots.contains(slot)) { + event.toolTip.clear() + event.toolTip.add("§7Duplicate contest") + event.toolTip.add("§7hidden by SkyHanni!") + return } if (config.jacobFarmingContestRealTime) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt index 985480003..f43042bca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingWeightDisplay.kt @@ -29,10 +29,8 @@ class FarmingWeightDisplay { @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (isEnabled()) { - if (config.eliteFarmingWeightIgnoreLow || weight >= 200) { - config.eliteFarmingWeightPos.renderStrings(display, posLabel = "Farming Weight Display") - } + if (isEnabled() && config.eliteFarmingWeightIgnoreLow || weight >= 200) { + config.eliteFarmingWeightPos.renderStrings(display, posLabel = "Farming Weight Display") } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt index 4943722fe..5f82e690b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt @@ -122,10 +122,8 @@ object GardenCropMilestoneDisplay { progressDisplay = drawProgressDisplay(it) } - if (config.cropMilestoneBestDisplay) { - if (config.cropMilestoneBestAlwaysOn || currentCrop != null) { - bestCropTime.display = bestCropTime.drawBestDisplay(currentCrop) - } + if (config.cropMilestoneBestDisplay && config.cropMilestoneBestAlwaysOn || currentCrop != null) { + bestCropTime.display = bestCropTime.drawBestDisplay(currentCrop) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index c7817066e..d557d89d9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -114,7 +114,7 @@ object GardenCropSpeed { toolName.endsWith("DICER_3") -> 2 else -> -1 } - if (tier != -1 && melonDicer.size > 0 && pumpkinDicer.size > 0) { + if (tier != -1 && melonDicer.isNotEmpty() && pumpkinDicer.isNotEmpty()) { if (it == CropType.MELON) { latestMelonDicer = melonDicer[tier] } else if (it == CropType.PUMPKIN) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt index 916c31524..3ee90913e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/WrongFungiCutterWarning.kt @@ -34,15 +34,11 @@ class WrongFungiCutterWarning { if (event.crop != CropType.MUSHROOM) return val toString = event.blockState.toString() - if (toString == "minecraft:red_mushroom") { - if (mode == FungiMode.BROWN) { - notifyWrong() - } + if (toString == "minecraft:red_mushroom" && mode == FungiMode.BROWN) { + notifyWrong() } - if (toString == "minecraft:brown_mushroom") { - if (mode == FungiMode.RED) { - notifyWrong() - } + if (toString == "minecraft:brown_mushroom" && mode == FungiMode.RED) { + notifyWrong() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt index b89677aa0..b1e531329 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/CaptureFarmingGear.kt @@ -136,33 +136,25 @@ class CaptureFarmingGear { for ((_, item) in event.inventoryItems) { val split = item.getInternalName_old().split(";") - if (split.first() == "ELEPHANT") { - if (split.last().toInt() > highestElephantRarity) { - farmingItems[FarmingItems.ELEPHANT] = item - outdatedItems[FarmingItems.ELEPHANT] = false - highestElephantRarity = split.last().toInt() - } + if (split.first() == "ELEPHANT" && split.last().toInt() > highestElephantRarity) { + farmingItems[FarmingItems.ELEPHANT] = item + outdatedItems[FarmingItems.ELEPHANT] = false + highestElephantRarity = split.last().toInt() } - if (split.first() == "MOOSHROOM_COW") { - if (split.last().toInt() > highestMooshroomRarity) { - farmingItems[FarmingItems.MOOSHROOM_COW] = item - outdatedItems[FarmingItems.MOOSHROOM_COW] = false - highestMooshroomRarity = split.last().toInt() - } + if (split.first() == "MOOSHROOM_COW" && split.last().toInt() > highestMooshroomRarity) { + farmingItems[FarmingItems.MOOSHROOM_COW] = item + outdatedItems[FarmingItems.MOOSHROOM_COW] = false + highestMooshroomRarity = split.last().toInt() } - if (split.first() == "RABBIT") { - if (split.last().toInt() > highestRabbitRarity) { - farmingItems[FarmingItems.RABBIT] = item - outdatedItems[FarmingItems.RABBIT] = false - highestRabbitRarity = split.last().toInt() - } + if (split.first() == "RABBIT" && split.last().toInt() > highestRabbitRarity) { + farmingItems[FarmingItems.RABBIT] = item + outdatedItems[FarmingItems.RABBIT] = false + highestRabbitRarity = split.last().toInt() } - if (split.first() == "BEE") { - if (split.last().toInt() > highestBeeRarity) { + if (split.first() == "BEE" && split.last().toInt() > highestBeeRarity) { farmingItems[FarmingItems.BEE] = item outdatedItems[FarmingItems.BEE] = false highestBeeRarity = split.last().toInt() - } } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt index 53585603b..b1d1a0f38 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FFGuideGUI.kt @@ -207,11 +207,9 @@ open class FFGuideGUI : GuiScreen() { if (Mouse.getEventButtonState()) { mouseClickEvent() } - if (!Mouse.getEventButtonState()) { - if (Mouse.getEventDWheel() != 0) { - lastMouseScroll = Mouse.getEventDWheel() - noMouseScrollFrames = 0 - } + if (!Mouse.getEventButtonState() && Mouse.getEventDWheel() != 0) { + lastMouseScroll = Mouse.getEventDWheel() + noMouseScrollFrames = 0 } } @@ -271,22 +269,18 @@ open class FFGuideGUI : GuiScreen() { x = guiLeft - 28 y = guiTop + 15 - if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x, y, 28, 25)) { - if (selectedPage != FortuneGuidePage.CROP && selectedPage != FortuneGuidePage.OVERVIEW) { + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x, y, 28, 25) && selectedPage != FortuneGuidePage.CROP && selectedPage != FortuneGuidePage.OVERVIEW) { SoundUtils.playClickSound() selectedPage = if (currentCrop == null) { FortuneGuidePage.OVERVIEW } else { FortuneGuidePage.CROP } - } } y += 30 - if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x, y, 28, 25)) { - if (selectedPage != FortuneGuidePage.UPGRADES) { + if (GuiRenderUtils.isPointInRect(mouseX, mouseY, x, y, 28, 25) && selectedPage != FortuneGuidePage.UPGRADES) { selectedPage = FortuneGuidePage.UPGRADES SoundUtils.playClickSound() - } } if (selectedPage != FortuneGuidePage.UPGRADES) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index ea23494c7..b618c1937 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -338,14 +338,12 @@ class GardenVisitorFeatures { GardenVisitorDropStatistics.saveAndUpdate() return } - if (event.slotId == 29) { - if (event.slot.stack?.getLore()?.any { it == "§eClick to give!" } == true) { - changeStatus(visitor, VisitorStatus.ACCEPTED, "accepted") - update() - GardenVisitorDropStatistics.coinsSpent += round(lastFullPrice).toLong() - GardenVisitorDropStatistics.lastAccept = System.currentTimeMillis() - return - } + if (event.slotId == 29 && event.slot.stack?.getLore()?.any { it == "§eClick to give!" } == true) { + changeStatus(visitor, VisitorStatus.ACCEPTED, "accepted") + update() + GardenVisitorDropStatistics.coinsSpent += round(lastFullPrice).toLong() + GardenVisitorDropStatistics.lastAccept = System.currentTimeMillis() + return } } @@ -358,10 +356,8 @@ class GardenVisitorFeatures { if (config.visitorHighlightStatus != 1 && config.visitorHighlightStatus != 2) return val entity = event.entity - if (entity is EntityArmorStand) { - if (entity.name == "§e§lCLICK") { - event.isCanceled = true - } + if (entity is EntityArmorStand && entity.name == "§e§lCLICK") { + event.isCanceled = true } } @@ -502,7 +498,6 @@ class GardenVisitorFeatures { if (!GardenAPI.inGarden()) return if (!config.visitorNeedsDisplay && config.visitorHighlightStatus == 3) return if (!event.isMod(10)) return -// if (!event.isMod(300)) return if (GardenAPI.onBarnPlot && config.visitorHighlightStatus != 3) { checkVisitorsReady() @@ -624,18 +619,12 @@ class GardenVisitorFeatures { @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - if (config.visitorHypixelArrivedMessage) { - if (newVisitorArrivedMessage.matcher(event.message).matches()) { - event.blockedReason = "new_visitor_arrived" - } + if (config.visitorHypixelArrivedMessage && newVisitorArrivedMessage.matcher(event.message).matches()) { + event.blockedReason = "new_visitor_arrived" } - if (GardenAPI.inGarden()) { - if (config.visitorHideChat) { - if (hideVisitorMessage(event.message)) { + if (GardenAPI.inGarden() && config.visitorHideChat && hideVisitorMessage(event.message)) { event.blockedReason = "garden_visitor_message" - } - } } } @@ -669,18 +658,16 @@ class GardenVisitorFeatures { } } - if (config.visitorHighlightStatus == 0 || config.visitorHighlightStatus == 2) { - if (entity is EntityLivingBase) { - val color = visitor.status.color - if (color != -1) { - RenderLivingEntityHelper.setEntityColor( - entity, - color - ) { config.visitorHighlightStatus == 0 || config.visitorHighlightStatus == 2 } - } - // Haven't gotten either of the known effected visitors (Vex and Leo) so can't test for sure - if (color == -1 || !GardenAPI.inGarden()) RenderLivingEntityHelper.removeEntityColor(entity) + if ((config.visitorHighlightStatus == 0 || config.visitorHighlightStatus == 2) && entity is EntityLivingBase) { + val color = visitor.status.color + if (color != -1) { + RenderLivingEntityHelper.setEntityColor( + entity, + color + ) { config.visitorHighlightStatus == 0 || config.visitorHighlightStatus == 2 } } + // Haven't gotten either of the known effected visitors (Vex and Leo) so can't test for sure + if (color == -1 || !GardenAPI.inGarden()) RenderLivingEntityHelper.removeEntityColor(entity) } } } @@ -777,10 +764,8 @@ class GardenVisitorFeatures { } private fun showGui(): Boolean { - if (config.visitorNeedsInBazaarAlley) { - if (LorenzUtils.skyBlockIsland == IslandType.HUB && LorenzUtils.skyBlockArea == "Bazaar Alley") { - return true - } + if (config.visitorNeedsInBazaarAlley && LorenzUtils.skyBlockIsland == IslandType.HUB && LorenzUtils.skyBlockArea == "Bazaar Alley") { + return true } if (GardenAPI.hideExtraGuis()) return false -- cgit