/
BukkitFcItemFactory_1_13_00_R01.kt
65 lines (57 loc) · 1.89 KB
/
BukkitFcItemFactory_1_13_00_R01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package net.benwoodworth.fastcraft.bukkit.item
import net.benwoodworth.fastcraft.bukkit.bukkit
import net.benwoodworth.fastcraft.platform.item.FcItem
import net.benwoodworth.fastcraft.platform.item.FcItemType
import net.benwoodworth.fastcraft.platform.item.FcItemTypes
import net.benwoodworth.fastcraft.platform.text.FcText
import net.benwoodworth.fastcraft.platform.text.FcTextFactory
import org.bukkit.inventory.ItemStack
import javax.inject.Inject
class BukkitFcItemFactory_1_13_00_R01 @Inject constructor(
private val itemTypes: FcItemTypes,
private val textFactory: FcTextFactory
) : BukkitFcItemFactory {
override fun createFcItem(
type: FcItemType,
amount: Int,
displayName: FcText?,
lore: List<FcText>
): FcItem {
val item = ItemStack(type.bukkit.material, amount)
return BukkitFcItem_1_13_00_R01(
base = item,
displayName = displayName,
lore = lore,
itemTypes = itemTypes
)
}
override fun FcItem.copy(
type: FcItemType,
amount: Int,
displayName: FcText?,
lore: List<FcText>
): FcItem {
val item = bukkit.base
item.type = type.bukkit.material
item.amount = amount
return BukkitFcItem_1_13_00_R01(
base = item,
displayName = displayName,
lore = lore,
itemTypes = itemTypes
)
}
override fun createFcItem(itemStack: ItemStack): FcItem {
val item = itemStack.clone()
val meta = item.getItemMetaOrNull()
return BukkitFcItem_1_13_00_R01(
base = item,
displayName = meta?.displayName
?.let { textFactory.createFcText(it) },
lore = meta?.lore
?.map { textFactory.createFcText(it ?: "") }
?: emptyList(),
itemTypes = itemTypes
)
}
}