✔️ Prepare plugin 1.2 version.

This commit is contained in:
2025-11-30 17:22:48 +01:00
parent f0d1e27085
commit fa5a54c8b9
44 changed files with 2031 additions and 1525 deletions

View File

@@ -2,12 +2,12 @@ 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.NamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemRarity
@@ -19,181 +19,205 @@ import org.bukkit.persistence.PersistentDataType
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType
enum class CustomItems(val cache: Boolean, val supplier: () -> ItemStack) {
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").color(NamedTextColor.DARK_RED))
persistentDataContainer.set(
NamespacedKey("tcoww", "power"),
PersistentDataType.INTEGER,
3
)
lore(
listOf(
Component.text("Clique pour basculer en forme loup-garou.")
.color(NamedTextColor.GOLD)
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)
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)
}
itemMeta =
(itemMeta as DamageableCrossbow).apply {
addChargedProjectile(GunBullet.item)
displayName(Component.text("BlasTech DL-44", NamedTextColor.GOLD))
addEnchant(Enchantment.INFINITY, 1, true)
setMaxDamage(1)
}
}
}),
CrystalBall(true, {
ItemStack.of(Material.GLASS).apply {
itemMeta = itemMeta.apply {
customName(
Component.text("Boule de cristal").color(NamedTextColor.AQUA)
)
persistentDataContainer.set(
NamespacedKey("tcoww", "power"),
PersistentDataType.INTEGER,
4
)
lore(listOf(Component.text("/power view <pseudo> pour l'utiliser.").color(NamedTextColor.GOLD)))
}
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 {
customName(
Component.text("Potion de poison").color(NamedTextColor.DARK_PURPLE)
)
persistentDataContainer.set(
NamespacedKey("tcoww", "power"),
PersistentDataType.INTEGER,
1
)
color = Color.BLACK
lore(
listOf(
Component.text("/power kill <pseudo> pour l'utiliser.").color(NamedTextColor.GOLD)
itemMeta =
(itemMeta as DamageablePotion).apply {
setMaxStackSize(1)
setMaxDamage(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),
),
)
}
}
}),
HealPotion(true, {
ItemStack.of(Material.POTION).apply {
itemMeta = (itemMeta as PotionMeta).apply {
customName(
Component.text("Potion de vie").color(NamedTextColor.DARK_PURPLE)
)
persistentDataContainer.set(
NamespacedKey("tcoww", "power"),
PersistentDataType.INTEGER,
2
)
color = Color.RED
lore(listOf(Component.text("/power save <pseudo> pour l'utiliser.").color(NamedTextColor.GOLD)))
}
itemMeta =
(itemMeta as DamageablePotion).apply {
setMaxStackSize(1)
setMaxDamage(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)))
}
}
}),
SpawnLocTool(true, {
ItemStack.of(Material.SUGAR_CANE).apply {
itemMeta = itemMeta.apply {
setRarity(ItemRarity.EPIC)
persistentDataContainer.set(
NamespacedKey("tcoww", "tools"),
PersistentDataType.INTEGER,
2
)
lore(listOf(Component.text("Spawn location tool").color(NamedTextColor.GOLD)))
}
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(
NamespacedKey("tcoww", "tools"),
PersistentDataType.INTEGER,
1
)
lore(listOf(Component.text("bed location tool").color(NamedTextColor.GOLD)))
}
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(
NamespacedKey("tcoww", "tools"),
PersistentDataType.INTEGER,
3
)
lore(listOf(Component.text("Lobby location tool").color(NamedTextColor.GOLD)))
}
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 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?.playersMutable?.shuffled().orEmpty()
val players =
Game.current
?.remainingPlayer
?.shuffled()
.orEmpty()
val (villagers, werewolves) = players.partition {
Role.getRole(it)?.lg == false
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))
}
}
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)
}
itemMeta =
itemMeta.apply {
displayName(Component.text("Liste de nom", NamedTextColor.GOLD))
lore(finalLore)
}
}
});
}),
;
private var cachedItem: ItemStack? = null
@@ -206,21 +230,31 @@ enum class CustomItems(val cache: Boolean, val supplier: () -> ItemStack) {
}
}
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
)
interface DamageableCrossbow :
Damageable,
CrossbowMeta
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,
)
}
}