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
72
73
|
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter
import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.TimeUtils
import net.minecraft.command.CommandBase
object FarmingMilestoneCommand {
fun onCommand(crop: String?, current: String?, target: String?, needsTime: Boolean) {
if (crop == null) {
ChatUtils.userError("No crop type entered")
return
}
val enteredCrop = CropType.entries.firstOrNull { it.simpleName == crop.lowercase() } ?: run {
ChatUtils.userError("Invalid crop type entered")
return
}
val currentMilestone = getValidNumber(current)
val targetMilestone = getValidNumber(target)
if (currentMilestone == null) {
val currentProgress = enteredCrop.getCounter()
val currentCropMilestone = GardenCropMilestones.getTierForCropCount(currentProgress, enteredCrop) + 1
val cropsForTier = GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop)
val output = (cropsForTier - currentProgress).formatOutput(needsTime, enteredCrop)
ChatUtils.chat("§7$output needed to reach the next milestone")
return
}
if (targetMilestone == null) {
val cropsForTier = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop)
val output = cropsForTier.formatOutput(needsTime, enteredCrop)
ChatUtils.chat("§7$output needed for milestone §7$currentMilestone")
return
}
if (currentMilestone >= targetMilestone) {
ChatUtils.userError("Entered milestone is greater than or the same as target milestone")
return
}
val currentAmount = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop)
val targetAmount = GardenCropMilestones.getCropsForTier(targetMilestone, enteredCrop)
val output = (targetAmount - currentAmount).formatOutput(needsTime, enteredCrop)
ChatUtils.chat("§7$output needed for milestone §7$currentMilestone §a-> §7$targetMilestone")
}
fun onComplete(strings: Array<String>): List<String> {
return if (strings.size <= 1) {
CommandBase.getListOfStringsMatchingLastWord(
strings,
CropType.entries.map { it.simpleName }
)
} else listOf()
}
private fun getValidNumber(entry: String?) = entry?.toIntOrNull()?.coerceIn(0, 46)
private fun Long.formatOutput(needsTime: Boolean, crop: CropType): String {
if (!needsTime) return "${this.addSeparators()} §a${crop.cropName}"
val speed = crop.getSpeed() ?: -1
val missingTimeSeconds = this / speed
return "${TimeUtils.formatDuration(missingTimeSeconds * 1000)}§a"
}
}
|