aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-23 12:43:25 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-23 12:43:25 +0200
commite4f5cf5565b7742555b1bd4c72616d5ee99af826 (patch)
tree43abb9c1a681250f2f0a59e3e36e5be52e508545 /src/main/java
parent368523b99992687fbef3acb29f915c0b6ada5fd9 (diff)
downloadskyhanni-e4f5cf5565b7742555b1bd4c72616d5ee99af826.tar.gz
skyhanni-e4f5cf5565b7742555b1bd4c72616d5ee99af826.tar.bz2
skyhanni-e4f5cf5565b7742555b1bd4c72616d5ee99af826.zip
code cleanup
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/CopyTabListCommand.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt6
4 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
index c476482cb..62c0a5503 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ScoreboardData.kt
@@ -50,7 +50,7 @@ class ScoreboardData {
var sidebarLines: List<String> = emptyList() // TODO rename to raw
var sidebarLinesRaw: List<String> = emptyList() // TODO delete
- var objectiveLine = ""
+ var objectiveTitle = ""
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
@@ -78,7 +78,7 @@ class ScoreboardData {
private fun fetchScoreboardLines(): List<String> {
val scoreboard = Minecraft.getMinecraft().theWorld?.scoreboard ?: return emptyList()
val objective = scoreboard.getObjectiveInDisplaySlot(1) ?: return emptyList()
- objectiveLine = objective.displayName
+ objectiveTitle = objective.displayName
var scores = scoreboard.getSortedScores(objective)
val list = scores.filter { input: Score? ->
input != null && input.playerName != null && !input.playerName.startsWith("#")
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt
index 0483001f8..212350fdb 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyScoreboardCommand.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.test.command
import at.hannibal2.skyhanni.data.ScoreboardData
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -9,12 +10,12 @@ object CopyScoreboardCommand {
fun command(args: Array<String>) {
val resultList = mutableListOf<String>()
val noColor = args.size == 1 && args[0] == "true"
- resultList.add("Header:")
- resultList.add(if (noColor) ScoreboardData.objectiveLine.removeColor() else ScoreboardData.objectiveLine)
+ resultList.add("Title:")
+ resultList.add(ScoreboardData.objectiveTitle.transformIf(noColor) { removeColor() })
resultList.add("")
for (line in ScoreboardData.sidebarLinesFormatted) {
- val scoreboardLine = if (noColor) line.removeColor() else line
+ val scoreboardLine = line.transformIf(noColor) { removeColor() }
resultList.add("'$scoreboardLine'")
}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyTabListCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyTabListCommand.kt
index d308ba09e..9a745cc11 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyTabListCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyTabListCommand.kt
@@ -2,6 +2,8 @@ package at.hannibal2.skyhanni.test.command
import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiPlayerTabOverlay
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.conditionalTransform
+import at.hannibal2.skyhanni.utils.LorenzUtils.transformIf
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
@@ -12,12 +14,12 @@ object CopyTabListCommand {
val resultList = mutableListOf<String>()
val noColor = args.size == 1 && args[0] == "true"
for (line in TabListData.getTabList()) {
- val tabListLine = if (noColor) line.removeColor() else line
+ val tabListLine = line.transformIf(noColor) { removeColor() }
if (tabListLine != "") resultList.add("'$tabListLine'")
}
val tabList = Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay
- val tabHeader = if (noColor) tabList.header_skyhanni.unformattedText else tabList.header_skyhanni.formattedText
- val tabFooter = if (noColor) tabList.footer_skyhanni.unformattedText else tabList.footer_skyhanni.formattedText
+ val tabHeader = tabList.header_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText })
+ val tabFooter = tabList.footer_skyhanni.conditionalTransform(noColor, { unformattedText }, { formattedText })
val string = "Header:\n\n$tabHeader\n\nBody:\n\n${resultList.joinToString("\n")}\n\nFooter:\n\n$tabFooter"
OSUtils.copyToClipboard(string)
LorenzUtils.chat("§e[SkyHanni] Tab list copied into the clipboard!")
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index a96937b88..8bf8041a2 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -533,4 +533,10 @@ object LorenzUtils {
}
val JsonPrimitive.asIntOrNull get() = takeIf { it.isNumber }?.asInt
+
+ fun <T> T.transformIf(condition: Boolean, transofmration: T.() -> T) =
+ if (condition) transofmration(this) else this
+
+ fun <T> T.conditionalTransform(condition: Boolean, ifTrue: T.() -> Any, ifFalse: T.() -> Any) =
+ if (condition) ifTrue(this) else ifFalse(this)
}