diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-09 12:12:27 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-08-09 12:12:27 +0200 |
commit | 17ec026c19d1e203244217d599f72bd265d9aac8 (patch) | |
tree | 28c86ae9415e11ec316741ba752a7e807a10f74c /src/main | |
parent | 3bcd5b3a8afa5b322d75af1b82681fd7b1e494e5 (diff) | |
download | skyhanni-17ec026c19d1e203244217d599f72bd265d9aac8.tar.gz skyhanni-17ec026c19d1e203244217d599f72bd265d9aac8.tar.bz2 skyhanni-17ec026c19d1e203244217d599f72bd265d9aac8.zip |
Using NEUInternalName in slayer profit tracker
Diffstat (limited to 'src/main')
8 files changed, 58 insertions, 51 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index 9e0cad6c0..8fd1b4cb5 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -29,7 +30,7 @@ class CollectionAPI { val internalName = NEUItems.transHypixelNameToInternalName(hypixelId) // MUSHROOM_COLLECTION, - NEUItems.getItemStackOrNull(internalName)?.displayName ?: continue + internalName.getItemStackOrNull()?.displayName ?: continue collectionValue[internalName] = counter } diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 7eeffb9a4..1e1ec683a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems import com.google.gson.GsonBuilder import com.google.gson.TypeAdapter @@ -65,6 +66,15 @@ class ConfigManager { return NEUItems.loadNBTData(reader.nextString()) } }.nullSafe()) + .registerTypeAdapter(NEUInternalName::class.java, object : TypeAdapter<NEUInternalName>() { + override fun write(out: JsonWriter, value: NEUInternalName) { + out.value(value.asString()) + } + + override fun read(reader: JsonReader): NEUInternalName { + return NEUInternalName.from(reader.nextString()) + } + }.nullSafe()) .enableComplexMapKeySerialization() .create() } diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index 080b77ce8..f5e6bdce2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -11,14 +11,11 @@ import at.hannibal2.skyhanni.features.misc.FrozenTreasure; import at.hannibal2.skyhanni.features.misc.ghostcounter.GhostData; import at.hannibal2.skyhanni.features.rift.area.westvillage.KloonTerminal; import at.hannibal2.skyhanni.utils.LorenzVec; +import at.hannibal2.skyhanni.utils.NEUInternalName; import com.google.gson.annotations.Expose; import net.minecraft.item.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class Storage { @@ -297,7 +294,7 @@ public class Storage { public static class SlayerProfitList { @Expose - public Map<String, SlayerItemProfit> items = new HashMap<>(); + public Map<NEUInternalName, SlayerItemProfit> items = new HashMap<>(); @Expose public long mobKillCoins = 0; @@ -310,7 +307,7 @@ public class Storage { public static class SlayerItemProfit { @Expose - public String internalName; + public NEUInternalName internalName; @Expose public long timesDropped; @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt index 6b8af2941..097eb2dec 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt @@ -1,13 +1,15 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.* -import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.features.slayer.SlayerType -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.nextAfter -import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.common.cache.CacheBuilder @@ -18,7 +20,8 @@ import java.util.concurrent.TimeUnit object SlayerAPI { private var nameCache = - CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build<Pair<String, Int>, Pair<String, Double>>() + CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES) + .build<Pair<NEUInternalName, Int>, Pair<String, Double>>() var questStartTime = 0L var isInSlayerArea = false @@ -53,7 +56,7 @@ object SlayerAPI { } fun getItemNameAndPrice(stack: ItemStack): Pair<String, Double> { - val internalName = stack.getInternalName() + val internalName = stack.getInternalName_new() val amount = stack.stackSize val key = internalName to amount nameCache.getIfPresent(key)?.let { @@ -63,8 +66,8 @@ object SlayerAPI { val amountFormat = if (amount != 1) "§7${amount}x §r" else "" val displayName = getNameWithEnchantmentFor(internalName) - val price = NEUItems.getPrice(internalName) - val npcPrice = BazaarApi.getBazaarDataByInternalName(internalName)?.npcPrice ?: 0.0 + val price = internalName.getPrice() + val npcPrice = internalName.getBazaarData()?.npcPrice ?: 0.0 val maxPrice = npcPrice.coerceAtLeast(price) val totalPrice = maxPrice * amount @@ -76,11 +79,11 @@ object SlayerAPI { return result } - fun getNameWithEnchantmentFor(internalName: String): String? { - if (internalName == "WISP_POTION") { + fun getNameWithEnchantmentFor(internalName: NEUInternalName): String? { + if (internalName.asString() == "WISP_POTION") { return "§fWisp's Ice-Flavored Water" } - return NEUItems.getItemStack(internalName).nameWithEnchantment + return internalName.getItemStack().nameWithEnchantment } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index b0c08a4e8..b40bb81b2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -25,17 +25,15 @@ class BazaarApi { NEUItems.getInternalNameOrNull(name)?.let { getBazaarDataByInternalName(it) } fun getBazaarDataByInternalName(internalName: String) = - getBazaarDataByInternalName_new(NEUInternalName.from(internalName)) + NEUInternalName.from(internalName).getBazaarData() - fun getBazaarDataByInternalName_new(internalName: NEUInternalName) = if (isBazaarItem(internalName)) { - holder.getData(internalName) + fun NEUInternalName.getBazaarData() = if (isBazaarItem()) { + holder.getData(this) } else null fun isBazaarItem(stack: ItemStack) = isBazaarItem(stack.getInternalName()) - fun isBazaarItem(internalName: NEUInternalName): Boolean { - return NEUItems.manager.auctionManager.getBazaarInfo(internalName.asString()) != null - } + fun NEUInternalName.isBazaarItem() = NEUItems.manager.auctionManager.getBazaarInfo(asString()) != null fun isBazaarItem(internalName: String): Boolean { return NEUItems.manager.auctionManager.getBazaarInfo(internalName) != null diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt index af01ca68b..741a1a089 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt @@ -10,6 +10,8 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft @@ -62,7 +64,7 @@ class CollectionTracker { return } - val stack = NEUItems.getItemStackOrNull(foundInternalName) + val stack = foundInternalName.getItemStackOrNull() if (stack == null) { LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") return @@ -129,7 +131,7 @@ class CollectionTracker { display = Collections.singletonList(buildList { internalName?.let { - add(NEUItems.getItemStack(it)) + add(it.getItemStack()) } add("$itemName collection: §e$format $gainText") }) @@ -141,7 +143,7 @@ class CollectionTracker { fun handleTabComplete(command: String): List<String>? { if (command != "shtrackcollection") return null - return CollectionAPI.collectionValue.keys.mapNotNull { NEUItems.getItemStackOrNull(it) } + return CollectionAPI.collectionValue.keys.mapNotNull { it.getItemStackOrNull() } .map { it.displayName.removeColor().replace(" ", "_") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt index 581761831..d67390349 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -6,15 +6,16 @@ import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.SlayerAPI import at.hannibal2.skyhanni.data.TitleUtils import at.hannibal2.skyhanni.events.* -import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.features.bazaar.BazaarData import at.hannibal2.skyhanni.test.PriceSource import at.hannibal2.skyhanni.utils.* -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull_new import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -80,7 +81,7 @@ object SlayerItemProfitTracker { update() } - private fun addItemPickup(internalName: String, stackSize: Int) { + private fun addItemPickup(internalName: NEUInternalName, stackSize: Int) { val itemLog = currentLog() ?: return itemLog.modify { @@ -134,8 +135,7 @@ object SlayerItemProfitTracker { val itemStack = item.entityItem val name = itemStack.name ?: return if (SlayerAPI.ignoreSlayerDrop(name)) return - val internalName = itemStack.getInternalName() - if (internalName == "") return + val internalName = itemStack.getInternalNameOrNull_new() ?: return val (itemName, price) = SlayerAPI.getItemNameAndPrice(itemStack) addItemPickup(internalName, itemStack.stackSize) @@ -180,7 +180,7 @@ object SlayerItemProfitTracker { val price = (getPrice(internalName) * amount).toLong() - val cleanName = SlayerAPI.getNameWithEnchantmentFor(internalName) ?: internalName + val cleanName = SlayerAPI.getNameWithEnchantmentFor(internalName) ?: internalName.asString() var name = cleanName val priceFormat = NumberUtil.format(price) val hidden = itemProfit.hidden @@ -298,18 +298,14 @@ object SlayerItemProfitTracker { list.slayerCompletedCount = 0 } - private fun getPrice(internalName: String): Double { - val bazaarData = BazaarApi.getBazaarDataByInternalName(internalName) - return bazaarData?.let { getPrice(it) } ?: NEUItems.getPrice(internalName) - } + private fun getPrice(internalName: NEUInternalName) = + internalName.getBazaarData()?.let { getPrice(it) } ?: internalName.getPrice() - private fun getPrice(bazaarData: BazaarData): Double { - return when (config.priceFrom) { - 0 -> bazaarData.sellPrice - 1 -> bazaarData.buyPrice + private fun getPrice(bazaarData: BazaarData) = when (config.priceFrom) { + 0 -> bazaarData.sellPrice + 1 -> bazaarData.buyPrice - else -> bazaarData.npcPrice - } + else -> bazaarData.npcPrice } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 4c18c7f94..75f9d1562 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -172,25 +172,25 @@ object NEUItems { fun getPrice(internalName: String, useSellingPrice: Boolean = false) = NEUInternalName.from(internalName).getPrice(useSellingPrice) - fun getItemStackOrNull(internalName: NEUInternalName) = ItemResolutionQuery(manager) - .withKnownInternalName(internalName.asString()) + fun NEUInternalName.getItemStackOrNull() = ItemResolutionQuery(manager) + .withKnownInternalName(asString()) .resolveToItemStack()?.copy() - fun getItemStackOrNull(internalName: String) = getItemStackOrNull(NEUInternalName.from(internalName)) + fun getItemStackOrNull(internalName: String) = NEUInternalName.from(internalName).getItemStackOrNull() fun getItemStack(internalName: String, definite: Boolean = false): ItemStack = - getItemStack(NEUInternalName.from(internalName), definite) + NEUInternalName.from(internalName).getItemStack(definite) - fun getItemStack(internalName: NEUInternalName, definite: Boolean = false): ItemStack = - getItemStackOrNull(internalName) ?: run { - if (internalName.getPrice() == -1.0) return@run fallbackItem + fun NEUInternalName.getItemStack(definite: Boolean = false): ItemStack = + getItemStackOrNull() ?: run { + if (getPrice() == -1.0) return@run fallbackItem if (definite) { Utils.showOutdatedRepoNotification() } CopyErrorCommand.logError( IllegalStateException("Something went wrong!"), - "Encountered an error getting the item for §7$internalName§c. " + + "Encountered an error getting the item for §7$this§c. " + "This may be because your NEU repo is outdated. Please ask in the SkyHanni " + "Discord if this is the case" ) |