Skip to content

Commit

Permalink
[plugin] add color support to the [item] action (closes #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Jan 4, 2023
1 parent 23d6561 commit b0d12a7
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.bukkit.configuration.ConfigurationSection
import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.LeatherArmorMeta
import java.util.*

class ItemCreator(plugin: ArcaneVouchers) {
Expand Down Expand Up @@ -194,7 +195,8 @@ class ItemCreator(plugin: ArcaneVouchers) {
return null
}

val builder = ItemBuilder.from(parseBaseItem(tokenizer.nextToken().uppercase(), tokenizer.nextToken()) ?: return null)
val baseItem = parseBaseItem(tokenizer.nextToken().uppercase(), tokenizer.nextToken()) ?: return null
val builder = ItemBuilder.from(baseItem)

while (tokenizer.hasMoreTokens()) {
val parts = tokenizer.nextToken().split(Constant.Separator.COLON, 2)
Expand Down Expand Up @@ -222,6 +224,18 @@ class ItemCreator(plugin: ArcaneVouchers) {

"model" -> value.toIntOrNull()?.let { builder.model(it) }

"color" -> {
if (!baseItem.hasItemMeta()) {
continue
}

val meta = baseItem.itemMeta ?: continue

if (meta is LeatherArmorMeta) {
meta.setColor(value.toColor())
}
}

"nbt" -> {
// Take everything that's after 'nbt:'
val sNbt = string.substringAfter("$key:")
Expand Down

0 comments on commit b0d12a7

Please sign in to comment.