forked from hannibal002/SkyHanni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/at/hannibal2/skyhanni/features/garden/FarmingMilestoneCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package at.hannibal2.skyhanni.features.garden | ||
|
||
import at.hannibal2.skyhanni.data.GardenCropMilestones | ||
import at.hannibal2.skyhanni.data.GardenCropMilestones.getCounter | ||
import at.hannibal2.skyhanni.utils.LorenzUtils | ||
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators | ||
import net.minecraft.command.CommandBase | ||
|
||
object FarmingMilestoneCommand { | ||
|
||
fun onCommand(crop: String?, current: String?, target: String?) { | ||
if (crop == null) { | ||
LorenzUtils.chat("No crop type entered") | ||
return | ||
} | ||
|
||
val enteredCrop = CropType.entries.firstOrNull { it.simpleName == crop.lowercase() } ?: run { | ||
LorenzUtils.chat("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 cropsNeeded = GardenCropMilestones.getCropsForTier(currentCropMilestone, enteredCrop) - currentProgress | ||
|
||
LorenzUtils.chat("§a${enteredCrop.cropName} needed for you to reach the next milestone ($currentCropMilestone) is ${cropsNeeded.addSeparators()}") | ||
return | ||
} | ||
|
||
if (targetMilestone == null) { | ||
val cropsNeeded = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop) | ||
|
||
LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $currentMilestone is ${cropsNeeded.addSeparators()}") | ||
return | ||
} | ||
if (currentMilestone >= targetMilestone) { | ||
LorenzUtils.chat("Entered milestone is greater than target milestone") | ||
return | ||
} | ||
|
||
val currentAmount = GardenCropMilestones.getCropsForTier(currentMilestone, enteredCrop) | ||
val targetAmount = GardenCropMilestones.getCropsForTier(targetMilestone, enteredCrop) | ||
val cropsNeeded = targetAmount - currentAmount | ||
|
||
LorenzUtils.chat("§a${enteredCrop.cropName} needed to reach milestone $targetMilestone from milestone $currentMilestone is ${cropsNeeded.addSeparators()}") | ||
} | ||
|
||
fun onComplete(strings: Array<String>): List<String> { | ||
if (strings.size <= 1) | ||
return CommandBase.getListOfStringsMatchingLastWord( | ||
strings, | ||
CropType.entries.map { it.simpleName } | ||
) | ||
return listOf() | ||
} | ||
|
||
private fun getValidNumber(entry: String?): Int? { | ||
if (entry == null) return null | ||
var result = try { | ||
entry.toInt() | ||
} catch (_: Exception) { | ||
null | ||
} | ||
if (result == null) return null | ||
|
||
if (result < 0) result = 0 | ||
if (result > 46) result = 46 | ||
|
||
return result | ||
} | ||
} |