walkmc.extensions.Bars.kt Maven / Gradle / Ivy
package walkmc.extensions
import org.bukkit.*
import walkmc.extensions.numbers.*
import walkmc.extensions.strings.*
/**
* Create a new progress bar with the specified amount value, max, symbol,
* amount, incomplete color, complete color and percentage color.
*/
tailrec fun createBar(
value: Number,
max: Number,
symbol: String = "│",
amount: Int = 10,
incomplete: ChatColor = ChatColor.GRAY,
complete: ChatColor = ChatColor.GREEN,
percentageColor: ChatColor = ChatColor.GRAY,
): String {
val percentage = percentage(value, max)
// evict +100% error
if (percentage > 100)
return createBar(max, max, symbol, amount, incomplete, complete, percentageColor)
val completedAmount = amount * percentage.toInt() / 100
val completed = "$complete" + symbol * completedAmount
val uncompleted = "$incomplete" + symbol * (amount - completedAmount)
return "$completed$uncompleted $percentageColor(${percentage.decimals(2)}%)"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy