Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Detekt Fixes Part 8 #2734

Merged
merged 10 commits into from
Oct 18, 2024
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

34 changes: 18 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -36,28 +36,30 @@ jobs:
with:
name: "Test Results"
path: versions/1.8.9/build/reports/tests/test/
#detekt:
# name: Run detekt
# runs-on: ubuntu-latest
detekt:
name: Run detekt
runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - uses: ./.github/actions/setup-normal-workspace
# # detektMain is a LOT slower than detekt, but it does type analysis
# - name: Run detekt main (w/typing analysis)
# run: |
# ./gradlew detektMain --stacktrace
# - name: Annotate detekt failures
# if: ${{ !cancelled() }}
# run: |
# chmod +x .github/scripts/process_detekt_sarif.sh
# ./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ./.github/actions/setup-normal-workspace
# detektMain is a LOT slower than detekt, but it does type analysis
- name: Run detekt main (w/typing analysis)
run: |
./gradlew detektMain --stacktrace
- name: Annotate detekt failures
if: ${{ !cancelled() }}
run: |
chmod +x .github/scripts/process_detekt_sarif.sh
./.github/scripts/process_detekt_sarif.sh versions/1.8.9/build/reports/detekt/main.sarif


preprocess:
runs-on: ubuntu-latest
name: "Build multi version"
env:
SKIP_DETEKT: "true"
steps:
- name: Checkout code
uses: actions/checkout@v4
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -367,7 +367,7 @@ detekt {

tasks.withType<Detekt>().configureEach {
onlyIf {
false // TODO: Remove onlyIf when we're ready to enforce
System.getenv("SKIP_DETEKT") != "true"
}

reports {
27 changes: 2 additions & 25 deletions detekt/baseline.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/api/ReforgeAPI.kt
Original file line number Diff line number Diff line change
@@ -201,7 +201,7 @@ object ReforgeAPI {
return Reforge(
name = it.reforgeName,
type = LorenzUtils.enumValueOf<ReforgeType>(type.first),
stats = it.reforgeStats ?: emptyMap(),
stats = it.reforgeStats.orEmpty(),
reforgeStone = it.internalName,
specialItems = type.second.takeIf { it.isNotEmpty() },
extraProperty = it.reforgeAbility,
1 change: 0 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
Original file line number Diff line number Diff line change
@@ -437,7 +437,6 @@ object SkillAPI {
val neededXp = levelingMap.filter { it.key < level }.values.sum().toLong()
ChatUtils.chat("You need §b${neededXp.addSeparators()} §eXP to be level §b${level.toDouble()}")
} else {
val base = levelingMap.values.sum().toLong()
val neededXP = xpRequiredForLevel(level.toDouble())
ChatUtils.chat("You need §b${neededXP.addSeparators()} §eXP to be level §b${level.toDouble()}")
}
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ class ConfigManager {
println("")
println(
"This crash is here to remind you to fix the missing " +
"@ConfigLink annotation over your new config position config element."
"@ConfigLink annotation over your new config position config element."
)
println("")
println("Steps to fix:")
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ object ConfigUpdaterMigrator {
if (newParentElement !is JsonObject) {
logger.log(
"Catastrophic: element at path $old could not be relocated to $new, " +
"since another element already inhabits that path"
"since another element already inhabits that path"
)
return
}
@@ -128,13 +128,11 @@ object ConfigUpdaterMigrator {
?.flatMap { player ->
player.value.asJsonObject["profiles"]?.asJsonObject?.entrySet()?.map {
"storage.players.${player.key}.profiles.${it.key}"
} ?: listOf()
}
?: listOf()
}.orEmpty()
}.orEmpty()
),
"#player" to (
storage?.get("players")?.asJsonObject?.entrySet()?.map { "storage.players.${it.key}" }
?: listOf()
storage?.get("players")?.asJsonObject?.entrySet()?.map { "storage.players.${it.key}" }.orEmpty()
),
)
val migration = ConfigFixEvent(
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package at.hannibal2.skyhanni.config.commands

import at.hannibal2.skyhanni.api.event.SkyHanniEvent
import at.hannibal2.skyhanni.config.commands.Commands.commands
import at.hannibal2.skyhanni.config.commands.Commands.commandList
import net.minecraftforge.client.ClientCommandHandler

object CommandRegistrationEvent : SkyHanniEvent() {
fun register(name: String, block: CommandBuilder.() -> Unit) {
val info = CommandBuilder(name).apply(block)
if (commands.any { it.name == name }) {
if (commandList.any { it.name == name }) {
error("The command '$name is already registered!'")
}
ClientCommandHandler.instance.registerCommand(info.toSimpleCommand())
commands.add(info)
commandList.add(info)
}
}
Original file line number Diff line number Diff line change
@@ -105,9 +105,10 @@ import at.hannibal2.skyhanni.utils.chat.ChatClickActionManager
import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternGui

@SkyHanniModule
@Suppress("LargeClass", "LongMethod")
object Commands {

val commands = mutableListOf<CommandBuilder>()
val commandList = mutableListOf<CommandBuilder>()

@HandleEvent
fun onCommandRegistration(event: CommandRegistrationEvent) {
@@ -298,6 +299,7 @@ object Commands {
event.register("shcolors") {
description = "Prints a list of all Minecraft color & formatting codes in chat."
category = CommandCategory.USERS_ACTIVE
@Suppress("AvoidBritishSpelling")
aliases = listOf("shcolor", "shcolours", "shcolour")
callback { ColorFormattingHelper.printColorCodeList() }
}
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/BossbarData.kt
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ object BossbarData {
private var bossbar: String? = null
private var previousServerBossbar = ""

fun getBossbar() = bossbar ?: ""
fun getBossbar() = bossbar.orEmpty()

@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/EventCounter.kt
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ object EventCounter {

private val config get() = SkyHanniMod.feature.dev.debug

private var map = mutableMapOf<String, Int>()
private val map = mutableMapOf<String, Int>()
private var lastUpdate = SimpleTimeMark.farPast()

private var enabled = false
Original file line number Diff line number Diff line change
@@ -87,39 +87,17 @@ object GardenCropMilestonesCommunityFix {

val lore = stack.getLore()
val next = lore.nextAfter({ GardenCropMilestones.totalPattern.matches(it) }, 3) ?: return
val total = lore.nextAfter({ GardenCropMilestones.totalPattern.matches(it) }, 6) ?: return

// debug(" ")
// debug("crop: $crop")
// debug("realTier: $realTier")

val guessNextMax = nextMax(realTier, crop)
// debug("guessNextMax: ${guessNextMax.addSeparators()}")
val nextMax = amountPattern.matchMatcher(next) {
group("max").formatLong()
} ?: return
// debug("nextMax real: ${nextMax.addSeparators()}")

if (nextMax != guessNextMax) {
// debug("wrong, add to list")
wrongData.add("$crop:$realTier:${nextMax.addSeparators()}")
}

val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop) // no need to overflow here
// println("guessTotalMax: ${guessTotalMax.addSeparators()}")
val totalMax = amountPattern.matchMatcher(total) {
group("max").formatLong()
} ?: return
// println("totalMax real: ${totalMax.addSeparators()}")
val totalOffBy = guessTotalMax - totalMax
// debug("$crop total offf by: ${totalOffBy.addSeparators()}")
}

// fun debug(message: String) {
// if (SkyHanniMod.feature.dev.debug.enabled) {
// println(message)
// }
// }

/**
* This helps to fix wrong crop milestone data
* This command reads the clipboard content,
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ object GuiEditManager {

private var lastHotkeyPressed = SimpleTimeMark.farPast()

private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private val currentPositions = TimeLimitedCache<String, Position>(15.seconds)
private val currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private var lastMovedGui: String? = null

@SubscribeEvent
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt
Original file line number Diff line number Diff line change
@@ -40,5 +40,5 @@ object GuildAPI {

fun isInGuild(name: String) = name in getAllMembers()

fun getAllMembers() = ProfileStorageData.playerSpecific?.guildMembers ?: emptyList()
fun getAllMembers() = ProfileStorageData.playerSpecific?.guildMembers.orEmpty()
}
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/HotmData.kt
Original file line number Diff line number Diff line change
@@ -447,6 +447,7 @@ enum class HotmData(
"perk.enable",
"§a§lENABLED|(§.)*SELECTED",
)
@Suppress("UnusedPrivateProperty")
private val disabledPattern by patternGroup.pattern(
"perk.disabled",
"§c§lDISABLED|§7§eClick to select!",
@@ -530,7 +531,7 @@ enum class HotmData(
HotmAPI.MayhemPerk.entries.forEach {
it.chatPattern
}
(0..CORE_OF_THE_MOUNTAIN.maxLevel).forEach { level ->
for (level in 0..CORE_OF_THE_MOUNTAIN.maxLevel) {
val map = mutableMapOf<HotmReward, Double>()
if (level >= 1) map.addOrPut(HotmReward.EXTRA_TOKENS, 1.0)
if (level >= 2) map.addOrPut(HotmReward.ABILITY_LEVEL, 1.0)
23 changes: 12 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ object HypixelData {
"servername.scoreboard",
"§e(?<prefix>.+\\.)?hypixel\\.net",
)
@Suppress("UnusedPrivateProperty")
private val islandNamePattern by patternGroup.pattern(
"islandname",
"(?:§.)*(Area|Dungeon): (?:§.)*(?<island>.*)",
@@ -139,7 +140,7 @@ object HypixelData {

// Data from locraw
var locrawData: JsonObject? = null
private var locraw: MutableMap<String, String> = listOf(
private val locraw: MutableMap<String, String> = listOf(
"server",
"gametype",
"lobbyname",
@@ -148,12 +149,12 @@ object HypixelData {
"map",
).associateWith { "" }.toMutableMap()

val server get() = locraw["server"] ?: ""
val gameType get() = locraw["gametype"] ?: ""
val lobbyName get() = locraw["lobbyname"] ?: ""
val lobbyType get() = locraw["lobbytype"] ?: ""
val mode get() = locraw["mode"] ?: ""
val map get() = locraw["map"] ?: ""
val server get() = locraw["server"].orEmpty()
val gameType get() = locraw["gametype"].orEmpty()
val lobbyName get() = locraw["lobbyname"].orEmpty()
val lobbyType get() = locraw["lobbytype"].orEmpty()
val mode get() = locraw["mode"].orEmpty()
val map get() = locraw["map"].orEmpty()

fun checkCurrentServerId() {
if (!LorenzUtils.inSkyBlock) return
@@ -267,7 +268,7 @@ object HypixelData {
if (obj.has("server")) {
locrawData = obj
for (key in locraw.keys) {
locraw[key] = obj[key]?.asString ?: ""
locraw[key] = obj[key]?.asString.orEmpty()
}
inLimbo = locraw["server"] == "limbo"
inLobby = locraw["lobbyname"] != ""
@@ -286,7 +287,7 @@ object HypixelData {
}
}

private var loggerIslandChange = LorenzLogger("debug/island_change")
private val loggerIslandChange = LorenzLogger("debug/island_change")

@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
@@ -442,7 +443,7 @@ object HypixelData {
}
}

serverNameConnectionPattern.matchMatcher(mc.currentServerData?.serverIP ?: "") {
serverNameConnectionPattern.matchMatcher(mc.currentServerData?.serverIP.orEmpty()) {
hypixel = true
if (group("prefix") == "alpha.") {
hypixelAlpha = true
@@ -497,7 +498,7 @@ object HypixelData {
TabListData.fullyLoaded = true
// Can not use color coding, because of the color effect (§f§lSKYB§6§lL§e§lOCK§A§L GUEST)
val guesting = guestPattern.matches(ScoreboardData.objectiveTitle.removeColor())
foundIsland = TabWidget.AREA.matchMatcherFirstLine { group("island").removeColor() } ?: ""
foundIsland = TabWidget.AREA.matchMatcherFirstLine { group("island").removeColor() }.orEmpty()
islandType = getIslandType(foundIsland, guesting)
}

2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ object ItemAddManager {
}

private var lastDiceRoll = SimpleTimeMark.farPast()
private var superCraftedItems = TimeLimitedSet<NEUInternalName>(30.seconds)
private val superCraftedItems = TimeLimitedSet<NEUInternalName>(30.seconds)

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@SkyHanniModule
object LocationFixData {

private var locationFixes = mutableMapOf<IslandType, List<LocationFix>>()
private val locationFixes = mutableMapOf<IslandType, List<LocationFix>>()

private data class LocationFix(val area: AxisAlignedBB, val realLocation: String)

2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ object MaxwellAPI {
}

var favoritePowers: List<String>
get() = storage?.maxwell?.favoritePowers ?: listOf()
get() = storage?.maxwell?.favoritePowers.orEmpty()
set(value) {
storage?.maxwell?.favoritePowers = value
}
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/MayorAPI.kt
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ object MayorAPI {
private var lastJerryExtraMayorReminder = SimpleTimeMark.farPast()

private var lastUpdate = SimpleTimeMark.farPast()
private var dispatcher = Dispatchers.IO
private val dispatcher = Dispatchers.IO

private var rawMayorData: MayorJson? = null
private var candidates = mapOf<Int, MayorCandidate>()
9 changes: 6 additions & 3 deletions src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
Original file line number Diff line number Diff line change
@@ -233,12 +233,12 @@ object SackAPI {
sibling.chatStyle?.chatHoverEvent?.value?.formattedText?.removeColor()?.takeIf {
it.startsWith("Added")
}
} ?: ""
}.orEmpty()
val sackRemoveText = event.chatComponent.siblings.firstNotNullOfOrNull { sibling ->
sibling.chatStyle?.chatHoverEvent?.value?.formattedText?.removeColor()?.takeIf {
it.startsWith("Removed")
}
} ?: ""
}.orEmpty()

val sackChangeText = sackAddText + sackRemoveText
if (sackChangeText.isEmpty()) return
@@ -345,7 +345,10 @@ object SackAPI {
var roughPrice: Long = 0,
var flawedPrice: Long = 0,
var finePrice: Long = 0,
) : AbstractSackItem()
) : AbstractSackItem() {
val priceSum: Long
get() = roughPrice + flawedPrice + finePrice
}

data class SackRune(
var stack: ItemStack? = null,
5 changes: 3 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ object ScoreboardData {

private var sidebarLines: List<String> = emptyList() // TODO rename to raw
var sidebarLinesRaw: List<String> = emptyList() // TODO delete
val objectiveTitle: String get() = Minecraft.getMinecraft().theWorld?.scoreboard?.getObjectiveInDisplaySlot(1)?.displayName ?: ""
val objectiveTitle: String get() =
Minecraft.getMinecraft().theWorld?.scoreboard?.getObjectiveInDisplaySlot(1)?.displayName.orEmpty()

private var dirty = false

@@ -48,7 +49,7 @@ object ScoreboardData {
* - '§8- §c§6Flame Dr§6agon§a 460M§c❤'
* ```
*/
val lastColor = start.lastColorCode() ?: ""
val lastColor = start.lastColorCode().orEmpty()

// Generate the list of color suffixes
val colorSuffixes = lastColor.chunked(2).toMutableList()
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.