aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt24
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt38
4 files changed, 68 insertions, 28 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
index 612f048de..1a75b4cbc 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
@@ -68,10 +68,9 @@ object ItemUtils {
}
// TODO change else janni is sad
- fun ItemStack.isCoopSoulBound(): Boolean =
- getLore().any {
- it == "§8§l* §8Co-op Soulbound §8§l*" || it == "§8§l* §8Soulbound §8§l*"
- }
+ fun ItemStack.isCoopSoulBound(): Boolean = getLore().any {
+ it == "§8§l* §8Co-op Soulbound §8§l*" || it == "§8§l* §8Soulbound §8§l*"
+ }
// TODO change else janni is sad
fun ItemStack.isSoulBound(): Boolean = getLore().any { it == "§8§l* §8Soulbound §8§l*" }
@@ -82,8 +81,7 @@ object ItemUtils {
fun getItemsInInventory(withCursorItem: Boolean = false): List<ItemStack> {
val list: LinkedList<ItemStack> = LinkedList()
- val player = Minecraft.getMinecraft().thePlayer
- ?: ErrorManager.skyHanniError("getItemsInInventoryWithSlots: player is null!")
+ val player = Minecraft.getMinecraft().thePlayer ?: ErrorManager.skyHanniError("getItemsInInventoryWithSlots: player is null!")
for (slot in player.openContainer.inventorySlots) {
if (slot.hasStack) {
@@ -138,8 +136,8 @@ object ItemUtils {
if (tagCompound == null) return null
val nbt = tagCompound
if (!nbt.hasKey("SkullOwner")) return null
- return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties")
- .getTagList("textures", Constants.NBT.TAG_COMPOUND).getCompoundTagAt(0).getString("Value")
+ return nbt.getCompoundTag("SkullOwner").getCompoundTag("Properties").getTagList("textures", Constants.NBT.TAG_COMPOUND)
+ .getCompoundTagAt(0).getString("Value")
}
fun ItemStack.getSkullOwner(): String? {
@@ -208,8 +206,7 @@ object ItemUtils {
for (line in this.getLore().reversed()) {
val (category, rarity) = UtilsPatterns.rarityLoreLinePattern.matchMatcher(line) {
- group("itemCategory").replace(" ", "_") to
- group("rarity").replace(" ", "_")
+ group("itemCategory").replace(" ", "_") to group("rarity").replace(" ", "_")
} ?: continue
val itemCategory = getItemCategory(category, name, cleanName)
@@ -290,8 +287,7 @@ object ItemUtils {
return data.itemRarity
}
- private fun itemRarityLastCheck(data: CachedItemData) =
- data.itemRarityLastCheck.passedSince() > 10.seconds
+ private fun itemRarityLastCheck(data: CachedItemData) = data.itemRarityLastCheck.passedSince() > 10.seconds
/**
* Use when comparing the name (e.g. regex), not for showing to the user
@@ -391,6 +387,9 @@ object ItemUtils {
val NEUInternalName.itemNameWithoutColor: String get() = itemName.removeColor()
+ val NEUInternalName.readableInternalName: String
+ get() = asString().replace("_", " ").lowercase()
+
private fun NEUInternalName.grabItemName(): String {
if (this == NEUInternalName.WISP_POTION) {
return "§fWisp's Ice-Flavored Water"
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
index 18568869a..6d0eb33e5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull
+
class NEUInternalName private constructor(private val internalName: String) {
companion object {
@@ -20,7 +22,25 @@ class NEUInternalName private constructor(private val internalName: String) {
}
fun fromItemNameOrNull(itemName: String): NEUInternalName? =
- ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet"))
+ ItemNameResolver.getInternalNameOrNull(itemName.removeSuffix(" Pet")) ?: getCoins(itemName)
+
+ fun fromItemNameOrInternalName(itemName: String): NEUInternalName =
+ fromItemNameOrNull(itemName) ?: itemName.asInternalName()
+
+ private fun getCoins(itemName: String): NEUInternalName? = if (isCoins(itemName)) SKYBLOCK_COIN else null
+
+ private fun isCoins(itemName: String): Boolean =
+ itemName.lowercase().let {
+ when (it) {
+ "coin", "coins",
+ "skyblock coin", "skyblock coins",
+ "skyblock_coin", "skyblock_coins",
+ -> true
+
+ else -> false
+ }
+ }
+
fun fromItemName(itemName: String): NEUInternalName = fromItemNameOrNull(itemName) ?: run {
val name = "itemName:$itemName"
@@ -52,4 +72,6 @@ class NEUInternalName private constructor(private val internalName: String) {
fun replace(oldValue: String, newValue: String) =
internalName.replace(oldValue.uppercase(), newValue.uppercase()).asInternalName()
+
+ fun isKnownItem(): Boolean = getItemStackOrNull() != null || this == SKYBLOCK_COIN
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
index 4b871377b..bce63e2d1 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/ItemTrackerData.kt
@@ -24,12 +24,17 @@ abstract class ItemTrackerData : TrackerData() {
resetItems()
}
- fun addItem(internalName: NEUInternalName, stackSize: Int) {
+ fun addItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
val item = items.getOrPut(internalName) { TrackedItem() }
- item.timesGained++
- item.totalAmount += stackSize
+ if (!command) {
+ item.timesGained++
+ }
+ item.totalAmount += amount
item.lastTimeUpdated = SimpleTimeMark.now()
+ if (command && item.totalAmount <= 0) {
+ items.remove(internalName)
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
index 684a7eb00..e7af81cea 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt
@@ -3,11 +3,13 @@ package at.hannibal2.skyhanni.utils.tracker
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage
import at.hannibal2.skyhanni.data.SlayerAPI
+import at.hannibal2.skyhanni.data.TrackerManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.ItemPriceSource
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
+import at.hannibal2.skyhanni.utils.ItemUtils.readableInternalName
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector
@@ -26,23 +28,29 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
) : SkyHanniTracker<Data>(name, createNewSession, getStorage, drawDisplay) {
companion object {
-
val SKYBLOCK_COIN = NEUInternalName.SKYBLOCK_COIN
}
- fun addCoins(coins: Int) {
- addItem(SKYBLOCK_COIN, coins)
- }
-
- fun addItem(internalName: NEUInternalName, amount: Int) {
+ fun addItem(internalName: NEUInternalName, amount: Int, command: Boolean) {
modify {
- it.addItem(internalName, amount)
+ it.addItem(internalName, amount, command)
}
- getSharedTracker()?.let {
- val hidden = it.get(DisplayMode.TOTAL).items[internalName]!!.hidden
- it.get(DisplayMode.SESSION).items[internalName]!!.hidden = hidden
+ getSharedTracker()?.let { sharedData ->
+ sharedData.get(DisplayMode.TOTAL).items[internalName]?.let { data ->
+ sharedData.get(DisplayMode.SESSION).items[internalName]!!.hidden = data.hidden
+ }
}
+ if (command) {
+ TrackerManager.commandEditTrackerSuccess = true
+ val displayName = internalName.itemName
+ if (amount > 0) {
+ ChatUtils.chat("Manually added to $name: §r$displayName §7(${amount}x§7)")
+ } else {
+ ChatUtils.chat("Manually removed from $name: §r$displayName §7(${-amount}x§7)")
+ }
+ return
+ }
// TODO move the function to common
val (itemName, price) = SlayerAPI.getItemNameAndPrice(internalName, amount)
if (config.warnings.chat && price >= config.warnings.minimumChat) {
@@ -62,7 +70,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
onChange = {
config.priceSource = ItemPriceSource.entries[it.ordinal] // todo avoid ordinal
update()
- }
+ },
)
}
}
@@ -140,7 +148,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
}
update()
- }
+ },
) else Renderable.string(displayName)
lists.addAsSingletonList(renderable)
@@ -172,6 +180,12 @@ class SkyHanniItemTracker<Data : ItemTrackerData>(
}
add("§eClick to " + (if (hidden) "show" else "hide") + "!")
add("§eControl + Click to remove this item!")
+
+ add("")
+ add("§7Use §e/shedittracker ${internalName.readableInternalName} <amount>")
+ add("§7to edit the number.")
+ add("§7Use negative numbers to remove items.")
+
if (SkyHanniMod.feature.dev.debug.enabled) {
add("")
add("§7${internalName}")