diff options
author | Walker Selby <git@walkerselby.com> | 2023-09-29 11:30:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 20:30:27 +0200 |
commit | 343d5d9cea12beaf7a8dfabda2f61ad940be592a (patch) | |
tree | ceb0a82790eaa1a1babfe4a2e05220378037a748 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | b364b6da62668ea44dfc23180fe70c13ec707804 (diff) | |
download | skyhanni-343d5d9cea12beaf7a8dfabda2f61ad940be592a.tar.gz skyhanni-343d5d9cea12beaf7a8dfabda2f61ad940be592a.tar.bz2 skyhanni-343d5d9cea12beaf7a8dfabda2f61ad940be592a.zip |
Random Code Cleanup (#516)
Sonar Lint for the win #516
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
12 files changed, 79 insertions, 152 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt index 5cf493fd5..f9e8ddb86 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt @@ -133,14 +133,6 @@ object EntityUtils { fun EntityLivingBase.isAtFullHealth() = baseMaxHealth == health.toInt() -// fun WorldClient.getEntitiesNearby( -// clazz: Class<EntityBlaze>, -// location: LorenzVec, -// radius: Double -// ): MutableList<EntityBlaze> = getEntities(clazz) { entity -> -// entity?.getLorenzVec()?.let { it.distance(location) < radius } ?: false -// } - fun EntityArmorStand.hasSkullTexture(skin: String): Boolean { if (inventory == null) return false return inventory.any { it != null && it.getSkullTexture() == skin } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt index a8d493018..e250511a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/GuiRenderUtils.kt @@ -254,12 +254,10 @@ object GuiRenderUtils { if (filledWidth < 2) xPos + 1 else xPos + filledWidth - 1, yPos + 19, barColor ) - if (tooltip != "") { - if (isPointInRect(mouseX, mouseY, xPos - 2, yPos - 2, width + 4, 20 + 4)) { - val split = tooltip.split("\n") - for (line in split) { - output.add(line) - } + if (tooltip != "" && isPointInRect(mouseX, mouseY, xPos - 2, yPos - 2, width + 4, 20 + 4)) { + val split = tooltip.split("\n") + for (line in split) { + output.add(line) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 176266d1d..a2c1f1aa3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -69,12 +69,8 @@ object ItemUtils { } } - if (withCursorItem) { - if (player.inventory != null) { - if (player.inventory.itemStack != null) { - list.add(player.inventory.itemStack) - } - } + if (withCursorItem && player.inventory != null && player.inventory.itemStack != null) { + list.add(player.inventory.itemStack) } return list } @@ -92,14 +88,9 @@ object ItemUtils { } } - if (withCursorItem) { - if (player.inventory != null) { - if (player.inventory.itemStack != null) { - map[player.inventory.itemStack] = -1 - } - } + if (withCursorItem && player.inventory != null && player.inventory.itemStack != null) { + map[player.inventory.itemStack] = -1 } - return map } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt index 0da4c5d80..a382a5149 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzLogger.kt @@ -58,10 +58,8 @@ class LorenzLogger(filePath: String) { private fun createParent(file: File) { val parent = file.parentFile - if (parent != null) { - if (!parent.isDirectory) { - parent.mkdirs() - } + if (parent != null && !parent.isDirectory) { + parent.mkdirs() } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 3ad8e3fe9..4a60f18a4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -70,10 +70,8 @@ object LorenzUtils { var lastButtonClicked = 0L fun debug(message: String) { - if (SkyHanniMod.feature.dev.debugEnabled) { - if (internalChat(DEBUG_PREFIX + message)) { - consoleLog("[Debug] $message") - } + if (SkyHanniMod.feature.dev.debugEnabled && internalChat(DEBUG_PREFIX + message)) { + consoleLog("[Debug] $message") } } @@ -151,7 +149,6 @@ object LorenzUtils { fun formatPercentage(percentage: Double): String = formatPercentage(percentage, "0.00") fun formatPercentage(percentage: Double, format: String?): String = -// NumberFormat.getPercentInstance().format(percentage) DecimalFormat(format).format(percentage * 100).replace(',', '.') + "%" fun formatInteger(i: Int): String = formatInteger(i.toLong()) @@ -297,7 +294,7 @@ object LorenzUtils { fun isControlKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LCONTROL) || OSUtils.isKeyHeld(Keyboard.KEY_RCONTROL) // A mac-only key, represents Windows key on windows (but different key code) - fun isCommandKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LMETA) || OSUtils.isKeyHeld(Keyboard.KEY_LMETA) + fun isCommandKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LMETA) || OSUtils.isKeyHeld(Keyboard.KEY_RMETA) // MoulConfig is in Java, I don't want to downgrade this logic fun <T> onChange(vararg properties: Property<out T>, observer: Observer<T>) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt index f929e7e06..948b8bfdd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt @@ -39,30 +39,22 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter { val formattedMessage = message.formattedMessage val thrown = event.thrown - if (SkyHanniMod.feature.dev.filterChat) { - if (formattedMessage.startsWith("[CHAT] ")) { - filterConsole("chat") - return Filter.Result.DENY - } + if (SkyHanniMod.feature.dev.filterChat && formattedMessage.startsWith("[CHAT] ")) { + filterConsole("chat") + return Filter.Result.DENY } - if (SkyHanniMod.feature.dev.filterGrowBuffer) { - if (formattedMessage.startsWith("Needed to grow BufferBuilder buffer: Old size ")) { - filterConsole("Grow BufferBuilder buffer") - return Filter.Result.DENY - } + if (SkyHanniMod.feature.dev.filterGrowBuffer && formattedMessage.startsWith("Needed to grow BufferBuilder buffer: Old size ")) { + filterConsole("Grow BufferBuilder buffer") + return Filter.Result.DENY } - if (SkyHanniMod.feature.dev.filterUnknownSound) { - if (formattedMessage.startsWith("Unable to play unknown soundEvent: minecraft:")) { - filterConsole("Unknown soundEvent (minecraft:)") - return Filter.Result.DENY - } + if (SkyHanniMod.feature.dev.filterUnknownSound && formattedMessage.startsWith("Unable to play unknown soundEvent: minecraft:")) { + filterConsole("Unknown soundEvent (minecraft:)") + return Filter.Result.DENY } //TODO testing - if (SkyHanniMod.feature.dev.filterParticleVillagerHappy) { - if (formattedMessage == "Could not spawn particle effect VILLAGER_HAPPY") { - filterConsole("particle VILLAGER_HAPPY") - return Filter.Result.DENY - } + if (SkyHanniMod.feature.dev.filterParticleVillagerHappy && formattedMessage == "Could not spawn particle effect VILLAGER_HAPPY") { + filterConsole("particle VILLAGER_HAPPY") + return Filter.Result.DENY } if (SkyHanniMod.feature.dev.filterOptiFine) { @@ -75,18 +67,14 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter { return Filter.Result.DENY } } - if (loggerName == "AsmHelper") { - if (SkyHanniMod.feature.dev.filterAmsHelperTransformer) { + if (loggerName == "AsmHelper" && SkyHanniMod.feature.dev.filterAmsHelperTransformer) { if (formattedMessage.startsWith("Transforming class ")) { filterConsole("AsmHelper Transforming") return Filter.Result.DENY - } } - if (SkyHanniMod.feature.dev.filterAsmHelperApplying) { - if (formattedMessage.startsWith("Applying AsmWriter ModifyWriter")) { - filterConsole("AsmHelper Applying AsmWriter") - return Filter.Result.DENY - } + if (SkyHanniMod.feature.dev.filterAsmHelperApplying && formattedMessage.startsWith("Applying AsmWriter ModifyWriter")) { + filterConsole("AsmHelper Applying AsmWriter") + return Filter.Result.DENY } } @@ -125,38 +113,32 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter { } } - if (thrown != null) { + if (thrown != null && SkyHanniMod.feature.dev.filterScoreboardErrors) { val cause = thrown.cause - if (cause != null) { - if (cause.stackTrace.isNotEmpty()) { - val first = cause.stackTrace[0] - if (SkyHanniMod.feature.dev.filterScoreboardErrors) { - val firstName = first.toString() - if (firstName == "net.minecraft.scoreboard.Scoreboard.removeTeam(Scoreboard.java:229)" || - firstName == "net.minecraft.scoreboard.Scoreboard.removeTeam(Scoreboard.java:262)" - ) { - filterConsole("NullPointerException at Scoreboard.removeTeam") - return Filter.Result.DENY - } - if (firstName == "net.minecraft.scoreboard.Scoreboard.createTeam(Scoreboard.java:218)") { - filterConsole("IllegalArgumentException at Scoreboard.createTeam") - return Filter.Result.DENY - } - if (firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:179)" || - firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:198)" - ) { - filterConsole("IllegalArgumentException at Scoreboard.removeObjective") - return Filter.Result.DENY - } - } + if (cause != null && cause.stackTrace.isNotEmpty()) { + val first = cause.stackTrace[0] + val firstName = first.toString() + if (firstName == "net.minecraft.scoreboard.Scoreboard.removeTeam(Scoreboard.java:229)" || + firstName == "net.minecraft.scoreboard.Scoreboard.removeTeam(Scoreboard.java:262)" + ) { + filterConsole("NullPointerException at Scoreboard.removeTeam") + return Filter.Result.DENY } - } - if (SkyHanniMod.feature.dev.filterScoreboardErrors) { - if (thrown.toString().contains(" java.lang.IllegalArgumentException: A team with the name '")) { - filterConsole("IllegalArgumentException because scoreboard team already exists") + if (firstName == "net.minecraft.scoreboard.Scoreboard.createTeam(Scoreboard.java:218)") { + filterConsole("IllegalArgumentException at Scoreboard.createTeam") + return Filter.Result.DENY + } + if (firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:179)" || + firstName == "net.minecraft.scoreboard.Scoreboard.removeObjective(Scoreboard.java:198)" + ) { + filterConsole("IllegalArgumentException at Scoreboard.removeObjective") return Filter.Result.DENY } } + if (thrown.toString().contains(" java.lang.IllegalArgumentException: A team with the name '")) { + filterConsole("IllegalArgumentException because scoreboard team already exists") + return Filter.Result.DENY + } } if (!SkyHanniMod.feature.dev.printUnfilteredDebugs) return Filter.Result.ACCEPT @@ -178,19 +160,17 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter { debug("marker is null") } debug("thrown: '$thrown'") - if (thrown != null) { - if (thrown.stackTrace.isNotEmpty()) { - var element = thrown.stackTrace[0] - debug("thrown first element: '$element'") - val cause = thrown.cause - if (cause != null) { - debug("throw cause: '$cause'") - if (cause.stackTrace.isNotEmpty()) { - element = cause.stackTrace[0] - debug("thrown cause first element: '$element'") - } else { - debug("thrown cause has no elements") - } + if (thrown != null && thrown.stackTrace.isNotEmpty()) { + var element = thrown.stackTrace[0] + debug("thrown first element: '$element'") + val cause = thrown.cause + if (cause != null) { + debug("throw cause: '$cause'") + if (cause.stackTrace.isNotEmpty()) { + element = cause.stackTrace[0] + debug("thrown cause first element: '$element'") + } else { + debug("thrown cause has no elements") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index fac794a53..6e943b059 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -246,37 +246,25 @@ object NEUItems { val count = ingredient.count.toInt() var internalItemId = ingredient.internalItemId // ignore cactus green - if (internalName == "ENCHANTED_CACTUS_GREEN") { - if (internalItemId == "INK_SACK-2") { - internalItemId = "CACTUS" - } + if (internalName == "ENCHANTED_CACTUS_GREEN" && internalItemId == "INK_SACK-2") { + internalItemId = "CACTUS" } // ignore wheat in enchanted cookie - if (internalName == "ENCHANTED_COOKIE") { - if (internalItemId == "WHEAT") { + if (internalName == "ENCHANTED_COOKIE" && internalItemId == "WHEAT") { continue - } } // ignore golden carrot in enchanted golden carrot - if (internalName == "ENCHANTED_GOLDEN_CARROT") { - if (internalItemId == "GOLDEN_CARROT") { + if (internalName == "ENCHANTED_GOLDEN_CARROT" && internalItemId == "GOLDEN_CARROT") { continue - } } // ignore rabbit hide in leather - if (internalName == "LEATHER") { - if (internalItemId == "RABBIT_HIDE") { + if (internalName == "LEATHER" && internalItemId == "RABBIT_HIDE") { continue - } } -// println("") -// println("rawId: $rawId") -// println("internalItemId: $internalItemId") - val old = map.getOrDefault(internalItemId, 0) map[internalItemId] = old + count } @@ -332,9 +320,7 @@ object NEUItems { if (!jsonObject.has("internalname")) { jsonObject.add("internalname", JsonPrimitive("_")) } - if (removeLore) { - if (jsonObject.has("lore")) jsonObject.remove("lore") - } + if (removeLore && jsonObject.has("lore")) jsonObject.remove("lore") val jsonString = jsonObject.toString() return StringUtils.encodeBase64(jsonString) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt index 3fe7f6973..7a780c3b5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ParkourHelper.kt @@ -53,10 +53,8 @@ class ParkourHelper( if (visible) { for ((index, location) in locations.withIndex()) { - if (location.offsetCenter().distanceToPlayer() < detectionRange) { - if (Minecraft.getMinecraft().thePlayer.onGround) { - current = index - } + if (location.offsetCenter().distanceToPlayer() < detectionRange && Minecraft.getMinecraft().thePlayer.onGround) { + current = index } } } @@ -64,10 +62,8 @@ class ParkourHelper( val distanceToPlayer = locations.first().offsetCenter().distanceToPlayer() if (distanceToPlayer < detectionRange) { visible = true - } else if (distanceToPlayer > 15) { - if (current < 1) { - visible = false - } + } else if (distanceToPlayer > 15 && current < 1) { + visible = false } if (!visible) return @@ -117,10 +113,8 @@ class ParkourHelper( event.drawFilledBoundingBox_nea(aabb, colorForIndex(index), 1f) if (outline) event.outlineTopFace(aabb, 2, Color.BLACK, true) } - if (SkyHanniMod.feature.dev.waypoint.showPlatformNumber) { - if (!isMovingPlatform) { - event.drawString(location.offsetCenter().add(0, 1, 0), "§a§l$index", seeThroughBlocks = true) - } + if (SkyHanniMod.feature.dev.waypoint.showPlatformNumber && !isMovingPlatform) { + event.drawString(location.offsetCenter().add(0, 1, 0), "§a§l$index", seeThroughBlocks = true) } } } catch (e: Throwable) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 405dc1bb5..ce676656e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -230,7 +230,6 @@ object RenderUtils { GlStateManager.translate(0f, -0.25f, 0f) GlStateManager.rotate(-renderManager.playerViewX, 1.0f, 0.0f, 0.0f) GlStateManager.rotate(renderManager.playerViewY, 0.0f, 1.0f, 0.0f) -// RenderUtil.drawNametag(EnumChatFormatting.YELLOW.toString() + dist.roundToInt() + "m") GlStateManager.popMatrix() GlStateManager.disableLighting() @@ -333,9 +332,7 @@ object RenderUtils { GlStateManager.rotate(-renderManager.playerViewY, 0f, 1f, 0f) GlStateManager.rotate(renderManager.playerViewX, 1f, 0f, 0f) GlStateManager.scale(-f1, -f1, -f1) -// GlStateManager.scale(scale, scale, scale) GlStateManager.scale(finalScale, finalScale, finalScale) -// GlStateManager.scale(finalScale, finalScale, finalScale) GlStateManager.enableBlend() GlStateManager.disableLighting() GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 1ac5ad3f1..49c9c520c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -150,11 +150,9 @@ object StringUtils { for (i in 0..steps) { val toDouble = i.toDouble() val stepPercentage = toDouble / steps - if (stepPercentage >= percentage) { - if (!inMissingArea) { - builder.append(missing) - inMissingArea = true - } + if (stepPercentage >= percentage && !inMissingArea) { + builder.append(missing) + inMissingArea = true } builder.append(step) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index bcc4bff5f..3f78c7a3b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -66,9 +66,7 @@ object TimeUtils { } count++ - if (maxUnits != -1) { - if (count == maxUnits) break - } + if (maxUnits != -1 && count == maxUnits) break } } return builder.toString().trim() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index b3ba7f906..a4a3f1460 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -105,10 +105,8 @@ interface Renderable { override fun render(posX: Int, posY: Int) { val isDown = Mouse.isButtonDown(button) - if (isDown > wasDown && isHovered(posX, posY)) { - if (condition() && shouldAllowLink(true, bypassChecks)) { - onClick() - } + if (isDown > wasDown && isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) { + onClick() } wasDown = isDown render.render(posX, posY) |