From 3aa270c43b368f003c0adf69d0ce161e2e710382 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Sat, 20 Aug 2022 19:06:48 +0200 Subject: fixed BazaarOrderHelper and added essence to bazaar --- .../skyhanni/features/bazaar/BazaarDataGrabber.kt | 31 +++++++++++++++------ .../skyhanni/features/bazaar/BazaarOrderHelper.kt | 32 ++++++++-------------- .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 7 +++++ .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 17 ------------ .../at/hannibal2/skyhanni/utils/StringUtils.kt | 20 ++++++++++++++ 5 files changed, 60 insertions(+), 47 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt index 925ab11fa..eea1138fa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.bazaar import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import kotlin.concurrent.fixedRateTimer internal class BazaarDataGrabber(private var bazaarMap: MutableMap) { @@ -84,19 +85,12 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap price) { - slot highlight LorenzColor.GOLD - continue@out - } + if (isSelling && price > data.buyPrice || isBuying && price < data.sellPrice) { + slot highlight LorenzColor.GOLD + continue@out } - } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index b9b11479f..aafed0994 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -191,4 +191,11 @@ object ItemUtils { return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties") .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value") } + + //extra method for shorter name and kotlin nullability logic + var ItemStack.name: String? + get() = this.displayName + set(value) { + setStackDisplayName(value) + } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index c4bc912ee..04d7bb34a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -58,23 +58,6 @@ object LorenzUtils { fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this) - fun String.removeColor(): String { - val builder = StringBuilder() - var skipNext = false - for (c in this.toCharArray()) { - if (c == '§') { - skipNext = true - continue - } - if (skipNext) { - skipNext = false - continue - } - builder.append(c) - } - - return builder.toString() - } fun SimpleDateFormat.formatCurrentTime(): String = this.format(System.currentTimeMillis()) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt new file mode 100644 index 000000000..a28f6fd2e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -0,0 +1,20 @@ +package at.hannibal2.skyhanni.utils + +object StringUtils { + + fun String.firstLetterUppercase(): String { + if (isEmpty()) return this + + val lowercase = this.lowercase() + val first = lowercase[0].uppercase() + return first + lowercase.substring(1) + } + + fun String.removeColor(): String { + return replace("(?i)\\u00A7.", "") + } + +// fun cleanColour(`in`: String): String? { +// return `in`.replace("(?i)\\u00A7.".toRegex(), "") +// } +} \ No newline at end of file -- cgit