Skip to content

Commit

Permalink
✨ support add lore
Browse files Browse the repository at this point in the history
  • Loading branch information
XiYang6666 committed Jun 7, 2024
1 parent 2eeb928 commit ca3f360
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/xyz/xasmc/hashbook/config/ConfigLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ object ConfigLoader {
ItemDataMode.PDC
}
},
setHashWhenOpenBook = yamlConfig.getBoolean("set_hash_when_open_book")
setHashWhenOpenBook = yamlConfig.getBoolean("set_hash_when_open_book"),
setLore = yamlConfig.getBoolean("set_lore"),
loreContent = yamlConfig.getString("lore_content") ?: "<dark_aqua>Recorded by HashBook",
)

return config
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/xyz/xasmc/hashbook/config/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ data class PluginConfig(
val debug: Boolean,
val storageMode: StorageMode,
val itemDataMode: ItemDataMode,
val setHashWhenOpenBook: Boolean
val setHashWhenOpenBook: Boolean,
val setLore: Boolean,
val loreContent: String
)
9 changes: 9 additions & 0 deletions src/main/kotlin/xyz/xasmc/hashbook/util/BookUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.BookMeta
import xyz.xasmc.hashbook.HashBook
import xyz.xasmc.hashbook.service.ItemDataServices
import xyz.xasmc.hashbook.service.StorageServices
import xyz.xasmc.hashbook.util.MessageUtil.debugMiniMessage
import xyz.xasmc.hashbook.util.MessageUtil.sendMiniMessage
import java.util.*

object BookUtil {
@OptIn(ExperimentalStdlibApi::class)
Expand Down Expand Up @@ -39,6 +41,13 @@ object BookUtil {
if (!ItemDataServices.hasItemData(newItem, "HashBook.Hash")) {
val hash = generateHash(bookMeta)

if (HashBook.config.setLore) {
val lore = bookMeta.lore() ?: LinkedList()
lore.add(MessageUtil.mm.deserialize(HashBook.config.loreContent))
bookMeta.lore(lore)
newItem.setItemMeta(bookMeta)
}

StorageServices.save(hash, bookMeta.pages())
player.debugMiniMessage("$msgTitle <aqua>[debug]<dark_green>已存储成书书页</dark_green> <aqua>hash</aqua>: <green>$hash</green> <aqua>meta</aqua>: <green>$bookMeta</green>")

Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ storage_mode: file
item_data_mode: pdc

# 打开成书时立即设置哈希
set_hash_when_open_book: true
set_hash_when_open_book: true

# 是否为已存储哈希的成书添加简介
set_lore: true

# 简介内容, 使用 MiniMessage 格式, 详见 https://docs.advntr.dev/minimessage/format.html
lore_content: "<dark_aqua>Recorded by HashBook"

0 comments on commit ca3f360

Please sign in to comment.