Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
CustomInventory::item 複数スロット対応しました
Browse files Browse the repository at this point in the history
  • Loading branch information
sya-ri committed Apr 27, 2020
1 parent bd4ebd6 commit 60368b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
15 changes: 0 additions & 15 deletions src/main/kotlin/me/syari/ss/core/config/dataType/ConfigDataType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@ interface ConfigDataType<T> {
return get(config, path, notFoundError) ?: default
}

/**
* - [ConfigDataType.NUMBER]
* - [ConfigDataType.INT]
* - [ConfigDataType.LONG]
* - [ConfigDataType.FLOAT]
* - [ConfigDataType.STRING]
* - [ConfigDataType.STRINGLIST]
* - [ConfigDataType.DATE]
* - [ConfigDataType.LOCATION]
* - [ConfigDataType.MATERIAL]
* - [ConfigDataType.PARTICLE]
* - [ConfigDataType.POTION]
* - [ConfigDataType.SOUND]
* - [ConfigDataType.DATABASE]
*/
companion object {
val NUMBER = ConfigNumberDataType
val INT = ConfigIntDataType
Expand Down
62 changes: 52 additions & 10 deletions src/main/kotlin/me/syari/ss/core/inventory/CustomInventory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ class CustomInventory(val inventory: Inventory, private val id: List<String>) {
fun item(index: Int, item: ItemStack): ClickEvent {
return if (index in 0 until inventory.size) {
inventory.setItem(index, item)
ClickEvent(this, index)
ClickEvent(this, listOf(index))
} else {
ClickEvent(this, null)
ClickEvent(this, listOf())
}
}

Expand Down Expand Up @@ -142,12 +142,34 @@ class CustomInventory(val inventory: Inventory, private val id: List<String>) {
amount: Int = 1,
shine: Boolean = false
): ClickEvent {
return item(index, CustomItemStack.create(material, display, *lore.toTypedArray(), amount = amount).apply {
if (shine) {
addEnchant(Enchantment.DURABILITY, 0)
addItemFlag(ItemFlag.HIDE_ENCHANTS)
}
})
return item(listOf(index), material, display, lore.toList(), amount, shine)
}

/**
* @param index アイテムの場所
* @param material アイテムタイプ
* @param display アイテム名
* @param lore アイテムの説明文
* @param amount アイテムの数
* @param shine エンチャントを付与する default: false
* @return [ClickEvent]
*/
fun item(
index: Iterable<Int>,
material: Material,
display: String,
lore: Collection<String>,
amount: Int = 1,
shine: Boolean = false
): ClickEvent {
return ClickEvent(this, index.map {
item(it, CustomItemStack.create(material, display, *lore.toTypedArray(), amount = amount).apply {
if (shine) {
addEnchant(Enchantment.DURABILITY, 0)
addItemFlag(ItemFlag.HIDE_ENCHANTS)
}
})
}.flatMap { it.slot })
}

/**
Expand All @@ -166,14 +188,34 @@ class CustomInventory(val inventory: Inventory, private val id: List<String>) {
vararg lore: String,
amount: Int = 1,
shine: Boolean = false
): ClickEvent {
return item(listOf(index), material, display, lore.toList(), amount, shine)
}

/**
* @param index アイテムの場所
* @param material アイテムタイプ
* @param display アイテム名
* @param lore アイテムの説明文
* @param amount アイテムの数
* @param shine エンチャントを付与する default: false
* @return [ClickEvent]
*/
fun item(
index: Iterable<Int>,
material: Material,
display: String,
vararg lore: String,
amount: Int = 1,
shine: Boolean = false
): ClickEvent {
return item(index, material, display, lore.toList(), amount, shine)
}

/**
* アイテム単位でクリックイベントを設定します
*/
data class ClickEvent(val inventory: CustomInventory, val slot: Int?) {
data class ClickEvent(val inventory: CustomInventory, val slot: List<Int>) {
/**
* @param clickType クリックタイプ
* @param run クリックタイプが一致した時に実行する処理
Expand All @@ -196,7 +238,7 @@ class CustomInventory(val inventory: Inventory, private val id: List<String>) {
}

private fun addEvent(clickType: ClickType?, run: () -> Unit) {
slot?.let {
slot.forEach {
inventory.events[it to clickType] = run
}
}
Expand Down

0 comments on commit 60368b6

Please sign in to comment.