Skip to content

Commit

Permalink
feat: add ItemMeta#asColorable
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 6, 2024
1 parent 39193ad commit d803553
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.mineinabyss.idofront.items

import org.bukkit.Color
import org.bukkit.inventory.meta.FireworkEffectMeta
import org.bukkit.inventory.meta.ItemMeta
import org.bukkit.inventory.meta.LeatherArmorMeta
import org.bukkit.inventory.meta.MapMeta
import org.bukkit.inventory.meta.PotionMeta

interface Colorable {
var color: Color?
}

/**
* These different ItemMeta classes don't share a common color property so we use this :(
*/
fun ItemMeta.asColorable(): Colorable? {
return when (val meta = this) {
is LeatherArmorMeta -> object : Colorable {
override var color: Color?
get() = meta.color
set(value) {
meta.setColor(value)
}
}

is PotionMeta -> object : Colorable {
override var color: Color?
get() = meta.color
set(value) {
meta.color = value
}
}

is MapMeta -> object : Colorable {
override var color: Color?
get() = meta.color
set(value) {
meta.color = value
}
}

else -> null
}
}

0 comments on commit d803553

Please sign in to comment.