Improve code style

This commit is contained in:
Jakob K
2021-05-12 14:17:44 +02:00
parent 3e9b243d3d
commit cf48510756
69 changed files with 144 additions and 609 deletions

View File

@@ -15,7 +15,6 @@ import org.bukkit.inventory.meta.ItemMeta
* aswell.
*/
data class CustomItemIdentifier(val customModelData: Int, val placeHolderMaterial: Material) {
constructor(itemStack: ItemStack) :
this(
kotlin.run {
@@ -38,5 +37,4 @@ data class CustomItemIdentifier(val customModelData: Int, val placeHolderMateria
itemStack
} else null
}
}

View File

@@ -8,20 +8,15 @@ import net.md_5.bungee.api.ChatColor
* can be used for minecraft lorelists.
*/
fun String.toLoreList(vararg lineColors: ChatColor = arrayOf(KColors.RESET), lineLength: Int = 40): List<String> {
val lineColor = lineColors.joinToString(separator = "")
val loreList = ArrayList<String>()
val lineBuilder = StringBuilder()
fun submitLine() {
loreList += "$lineColor$lineBuilder"
lineBuilder.clear()
}
fun addWord(word: String) {
if (lineBuilder.lengthWithoutMinecraftColour + word.lengthWithoutMinecraftColour > lineLength)
submitLine()
@@ -29,7 +24,6 @@ fun String.toLoreList(vararg lineColors: ChatColor = arrayOf(KColors.RESET), lin
lineBuilder.append(" ")
lineBuilder.append(word)
}
split(" ").forEach { addWord(it) }
@@ -38,38 +32,33 @@ fun String.toLoreList(vararg lineColors: ChatColor = arrayOf(KColors.RESET), lin
submitLine()
return loreList
}
/**
* Returns the length of this sequence, ignoring
* all minecraft colour codes.
*/
val CharSequence.lengthWithoutMinecraftColour: Int get() {
val CharSequence.lengthWithoutMinecraftColour: Int
get() {
var count = 0
var isPreviousColourCode = false
var count = 0
this.forEachIndexed { index, char ->
if (isPreviousColourCode) {
isPreviousColourCode = false
return@forEachIndexed
}
var isPreviousColourCode = false
this.forEachIndexed { index, char ->
if (isPreviousColourCode) {
isPreviousColourCode = false
return@forEachIndexed
if (char == '§') {
if (lastIndex >= index + 1) {
val nextChar = this[index + 1]
if (nextChar.isLetter() || nextChar.isDigit())
isPreviousColourCode = true
else
count++
}
} else count++
}
if (char == '§') {
if (lastIndex >= index + 1) {
val nextChar = this[index + 1]
if (nextChar.isLetter() || nextChar.isDigit())
isPreviousColourCode = true
else
count++
}
} else count++
}
return count
}
return count
}

View File

@@ -9,16 +9,12 @@ import org.bukkit.inventory.meta.ItemMeta
/*
ITEM STACK
*/
// creation
/**
* Creates a new [ItemStack] and opens a builder for it.
*/
inline fun itemStack(material: Material, builder: ItemStack.() -> Unit) = ItemStack(material).apply(builder)
// extensions
/**
* Opens a builder with the current meta.
* @param T the specific type of the meta
@@ -48,13 +44,10 @@ inline fun <reified T : ItemMeta> ItemStack.setMeta(builder: T.() -> Unit) {
/** @see setMeta */
@JvmName("simpleSetMeta")
inline fun ItemStack.setMeta(builder: ItemMeta.() -> Unit) = setMeta<ItemMeta>(builder)
/*
ITEM META
*/
// creation
/**
* Creates new a [ItemMeta] instance of the given material and opens a builder for it.
* @param T the specific type of the meta
@@ -67,9 +60,7 @@ inline fun <reified T : ItemMeta> itemMeta(material: Material, builder: T.() ->
/** @see itemMeta */
@JvmName("simpleItemMeta")
inline fun itemMeta(material: Material, builder: ItemMeta.() -> Unit) = itemMeta<ItemMeta>(material, builder)
// extensions
/**
* Sets the lore (description) of the item.
*/