summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bazaar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt19
2 files changed, 15 insertions, 19 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
index e3f50ad0b..3fce3b4d3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
@@ -6,15 +6,16 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
class BazaarCancelledBuyOrderClipboard {
- private val patternLastAmount = Pattern.compile("§a(.*)§7x")
+ private val patternLastAmount = Pattern.compile("§a(?<amount>.*)§7x")
private val patternCancelledMessage =
- "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(.*) coins §r§7from cancelling Buy Order!".toPattern()
+ "§6\\[Bazaar] §r§7§r§cCancelled! §r§7Refunded §r§6(?<coins>.*) coins §r§7from cancelling Buy Order!".toPattern()
private var latestAmount: String? = null
@@ -29,7 +30,7 @@ class BazaarCancelledBuyOrderClipboard {
for (line in stack.getLore()) {
val matcher = patternLastAmount.matcher(line)
if (matcher.find()) {
- latestAmount = matcher.group(1)
+ latestAmount = matcher.group("amount")
}
}
}
@@ -38,13 +39,9 @@ class BazaarCancelledBuyOrderClipboard {
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
- val message = event.message
-
- val matcher = patternCancelledMessage.matcher(message)
- if (matcher.matches()) {
+ patternCancelledMessage.matchMatcher(event.message) {
event.blockedReason = "bazaar cancelled buy order clipbaord"
- val coins = matcher.group(1)
-
+ val coins = group("coins")
LorenzUtils.chat("§e[SkyHanni] Bazaar buy order cancelled. $latestAmount saved to clipboard. ($coins coins)")
latestAmount?.let { OSUtils.copyToClipboard(it.replace(",", "")) }
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
index 1e00d8c22..fa0dd8187 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.Slot
@@ -43,13 +44,12 @@ class BazaarOrderHelper {
if (slot.stack == null) continue
val itemName = slot.stack.name ?: continue
- val matcher = bazaarItemNamePattern.matcher(itemName)
- if (!matcher.matches()) continue
+ bazaarItemNamePattern.matchMatcher(itemName) {
+ val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") }
+ if (buyOrSell.let { !it.first && !it.second }) return
- val buyOrSell = matcher.group("type").let { (it == "BUY") to (it == "SELL") }
- if (buyOrSell.let { !it.first && !it.second }) continue
-
- highlightItem(matcher.group("name"), slot, buyOrSell)
+ highlightItem(group("name"), slot, buyOrSell)
+ }
}
}
@@ -62,14 +62,13 @@ class BazaarOrderHelper {
val itemLore = slot.stack.getLore()
for (line in itemLore) {
- if (filledPattern.matcher(line).matches()) {
+ filledPattern.matchMatcher(line) {
slot highlight LorenzColor.GREEN
return
}
- val matcher = pricePattern.matcher(line)
- if (matcher.matches()) {
- val price = matcher.group("number").replace(",", "").toDouble()
+ pricePattern.matchMatcher(line) {
+ val price = group("number").replace(",", "").toDouble()
if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) {
slot highlight LorenzColor.GOLD
return