Files
TCOWW/src/main/kotlin/fr/azur/tcoww/items/CustomItems.kt
azur 97b73b0c55
All checks were successful
Auto Build / Build (push) Successful in 2m40s
🦋 Debugging for the 1.2.
2025-12-06 16:40:12 +01:00

268 lines
9.0 KiB
Kotlin

package fr.azur.tcoww.items
import fr.azur.tcoww.game.Game
import fr.azur.tcoww.roles.Role
import fr.azur.tcoww.utils.DataKeys
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import org.bukkit.Color
import org.bukkit.Material
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemRarity
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.CrossbowMeta
import org.bukkit.inventory.meta.Damageable
import org.bukkit.inventory.meta.PotionMeta
import org.bukkit.persistence.PersistentDataType
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
enum class CustomItems(
val cache: Boolean,
val supplier: () -> ItemStack,
) {
WereWolfTransformItem(true, {
ItemStack.of(Material.BONE).apply {
itemMeta =
itemMeta.apply {
customName(Component.text("Os de transformation", NamedTextColor.DARK_RED))
persistentDataContainer.set(
DataKeys.PowerItems,
PersistentDataType.INTEGER,
3,
)
lore(
listOf(
Component
.text("Clique pour basculer en forme loup-garou.")
.color(NamedTextColor.GOLD),
),
)
}
}
}),
GunBullet(true, {
ItemStack(Material.TIPPED_ARROW).apply {
itemMeta =
(itemMeta as PotionMeta).apply {
color = Color.ORANGE
displayName(Component.text("Balle de fusil.", NamedTextColor.YELLOW))
basePotionType =
basePotionType.apply {
addCustomEffect(PotionEffect(PotionEffectType.INSTANT_DAMAGE, 20, 99), true)
}
}
}
}),
BlasTechDL44(true, {
ItemStack.of(Material.CROSSBOW).apply {
itemMeta =
(itemMeta as CrossbowMeta).apply {
addChargedProjectile(GunBullet.item)
displayName(Component.text("BlasTech DL-44", NamedTextColor.GOLD))
addEnchant(Enchantment.INFINITY, 1, true)
}
itemMeta =
(itemMeta as Damageable).apply {
setMaxDamage(1)
}
}
}),
CrystalBall(true, {
ItemStack.of(Material.GLASS).apply {
itemMeta =
itemMeta.apply {
customName(
Component.text("Boule de cristal", NamedTextColor.AQUA),
)
persistentDataContainer.set(
DataKeys.PowerItems,
PersistentDataType.INTEGER,
4,
)
setMaxStackSize(1)
lore(listOf(Component.text("Click droit pour utiliser.", NamedTextColor.GOLD)))
}
}
}),
DeathPotion(true, {
ItemStack.of(Material.POTION).apply {
itemMeta =
(itemMeta as PotionMeta).apply {
setMaxStackSize(1)
customName(
Component.text("Potion de poison", NamedTextColor.DARK_PURPLE),
)
persistentDataContainer.set(
DataKeys.PowerItems,
PersistentDataType.INTEGER,
1,
)
color = Color.BLACK
lore(
listOf(
Component.text("Click droit pour utiliser.", NamedTextColor.GOLD),
),
)
}
itemMeta =
(itemMeta as Damageable).apply {
setMaxDamage(1)
}
}
}),
HealPotion(true, {
ItemStack.of(Material.POTION).apply {
itemMeta =
(itemMeta as PotionMeta).apply {
setMaxStackSize(1)
customName(
Component.text("Potion de vie", NamedTextColor.DARK_PURPLE),
)
persistentDataContainer.set(
DataKeys.PowerItems,
PersistentDataType.INTEGER,
2,
)
color = Color.RED
lore(listOf(Component.text("Click droit pour utiliser.", NamedTextColor.GOLD)))
}
itemMeta =
(itemMeta as Damageable).apply {
setMaxDamage(1)
}
}
}),
SpawnLocTool(true, {
ItemStack.of(Material.SUGAR_CANE).apply {
itemMeta =
itemMeta.apply {
setRarity(ItemRarity.EPIC)
persistentDataContainer.set(
DataKeys.ToolsItems,
PersistentDataType.INTEGER,
2,
)
lore(listOf(Component.text("Spawn location tool", NamedTextColor.GOLD)))
}
}
}),
BedLocTool(true, {
ItemStack.of(Material.WOODEN_HOE).apply {
itemMeta =
itemMeta.apply {
setRarity(ItemRarity.EPIC)
persistentDataContainer.set(
DataKeys.ToolsItems,
PersistentDataType.INTEGER,
1,
)
lore(listOf(Component.text("bed location tool", NamedTextColor.GOLD)))
}
}
}),
LobbyLocTool(true, {
ItemStack.of(Material.POPPED_CHORUS_FRUIT).apply {
itemMeta =
itemMeta.apply {
setRarity(ItemRarity.EPIC)
persistentDataContainer.set(
DataKeys.ToolsItems,
PersistentDataType.INTEGER,
3,
)
lore(listOf(Component.text("Lobby location tool", NamedTextColor.GOLD)))
}
}
}),
ListHint(false, {
val finalLore =
buildList {
add(
Component.text("C'est une liste de nom.", NamedTextColor.RED),
)
add(
Component.text("Il y a écrit que un de ces 3 citoyens", NamedTextColor.DARK_RED),
)
add(
Component.text("est un loup-garou.", NamedTextColor.DARK_RED),
)
val players =
Game.current
?.remainingPlayer
?.shuffled()
.orEmpty()
val (villagers, werewolves) =
players.partition {
Role.getRole(it)?.team != Role.Team.LG
}
val lg = werewolves.firstOrNull()
val names = mutableListOf<Player>()
if (lg != null) names.add(lg)
names.addAll(villagers.take(2))
val colors = NamedColors.namedColors.shuffled().toMutableList()
names.shuffled().forEach {
val color = colors.removeFirst()
add(Component.text("- ").append(it.displayName()).color(color))
}
if (isEmpty()) {
add(Component.text("nothing", NamedTextColor.DARK_RED, TextDecoration.OBFUSCATED))
}
}
ItemStack(Material.PAPER).apply {
itemMeta =
itemMeta.apply {
displayName(Component.text("Liste de nom", NamedTextColor.GOLD))
lore(finalLore)
}
}
}),
;
private var cachedItem: ItemStack? = null
val item: ItemStack
get() {
return if (cache) {
cachedItem ?: supplier().also { cachedItem = it }
} else {
supplier()
}
}
interface DamageablePotion :
Damageable,
PotionMeta {
override fun clone(): DamageablePotion
}
data object NamedColors {
val namedColors =
listOf(
NamedTextColor.DARK_RED,
NamedTextColor.RED,
NamedTextColor.GOLD,
NamedTextColor.YELLOW,
NamedTextColor.DARK_GREEN,
NamedTextColor.GREEN,
NamedTextColor.AQUA,
NamedTextColor.DARK_AQUA,
NamedTextColor.DARK_BLUE,
NamedTextColor.BLUE,
NamedTextColor.LIGHT_PURPLE,
NamedTextColor.DARK_PURPLE,
)
}
}