Added String.toLoreList() function

This commit is contained in:
bluefireoly
2020-10-23 18:12:57 +02:00
parent 6d709d2a64
commit 16005397be

View File

@@ -0,0 +1,36 @@
package net.axay.kspigot.items
import net.axay.kspigot.chat.KColors
import net.md_5.bungee.api.ChatColor
fun String.toLoreList(lineLength: Int = 40, lineColor: ChatColor = KColors.RESET): List<String> {
val loreList = ArrayList<String>()
val lineBuilder = StringBuilder()
fun submitLine() {
loreList += "$lineColor$lineBuilder"
lineBuilder.clear()
}
fun addWord(word: String) {
if (lineBuilder.length + word.length > lineLength)
submitLine()
if (lineBuilder.isNotEmpty())
lineBuilder.append(" ")
lineBuilder.append(word)
}
split(" ").forEach { addWord(it) }
if (lineBuilder.isNotEmpty())
submitLine()
return loreList
}