aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-11-19 17:16:17 +0100
committerGitHub <noreply@github.com>2023-11-19 17:16:17 +0100
commit21344b74bf0877083b345c5650766b5b7997cc76 (patch)
tree665b7c36c8a8911bcf3d759598742477d03c55b7 /src/main/java/at
parent5fdd4440016850804ef34057970be6788c27f3e0 (diff)
downloadskyhanni-21344b74bf0877083b345c5650766b5b7997cc76.tar.gz
skyhanni-21344b74bf0877083b345c5650766b5b7997cc76.tar.bz2
skyhanni-21344b74bf0877083b345c5650766b5b7997cc76.zip
share new crop data (#718)
Added wrong crop milestone step detection. #718
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesFix.kt160
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt6
5 files changed, 180 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index a84c86c4f..096078cf5 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigFileType
import at.hannibal2.skyhanni.config.ConfigGuiManager
import at.hannibal2.skyhanni.data.ChatManager
+import at.hannibal2.skyhanni.data.GardenCropMilestonesFix
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.PartyAPI
import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay
@@ -314,6 +315,10 @@ object Commands {
"shconfigmanagerreset",
"Reloads the config manager and rendering processors of MoulConfig. This §cWILL RESET §7your config, but also updating the java config files (names, description, orderings and stuff)."
) { SkyHanniDebugsAndTests.configManagerResetCommand(it) }
+ registerCommand(
+ "readcropmilestonefromclipboard",
+ "Read crop milestone from clipboard. This helps fixing wrong crop milestone data"
+ ) { GardenCropMilestonesFix.readDataFromClipboard() }
}
private fun internalCommands() {
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
index 65a416dca..7553f2f2a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/GardenConfig.java
@@ -202,4 +202,10 @@ public class GardenConfig {
@ConfigEditorBoolean
@FeatureToggle
public boolean plotBorders = true;
+
+ @Expose
+ @ConfigOption(name = "Copy Milestone Data", desc = "Copy wrong crop milestone data in clipboard when opening the crop milestone menu. Please share this data in SkyHanni discord.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean copyMilestoneData = true;
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
index a98f02fba..d810121ed 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestones.kt
@@ -6,6 +6,7 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.jsonobjects.GardenJson
import net.minecraft.item.ItemStack
@@ -14,7 +15,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object GardenCropMilestones {
// TODO USE SH-REPO
private val cropPattern = "§7Harvest §f(?<name>.*) §7on .*".toPattern()
- private val totalPattern = "§7Total: §a(?<name>.*)".toPattern()
+ val totalPattern = "§7Total: §a(?<name>.*)".toPattern()
fun getCropTypeByLore(itemStack: ItemStack): CropType? {
for (line in itemStack.getLore()) {
@@ -34,15 +35,16 @@ object GardenCropMilestones {
val crop = getCropTypeByLore(stack) ?: continue
for (line in stack.getLore()) {
totalPattern.matchMatcher(line) {
- val amount = group("name").replace(",", "").toLong()
+ val amount = group("name").formatNumber()
crop.setCounter(amount)
}
}
}
CropMilestoneUpdateEvent().postAndCatch()
+ GardenCropMilestonesFix.openInventory(event.inventoryItems)
}
- private var cropMilestoneData: Map<CropType, List<Int>> = emptyMap()
+ var cropMilestoneData: Map<CropType, List<Int>> = emptyMap()
val cropCounter: MutableMap<CropType, Long>? get() = GardenAPI.storage?.cropCounter
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesFix.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesFix.kt
new file mode 100644
index 000000000..1e3a27ebc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenCropMilestonesFix.kt
@@ -0,0 +1,160 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.ConfigManager
+import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
+import at.hannibal2.skyhanni.features.garden.CropType
+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.LorenzUtils.editCopy
+import at.hannibal2.skyhanni.utils.LorenzUtils.nextAfter
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
+import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
+import at.hannibal2.skyhanni.utils.OSUtils
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import kotlinx.coroutines.launch
+import net.minecraft.item.ItemStack
+
+object GardenCropMilestonesFix {
+ private val pattern = ".*§e(?<having>.*)§6/§e(?<max>.*)".toPattern()
+
+ fun openInventory(inventoryItems: Map<Int, ItemStack>) {
+ if (SkyHanniMod.feature.garden.copyMilestoneData) {
+ fixForWrongData(inventoryItems)
+ }
+ }
+
+ private fun fixForWrongData(inventoryItems: Map<Int, ItemStack>) {
+ val data = mutableListOf<String>()
+ for ((_, stack) in inventoryItems) {
+ val crop = GardenCropMilestones.getCropTypeByLore(stack) ?: continue
+ checkForWrongData(stack, crop, data)
+
+ CropMilestoneUpdateEvent().postAndCatch()
+ }
+
+ if (data.isNotEmpty()) {
+ LorenzUtils.chat(
+ "Found §c${data.size} §ewrong crop milestone steps in the menu! " +
+ "Correct data got put into clipboard. " +
+ "Please share it on SkyHanni Discord."
+ )
+ OSUtils.copyToClipboard("```${data.joinToString("\n")}```")
+ } else {
+ LorenzUtils.chat("No wrong crop milestone steps found!")
+ }
+ }
+
+ private fun checkForWrongData(
+ stack: ItemStack,
+ crop: CropType,
+ wrongData: MutableList<String>
+ ) {
+ val name = stack.name ?: return
+ val rawNumber = name.removeColor().replace(crop.cropName, "").trim()
+ val realTier = if (rawNumber == "") 0 else rawNumber.romanToDecimalIfNeeded()
+
+ val lore = stack.getLore()
+ val next = lore.nextAfter({ GardenCropMilestones.totalPattern.matches(it) }, 3) ?: return
+ val total = lore.nextAfter({ GardenCropMilestones.totalPattern.matches(it) }, 6) ?: return
+
+ debug(" ")
+ debug("crop: $crop")
+ debug("realTier: $realTier")
+
+ val guessNextMax = GardenCropMilestones.getCropsForTier(
+ realTier + 1,
+ crop
+ ) - GardenCropMilestones.getCropsForTier(realTier, crop)
+ debug("guessNextMax: ${guessNextMax.addSeparators()}")
+ val nextMax = pattern.matchMatcher(next) {
+ group("max").formatNumber()
+ } ?: return
+ debug("nextMax real: ${nextMax.addSeparators()}")
+ if (nextMax != guessNextMax) {
+ debug("wrong, add to list")
+ wrongData.add("$crop:$realTier:${nextMax.addSeparators()}")
+ }
+
+ val guessTotalMax = GardenCropMilestones.getCropsForTier(46, crop)
+ // println("guessTotalMax: ${guessTotalMax.addSeparators()}")
+ val totalMax = pattern.matchMatcher(total) {
+ group("max").formatNumber()
+ } ?: return
+ // println("totalMax real: ${totalMax.addSeparators()}")
+ val totalOffBy = guessTotalMax - totalMax
+ debug("totalOffBy: $totalOffBy")
+ }
+
+ fun debug(message: String) {
+ if (SkyHanniMod.feature.dev.debug.enabled) {
+// println(message)
+ }
+ }
+
+ /**
+ *
+ * This helps to fix wrong crop milestone data
+ * This command reads the clipboard content,
+ * in the format of users sending crop milestone step data.
+ *
+ * The new data will be compared to the currently saved data,
+ * differences are getting replaced, and the result gets put into the clipboard.
+ * The clipboard context can be used to update the repo content.
+ */
+ fun readDataFromClipboard() {
+ SkyHanniMod.coroutineScope.launch {
+ OSUtils.readFromClipboard()?.let {
+ handleInput(it)
+ }
+ }
+ }
+
+ private var totalFixedValues = 0
+
+ private fun handleInput(input: String) {
+ println(" ")
+ var fixed = 0
+ var alreadyCorrect = 0
+ for (line in input.lines()) {
+ val split = line.replace("```", "").replace(".", ",").split(":")
+ if (split.size != 3) continue
+ val (rawCrop, tier, amount) = split
+ val crop = LorenzUtils.enumValueOf<CropType>(rawCrop)
+
+ if (tryFix(crop, tier.toInt(), amount.formatNumber().toInt())) {
+ fixed++
+ } else {
+ alreadyCorrect++
+ }
+ }
+ totalFixedValues += fixed
+ LorenzUtils.chat("Fixed: $fixed/$alreadyCorrect, total fixes: $totalFixedValues")
+ val s = ConfigManager.gson.toJsonTree(GardenCropMilestones.cropMilestoneData).toString()
+ OSUtils.copyToClipboard("\"crop_milestones\":$s,")
+ }
+
+ private fun tryFix(crop: CropType, tier: Int, amount: Int): Boolean {
+ val guessNextMax = GardenCropMilestones.getCropsForTier(tier + 1, crop) - GardenCropMilestones.getCropsForTier(
+ tier,
+ crop
+ )
+ if (guessNextMax.toInt() == amount) {
+ return false
+ }
+ GardenCropMilestones.cropMilestoneData = GardenCropMilestones.cropMilestoneData.editCopy {
+ fix(crop, this, tier, amount)
+ }
+ return true
+ }
+
+ private fun fix(crop: CropType, map: MutableMap<CropType, List<Int>>, tier: Int, amount: Int) {
+ map[crop] = map[crop]!!.editCopy {
+ this[tier] = amount
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 52175ec56..90970a315 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -489,10 +489,12 @@ object LorenzUtils {
}
}
- fun List<String>.nextAfter(after: String, skip: Int = 1): String? {
+ fun List<String>.nextAfter(after: String, skip: Int = 1) = nextAfter({ it == after}, skip)
+
+ fun List<String>.nextAfter(after: (String) -> Boolean, skip: Int = 1): String? {
var missing = -1
for (line in this) {
- if (line == after) {
+ if (after(line)) {
missing = skip - 1
continue
}