From 438913125287404a4ca7fd1564c8b2d811720adb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 8 Aug 2023 00:25:04 +0200 Subject: code cleanup data --- .../at/hannibal2/skyhanni/data/ApiDataLoader.kt | 2 +- .../java/at/hannibal2/skyhanni/data/BlockData.kt | 4 +-- .../java/at/hannibal2/skyhanni/data/ChatManager.kt | 11 ++++---- .../at/hannibal2/skyhanni/data/ItemTipHelper.kt | 14 ++------- .../hannibal2/skyhanni/data/ProfileStorageData.kt | 2 +- .../at/hannibal2/skyhanni/data/ScoreboardData.kt | 2 +- .../at/hannibal2/skyhanni/data/SkillExperience.kt | 4 +-- .../at/hannibal2/skyhanni/data/repo/RepoManager.kt | 4 +-- .../at/hannibal2/skyhanni/data/repo/RepoUtils.kt | 33 ++++++++++++---------- 9 files changed, 36 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt index 3c1643dad..c77210ce6 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt @@ -25,7 +25,7 @@ class ApiDataLoader { fun onRepositoryReload(event: RepositoryReloadEvent) { usePlayerApiKey = false event.getConstant("DisabledFeatures")?.let { - if (it.asJsonObject["user_api_keys"]?.asBoolean ?: false) { + if (it.asJsonObject["user_api_keys"]?.asBoolean == true) { usePlayerApiKey = true } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt b/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt index 651312599..c43fe9ad0 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt @@ -11,8 +11,8 @@ class BlockData { @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) fun onChatPacket(event: PacketEvent.ReceiveEvent) { - val packet = event.packet - if (packet == null) return + @Suppress("USELESS_ELVIS") + val packet = event.packet ?: return if (packet is S23PacketBlockChange) { val blockPos = packet.blockPosition ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt index 8b6330f6d..6b42f9397 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt @@ -38,7 +38,7 @@ object ChatManager { } } - fun getRecentMessageHistory(): List = messageHistory.toList().map { it.second } + private fun getRecentMessageHistory(): List = messageHistory.toList().map { it.second } enum class ActionKind(format: Any) { BLOCKED(EnumChatFormatting.RED.toString() + EnumChatFormatting.BOLD), @@ -97,7 +97,7 @@ object ChatManager { loggerAll.log("[$blockReason] $message") loggerFilteredTypes.getOrPut(blockReason) { LorenzLogger("chat/filter_blocked/$blockReason") } .log(message) - messageHistory.put(key, MessageFilteringResult(original, ActionKind.BLOCKED, blockReason, null)) + messageHistory[key] = MessageFilteringResult(original, ActionKind.BLOCKED, blockReason, null) return } @@ -109,9 +109,9 @@ object ChatManager { loggerModified.log(" ") loggerModified.log("[original] " + original.formattedText) loggerModified.log("[modified] " + modified.formattedText) - messageHistory.put(key, MessageFilteringResult(original, ActionKind.MODIFIED, null, modified)) + messageHistory[key] = MessageFilteringResult(original, ActionKind.MODIFIED, null, modified) } else { - messageHistory.put(key, MessageFilteringResult(original, ActionKind.ALLOWED, null, null)) + messageHistory[key] = MessageFilteringResult(original, ActionKind.ALLOWED, null, null) } } @@ -154,7 +154,7 @@ object ChatManager { SkyHanniMod.screenToOpen = ChatFilterGui(getRecentMessageHistory()) } - val chatLinesField by lazy { + private val chatLinesField by lazy { MethodHandles.publicLookup().unreflectGetter( ReflectionHelper.findField(GuiNewChat::class.java, "chatLines", "field_146252_h", "h") .makeAccessible() @@ -164,6 +164,7 @@ object ChatManager { fun retractMessage(message: IChatComponent?, reason: String) { if (message == null) return val chatGUI = Minecraft.getMinecraft().ingameGUI.chatGUI + @Suppress("UNCHECKED_CAST") val chatLines = chatLinesField.invokeExact(chatGUI) as MutableList if (!chatLines.removeIf { it.chatComponent === message }) return diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt index 943e4f50d..ee699b161 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemTipHelper.kt @@ -16,21 +16,13 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class ItemTipHelper { -// private val lastColorCacheTime = HashMap() -// private val cache = HashMap() - @SubscribeEvent fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.GuiRenderItemPost) { val stack = event.stack ?: return if (!LorenzUtils.inSkyBlock || stack.stackSize != 1) return -// val uuid = stacremovek.getLore().joinToString { ", " } - val stackTip: String -// if (lastColorCacheTime.getOrDefault(uuid, 0L) + 1000 > System.currentTimeMillis()) { -// stackTip = cache[uuid]!! -// } else { - val itemTipEvent = RenderItemTipEvent(stack, mutableListOf()) - itemTipEvent.postAndCatch() + val itemTipEvent = RenderItemTipEvent(stack, mutableListOf()) + itemTipEvent.postAndCatch() if (itemTipEvent.renderObjects.isEmpty()) return @@ -57,7 +49,7 @@ class ItemTipHelper { val gui = Minecraft.getMinecraft().currentScreen if (gui !is GuiChest) return val chest = gui.inventorySlots as ContainerChest - var inventoryName = chest.getInventoryName() + val inventoryName = chest.getInventoryName() val guiLeft = (gui as AccessorGuiContainer).guiLeft val guiTop = (gui as AccessorGuiContainer).guiTop diff --git a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt index 9c2fff90d..b69afe21a 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ProfileStorageData.kt @@ -13,7 +13,7 @@ object ProfileStorageData { var playerSpecific: Storage.PlayerSpecific? = null var profileSpecific: Storage.ProfileSpecific? = null var loaded = false - var noTabListTime = -1L + private var noTabListTime = -1L private var nextProfile: String? = null diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt index 4f72ba3e3..9aee68957 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt @@ -73,7 +73,7 @@ class ScoreboardData { return scoreboard.toCharArray().filter { it.code in 21..126 || it.code == 167 }.joinToString(separator = "") } - fun fetchScoreboardLines(): List { + private fun fetchScoreboardLines(): List { val scoreboard = Minecraft.getMinecraft().theWorld?.scoreboard ?: return emptyList() val objective = scoreboard.getObjectiveInDisplaySlot(1) ?: return emptyList() var scores = scoreboard.getSortedScores(objective) diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index e91019ff6..2db2181a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -14,8 +14,8 @@ import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class SkillExperience { - private val actionBarPattern = "(?:.*)§3\\+(?:.*) (?.*) \\((?.*)\\/(?.*)\\)(?:.*)".toPattern() - private val inventoryPattern = "(?:.*) §e(?.*)§6\\/(?:.*)".toPattern() + private val actionBarPattern = ".*§3\\+.* (?.*) \\((?.*)/(?.*)\\).*".toPattern() + private val inventoryPattern = ".* §e(?.*)§6/.*".toPattern() @SubscribeEvent fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt index faefb9e33..712f3b9fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt @@ -22,7 +22,7 @@ class RepoManager(private val configLocation: File) { fun loadRepoInformation() { atomicShouldManuallyReload.set(true) if (SkyHanniMod.feature.dev.repoAutoUpdate) { - fetchRepository().thenRun(this::reloadRepository) + fetchRepository(false).thenRun(this::reloadRepository) } else { reloadRepository() } @@ -40,7 +40,7 @@ class RepoManager(private val configLocation: File) { reloadRepository("Repo loaded from local files successful :)") } - private fun fetchRepository(command: Boolean = false): CompletableFuture { + private fun fetchRepository(command: Boolean): CompletableFuture { return CompletableFuture.supplyAsync { try { val currentCommitJSON: JsonObject? = getJsonFromFile(File(configLocation, "currentCommit.json")) diff --git a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt index db4735aeb..e2cbedca3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/repo/RepoUtils.kt @@ -64,6 +64,7 @@ object RepoUtils { } } + @Suppress("NAME_SHADOWING") @Throws(IOException::class) private fun isInTree(rootDirectory: File, file: File): Boolean { var rootDirectory = rootDirectory @@ -78,21 +79,23 @@ object RepoUtils { } fun getConstant(repo: File, constant: String, gson: Gson, clazz: Class?): T? { - if (repo.exists()) { - val jsonFile = File(repo, "constants/$constant.json") - if (!jsonFile.isFile) { - CopyErrorCommand.logError(Error("File '$jsonFile' not found!"), "File in repo missing! ($jsonFile). Try §e/shupdaterepo") - return null - } - BufferedReader( - InputStreamReader( - FileInputStream(jsonFile), - StandardCharsets.UTF_8 - ) - ).use { reader -> - return gson.fromJson(reader, clazz) - } + if (!repo.exists()) return null + + val jsonFile = File(repo, "constants/$constant.json") + if (!jsonFile.isFile) { + CopyErrorCommand.logError( + Error("File '$jsonFile' not found!"), + "File in repo missing! ($jsonFile). Try §e/shupdaterepo" + ) + return null + } + BufferedReader( + InputStreamReader( + FileInputStream(jsonFile), + StandardCharsets.UTF_8 + ) + ).use { reader -> + return gson.fromJson(reader, clazz) } - return null } } \ No newline at end of file -- cgit