blob: 4bf34a5ae6fcfb93c2a0e87b1ed8b155fb2f8685 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay
import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.sorted
import at.hannibal2.skyhanni.utils.ItemUtils.getItemName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeUtils
object GardenCropsInCommand {
private val config get() = GardenAPI.config.moneyPerHours
fun onCommand(args: Array<String>) {
if (!config.display) {
ChatUtils.userError("shcropsin requires 'Show money per Hour' feature to be enabled to work!")
return
}
if (args.size < 2) {
ChatUtils.userError("Usage: /shcropsin <time> <item>")
return
}
val rawTime = args[0]
val seconds = try {
TimeUtils.getDuration(rawTime).inWholeSeconds
} catch (e: NumberFormatException) {
ChatUtils.userError("Not a valid time: '$rawTime'")
return
}
val multipliers = CropMoneyDisplay.multipliers
if (multipliers.isEmpty()) {
ChatUtils.userError("Data not loaded yet. Join the garden and display the money per hour display.")
return
}
val rawSearchName = args.toMutableList().drop(1).joinToString(" ")
val searchName = rawSearchName.lowercase()
val map = mutableMapOf<String, Long>()
for (entry in multipliers) {
val internalName = entry.key
val itemName = internalName.getItemName()
if (itemName.removeColor().lowercase().contains(searchName)) {
val (baseId, baseAmount) = NEUItems.getMultiplier(internalName)
val baseName = baseId.getItemName()
val crop = CropType.getByName(baseName.removeColor())
val speed = crop.getSpeed()
if (speed == null) {
map["$itemName §cNo speed data!"] = -1
} else {
val fullAmount = seconds * speed / baseAmount
map["$itemName §b${fullAmount.addSeparators()}x"] = fullAmount
}
}
}
if (map.isEmpty()) {
ChatUtils.userError("No crops found for '$rawSearchName'")
return
}
ChatUtils.chat("Crops farmed in $rawTime:\n" + map.sorted().keys.joinToString("\n"))
}
}
|