All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.chestmc.common.extensions.Bars.kt Maven / Gradle / Ivy

package net.chestmc.common.extensions

import net.chestmc.common.extensions.numbers.percentage
import net.chestmc.common.extensions.numbers.round
import org.bukkit.ChatColor

/**
 * Create a new progress bar with the specified amount value, max, symbol and amount.
 */
fun createBar(value: Number, max: Number, symbol: String = "︱", amount: Int = 10): String {
  val percentage = percentage(value, max)

  // evict +100% error
  if (percentage > 100)
    return createBar(max, max, symbol, amount)

  val completedAmount = amount * percentage.toInt() / 100
  val completed = "§a" + symbol.repeat(completedAmount)
  val uncompleted = "§7" + symbol.repeat(amount - completedAmount)

  return "$completed$uncompleted §7(${percentage.round(2)}%)"
}

/**
 * Create a new progress bar with the specified amount value, max, symbol,
 * amount, incomplete color, complete color and percentage color.
 */
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 = "§a" + "$complete$symbol".repeat(completedAmount)
  val uncompleted = "§7" + "$incomplete$symbol".repeat(amount - completedAmount)

  return "$completed$uncompleted $percentageColor(${percentage.round(2)}%)"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy