aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-16 20:16:20 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-16 20:16:20 +0200
commit4f4838404ad1aa90d35d3059f1d012c0cd7c9a07 (patch)
tree0d47a3662ee2df4c153aba98d2f4a3c391c08a2f /src
parentd82f1a825da599650ee2b6aab84a97e90abf4745 (diff)
downloadskyhanni-4f4838404ad1aa90d35d3059f1d012c0cd7c9a07.tar.gz
skyhanni-4f4838404ad1aa90d35d3059f1d012c0cd7c9a07.tar.bz2
skyhanni-4f4838404ad1aa90d35d3059f1d012c0cd7c9a07.zip
Using more regex
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt54
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt8
3 files changed, 32 insertions, 31 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 6af2932b3..c5fe44328 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarCancelledBuyOrderClipboard.kt
@@ -45,6 +45,7 @@ class BazaarCancelledBuyOrderClipboard {
event.blockedReason = "bazaar cancelled buy order clipbaord"
val coins = matcher.group(1)
+
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 8c5355920..b28cc1d7b 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt
@@ -10,10 +10,13 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
+import net.minecraft.inventory.Slot
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class BazaarOrderHelper {
private val bazaarItemNamePattern = "§.§l(?<type>BUY|SELL) (?<name>.*)".toPattern()
+ private val filledPattern = "§7Filled: §6.*§7/.* §a§l100%!".toPattern()
+ private val pricePattern = "§7Price per unit: §6(?<number>.*) coins".toPattern()
companion object {
fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) {
@@ -39,39 +42,36 @@ class BazaarOrderHelper {
if (slot.slotNumber != slot.slotIndex) continue
if (slot.stack == null) continue
- val stack = slot.stack
- val itemName = stack.name ?: continue
-
+ val itemName = slot.stack.name ?: continue
val matcher = bazaarItemNamePattern.matcher(itemName)
if (!matcher.matches()) continue
- val (isBuying, isSelling) = matcher.group("type").let { (it == "BUY") to (it == "SELL") }
- if (!isBuying && !isSelling) continue
+ 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)
+ }
+ }
- val bazaarItemName = matcher.group("name")
- val data = BazaarApi.getBazaarDataByName(bazaarItemName)
- if (data == null) {
- LorenzUtils.debug("Bazaar data is null for bazaarItemName '$bazaarItemName'")
- continue
+ private fun highlightItem(itemName: String, slot: Slot, buyOrSell: Pair<Boolean, Boolean>) {
+ val data = BazaarApi.getBazaarDataByName(itemName)
+ if (data == null) {
+ LorenzUtils.debug("Bazaar data is null for bazaarItemName '$itemName'")
+ return
+ }
+
+ val itemLore = slot.stack.getLore()
+ for (line in itemLore) {
+ if (filledPattern.matcher(line).matches()) {
+ slot highlight LorenzColor.GREEN
}
- val itemLore = stack.getLore()
- for (line in itemLore) {
- if (line.startsWith("§7Filled:")) {
- if (line.endsWith(" §a§l100%!")) {
- slot highlight LorenzColor.GREEN
- break
- }
- }
- if (line.startsWith("§7Price per unit:")) {
- var text = line.split(": §6")[1]
- text = text.substring(0, text.length - 6)
- text = text.replace(",", "")
- val price = text.toDouble()
- if (isSelling && price > data.buyPrice || isBuying && price < data.sellPrice) {
- slot highlight LorenzColor.GOLD
- break
- }
+ val matcher = pricePattern.matcher(line)
+ if (matcher.matches()) {
+ val price = matcher.group("number").replace(",", "").toDouble()
+ if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) {
+ slot highlight LorenzColor.GOLD
+ break
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
index 757e03a62..dcb018404 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenTeleportPadInventoryNumber.kt
@@ -57,10 +57,12 @@ class GardenTeleportPadInventoryNumber {
}
private var inTeleportPad = false
+ private val pattern = "§.(.*) teleport pad".toPattern()
@SubscribeEvent
fun onInventoryOpen(event: InventoryOpenEvent) {
- inTeleportPad = event.inventoryName == "Set Destination" && SkyHanniMod.feature.garden.teleportPadsInventoryNumbers
+ inTeleportPad =
+ event.inventoryName == "Set Destination" && SkyHanniMod.feature.garden.teleportPadsInventoryNumbers
}
@SubscribeEvent
@@ -69,12 +71,10 @@ class GardenTeleportPadInventoryNumber {
if (!inTeleportPad) return
val name = event.stack.name?.lowercase() ?: return
- val pattern = "§.(.*) teleport pad".toPattern()
-
val matcher = pattern.matcher(name)
if (!matcher.matches()) return
- val text = matcher.group(1)
+ val text = matcher.group(1)
numbers[text]?.let {
event.stackTip = "$it"
return