From 6de0d8d1d6c9b043a461fe169cccb30cf9408cd3 Mon Sep 17 00:00:00 2001 From: howard127 Date: Sat, 2 Sep 2023 16:14:25 +0900 Subject: [PATCH 1/3] [update] #1 --- .../jp/xhw/noticebox/NoticeBoxPlugin.kt | 15 +++- .../exception/UserNotFoundException.kt | 5 ++ .../service/FetchReadAnnouncesService.kt | 3 +- .../FetchUserAnnounceSamplesService.kt | 29 ++++++ ...vice.kt => GetNumberOfAnnouncesService.kt} | 2 +- .../GetNumberOfUserAnnouncesService.kt | 17 ++++ .../service/StoreUserFirstJoinService.kt | 19 ++++ .../service/UserOpenAnnounceService.kt | 3 +- .../jp/xhw/noticebox/domain/model/User.kt | 3 +- .../domain/repository/AnnounceRepository.kt | 5 ++ .../domain/repository/UserRepository.kt | 2 +- .../xhw/noticebox/infrastructure/dao/User.kt | 13 +++ .../xhw/noticebox/infrastructure/dao/Users.kt | 12 +++ .../repository/AnnounceSqliteRepository.kt | 15 ++++ .../repository/UserSqliteRepository.kt | 17 +++- .../jp/xhw/noticebox/presenter/gui/BoxMenu.kt | 88 ++++++++++++------- .../presenter/gui/DeleteAnnounceMenu.kt | 4 +- 17 files changed, 208 insertions(+), 44 deletions(-) create mode 100644 src/main/kotlin/jp/xhw/noticebox/application/exception/UserNotFoundException.kt create mode 100644 src/main/kotlin/jp/xhw/noticebox/application/service/FetchUserAnnounceSamplesService.kt rename src/main/kotlin/jp/xhw/noticebox/application/service/{GetNumberOfAnnounceService.kt => GetNumberOfAnnouncesService.kt} (75%) create mode 100644 src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfUserAnnouncesService.kt create mode 100644 src/main/kotlin/jp/xhw/noticebox/application/service/StoreUserFirstJoinService.kt create mode 100644 src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/User.kt create mode 100644 src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/Users.kt diff --git a/src/main/kotlin/jp/xhw/noticebox/NoticeBoxPlugin.kt b/src/main/kotlin/jp/xhw/noticebox/NoticeBoxPlugin.kt index 67a62c0..9cfb7a3 100644 --- a/src/main/kotlin/jp/xhw/noticebox/NoticeBoxPlugin.kt +++ b/src/main/kotlin/jp/xhw/noticebox/NoticeBoxPlugin.kt @@ -4,9 +4,11 @@ import dev.jorel.commandapi.CommandAPI import dev.jorel.commandapi.CommandAPIBukkitConfig import jp.xhw.noticebox.application.external.Economy import jp.xhw.noticebox.application.external.ItemClaimLogic +import jp.xhw.noticebox.application.service.StoreUserFirstJoinService import jp.xhw.noticebox.infrastructure.dao.AnnounceOpens import jp.xhw.noticebox.infrastructure.dao.AnnounceRewards import jp.xhw.noticebox.infrastructure.dao.Announces +import jp.xhw.noticebox.infrastructure.dao.Users import jp.xhw.noticebox.infrastructure.external.ItemClaimLogicImpl import jp.xhw.noticebox.infrastructure.external.VaultEconomy import jp.xhw.noticebox.infrastructure.repository.AnnounceSqliteRepository @@ -14,6 +16,9 @@ import jp.xhw.noticebox.infrastructure.repository.UserSqliteRepository import jp.xhw.noticebox.presenter.command.Command import jp.xhw.noticebox.presenter.listener.EventListener import org.bukkit.Bukkit +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.plugin.java.JavaPlugin import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils @@ -21,9 +26,10 @@ import org.jetbrains.exposed.sql.transactions.TransactionManager import org.jetbrains.exposed.sql.transactions.transaction import java.io.File import java.sql.Connection +import java.time.LocalDateTime import java.util.logging.Level -class NoticeBoxPlugin : JavaPlugin() { +class NoticeBoxPlugin : JavaPlugin(), Listener { companion object { lateinit var plugin: NoticeBoxPlugin @@ -57,8 +63,10 @@ class NoticeBoxPlugin : JavaPlugin() { SchemaUtils.create(Announces) SchemaUtils.create(AnnounceRewards) SchemaUtils.create(AnnounceOpens) + SchemaUtils.create(Users) } + server.pluginManager.registerEvents(this, this) server.pluginManager.registerEvents(EventListener(), this) Command().register() @@ -67,4 +75,9 @@ class NoticeBoxPlugin : JavaPlugin() { override fun onDisable() {} + @EventHandler + fun on(event: PlayerJoinEvent) { + StoreUserFirstJoinService(userRepository).store(event.player.uniqueId, LocalDateTime.now()) + } + } diff --git a/src/main/kotlin/jp/xhw/noticebox/application/exception/UserNotFoundException.kt b/src/main/kotlin/jp/xhw/noticebox/application/exception/UserNotFoundException.kt new file mode 100644 index 0000000..bb19eb6 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/application/exception/UserNotFoundException.kt @@ -0,0 +1,5 @@ +package jp.xhw.noticebox.application.exception + +import java.util.* + +class UserNotFoundException(val userId: UUID) : RuntimeException(userId.toString()) \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/FetchReadAnnouncesService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/FetchReadAnnouncesService.kt index 6967f81..6727e51 100644 --- a/src/main/kotlin/jp/xhw/noticebox/application/service/FetchReadAnnouncesService.kt +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/FetchReadAnnouncesService.kt @@ -1,5 +1,6 @@ package jp.xhw.noticebox.application.service +import jp.xhw.noticebox.application.exception.UserNotFoundException import jp.xhw.noticebox.domain.model.AnnounceId import jp.xhw.noticebox.domain.model.UserId import jp.xhw.noticebox.domain.repository.UserRepository @@ -10,7 +11,7 @@ class FetchReadAnnouncesService(private val userRepository: UserRepository) { fun fetch(userId: UUID): List { return transaction { - userRepository.find(UserId(userId)).openedAnnounceIds.map(AnnounceId::value) + userRepository.find(UserId(userId))?.openedAnnounceIds?.map(AnnounceId::value)?: throw UserNotFoundException(userId) } } diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/FetchUserAnnounceSamplesService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/FetchUserAnnounceSamplesService.kt new file mode 100644 index 0000000..f6f59a7 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/FetchUserAnnounceSamplesService.kt @@ -0,0 +1,29 @@ +package jp.xhw.noticebox.application.service + +import jp.xhw.noticebox.application.dto.AnnounceSampleDto +import jp.xhw.noticebox.application.exception.UserNotFoundException +import jp.xhw.noticebox.domain.model.User +import jp.xhw.noticebox.domain.model.UserId +import jp.xhw.noticebox.domain.repository.AnnounceRepository +import jp.xhw.noticebox.domain.repository.UserRepository +import org.jetbrains.exposed.sql.transactions.transaction +import java.util.* + +class FetchUserAnnounceSamplesService( + private val announceRepository: AnnounceRepository, + private val userRepository: UserRepository +) { + fun fetch(userId: UUID, offset: Long, limit: Int): List { + return transaction { + val user: User = userRepository.find(UserId(userId))?: throw UserNotFoundException(userId) + val announceSampleList = announceRepository.findPagedAnnounceSamples(offset, limit, user.firstJoin) + announceSampleList.map { sample -> + AnnounceSampleDto( + sample.announceId.value, + sample.title.value, + sample.createdAt + ) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnounceService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnouncesService.kt similarity index 75% rename from src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnounceService.kt rename to src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnouncesService.kt index da51bee..2da6cfd 100644 --- a/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnounceService.kt +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfAnnouncesService.kt @@ -3,7 +3,7 @@ package jp.xhw.noticebox.application.service import jp.xhw.noticebox.domain.repository.AnnounceRepository import org.jetbrains.exposed.sql.transactions.transaction -class GetNumberOfAnnounceService(private val announceRepository: AnnounceRepository) { +class GetNumberOfAnnouncesService(private val announceRepository: AnnounceRepository) { fun get(): Long { return transaction { announceRepository.count() diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfUserAnnouncesService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfUserAnnouncesService.kt new file mode 100644 index 0000000..9218c47 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/GetNumberOfUserAnnouncesService.kt @@ -0,0 +1,17 @@ +package jp.xhw.noticebox.application.service + +import jp.xhw.noticebox.application.exception.UserNotFoundException +import jp.xhw.noticebox.domain.model.UserId +import jp.xhw.noticebox.domain.repository.AnnounceRepository +import jp.xhw.noticebox.domain.repository.UserRepository +import org.jetbrains.exposed.sql.transactions.transaction +import java.util.UUID + +class GetNumberOfUserAnnouncesService(private val announceRepository: AnnounceRepository, private val userRepository: UserRepository) { + fun get(userId: UUID): Long { + return transaction { + val user = userRepository.find(UserId(userId))?: throw UserNotFoundException(userId) + announceRepository.count(user.firstJoin) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/StoreUserFirstJoinService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/StoreUserFirstJoinService.kt new file mode 100644 index 0000000..bd77ad8 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/StoreUserFirstJoinService.kt @@ -0,0 +1,19 @@ +package jp.xhw.noticebox.application.service + +import jp.xhw.noticebox.domain.model.User +import jp.xhw.noticebox.domain.model.UserId +import jp.xhw.noticebox.domain.repository.UserRepository +import org.jetbrains.exposed.sql.transactions.transaction +import java.time.LocalDateTime +import java.util.UUID + +class StoreUserFirstJoinService(private val userRepository: UserRepository) { + fun store(userId: UUID, date: LocalDateTime) { + transaction { + val user = userRepository.find(UserId(userId)) + if (user == null) { + userRepository.save(User(UserId(userId), mutableListOf(), date)) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/application/service/UserOpenAnnounceService.kt b/src/main/kotlin/jp/xhw/noticebox/application/service/UserOpenAnnounceService.kt index 5adee9a..a9edc08 100644 --- a/src/main/kotlin/jp/xhw/noticebox/application/service/UserOpenAnnounceService.kt +++ b/src/main/kotlin/jp/xhw/noticebox/application/service/UserOpenAnnounceService.kt @@ -1,6 +1,7 @@ package jp.xhw.noticebox.application.service import jp.xhw.noticebox.application.dto.RewardDto +import jp.xhw.noticebox.application.exception.UserNotFoundException import jp.xhw.noticebox.application.external.Economy import jp.xhw.noticebox.application.external.ItemClaimLogic import jp.xhw.noticebox.domain.model.AnnounceId @@ -18,7 +19,7 @@ class UserOpenAnnounceService( ) { fun open(userId: UUID, announceId: UUID): RewardDto? { return transaction { - val opener = userRepository.find(UserId(userId)) + val opener = userRepository.find(UserId(userId))?: throw UserNotFoundException(userId) val announce = announceRepository.findById(AnnounceId(announceId)) ?: return@transaction null if (opener.isNotOpened(announce)) { diff --git a/src/main/kotlin/jp/xhw/noticebox/domain/model/User.kt b/src/main/kotlin/jp/xhw/noticebox/domain/model/User.kt index bdcc609..123619d 100644 --- a/src/main/kotlin/jp/xhw/noticebox/domain/model/User.kt +++ b/src/main/kotlin/jp/xhw/noticebox/domain/model/User.kt @@ -1,9 +1,10 @@ package jp.xhw.noticebox.domain.model import jp.xhw.noticebox.domain.exceptions.AnnounceAlreadyOpenedException +import java.time.LocalDateTime import java.util.* -class User(val userId: UserId, val openedAnnounceIds: MutableList) { +class User(val userId: UserId, val openedAnnounceIds: MutableList, val firstJoin: LocalDateTime) { fun openAnnounce(announce: Announce) { if (openedAnnounceIds.contains(announce.announceId)) { diff --git a/src/main/kotlin/jp/xhw/noticebox/domain/repository/AnnounceRepository.kt b/src/main/kotlin/jp/xhw/noticebox/domain/repository/AnnounceRepository.kt index f5ce342..2a56e43 100644 --- a/src/main/kotlin/jp/xhw/noticebox/domain/repository/AnnounceRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/domain/repository/AnnounceRepository.kt @@ -4,11 +4,14 @@ import jp.xhw.noticebox.domain.model.Announce import jp.xhw.noticebox.domain.model.AnnounceId import jp.xhw.noticebox.domain.model.AnnounceReward import jp.xhw.noticebox.domain.model.AnnounceSample +import java.time.LocalDateTime interface AnnounceRepository { fun findById(announceId: AnnounceId): Announce? + fun findPagedAnnounceSamples(offset: Long, limit: Int, after: LocalDateTime): List + fun findPagedAnnounceSamples(offset: Long, limit: Int): List fun save(announce: Announce) @@ -19,4 +22,6 @@ interface AnnounceRepository { fun count(): Long + fun count(after: LocalDateTime): Long + } \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/domain/repository/UserRepository.kt b/src/main/kotlin/jp/xhw/noticebox/domain/repository/UserRepository.kt index 518c0c7..25f3e05 100644 --- a/src/main/kotlin/jp/xhw/noticebox/domain/repository/UserRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/domain/repository/UserRepository.kt @@ -5,7 +5,7 @@ import jp.xhw.noticebox.domain.model.UserId interface UserRepository { - fun find(userId: UserId): User + fun find(userId: UserId): User? fun save(user: User) } \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/User.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/User.kt new file mode 100644 index 0000000..a9a7b49 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/User.kt @@ -0,0 +1,13 @@ +package jp.xhw.noticebox.infrastructure.dao + +import org.jetbrains.exposed.dao.UUIDEntity +import org.jetbrains.exposed.dao.UUIDEntityClass +import org.jetbrains.exposed.dao.id.EntityID +import java.util.* + +class User (id: EntityID) : UUIDEntity(id) { + companion object : UUIDEntityClass(Users) + + var joinedAt by Users.joinedAt + +} \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/Users.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/Users.kt new file mode 100644 index 0000000..f450432 --- /dev/null +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/dao/Users.kt @@ -0,0 +1,12 @@ +package jp.xhw.noticebox.infrastructure.dao + +import org.jetbrains.exposed.dao.id.UUIDTable +import org.jetbrains.exposed.sql.Column +import org.jetbrains.exposed.sql.javatime.datetime +import java.time.LocalDateTime + +object Users : UUIDTable() { + + val joinedAt: Column = datetime("joined_at") + +} \ No newline at end of file diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt index 93681bf..8cde003 100644 --- a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt @@ -6,7 +6,9 @@ import jp.xhw.noticebox.infrastructure.dao.AnnounceRewards import jp.xhw.noticebox.infrastructure.dao.Announces import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater import org.jetbrains.exposed.sql.statements.api.ExposedBlob +import java.time.LocalDateTime import jp.xhw.noticebox.infrastructure.dao.Announce as AnnounceDao import jp.xhw.noticebox.infrastructure.dao.AnnounceReward as AnnounceRewardDao @@ -24,6 +26,15 @@ class AnnounceSqliteRepository : AnnounceRepository { ) } + override fun findPagedAnnounceSamples(offset: Long, limit: Int, after: LocalDateTime): List { + val announces = Announces + .slice(Announces.id, Announces.title, Announces.createdAt) + .select { Announces.createdAt greater after } + .orderBy(Announces.createdAt, SortOrder.DESC) + .limit(limit, offset = offset) + return announces.map(this::convertToAnnounceSample).toList() + } + override fun findPagedAnnounceSamples(offset: Long, limit: Int): List { val announces = Announces .slice(Announces.id, Announces.title, Announces.createdAt) @@ -80,6 +91,10 @@ class AnnounceSqliteRepository : AnnounceRepository { return AnnounceDao.count() } + override fun count(after: LocalDateTime): Long { + return Announces.select { Announces.createdAt greater after }.count() + } + private fun convertToAnnounceSample(resultRow: ResultRow): AnnounceSample { val uuid = resultRow[Announces.id].value diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt index 54fd533..3068cd2 100644 --- a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt @@ -8,19 +8,28 @@ import jp.xhw.noticebox.infrastructure.dao.AnnounceOpens import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.deleteWhere -import jp.xhw.noticebox.infrastructure.dao.AnnounceOpen as UserDao +import java.time.LocalDateTime +import jp.xhw.noticebox.infrastructure.dao.AnnounceOpen as AnnounceOpensDao +import jp.xhw.noticebox.infrastructure.dao.User as UserDao class UserSqliteRepository : UserRepository { - override fun find(userId: UserId): User { + override fun find(userId: UserId): User? { + val user = UserDao.findById(userId.value)?: return null val openedAnnounces = mutableListOf() - UserDao + AnnounceOpensDao .find { AnnounceOpens.userId eq userId.value } .forEach { announceOpen -> openedAnnounces.add(AnnounceId(announceOpen.announceId)) } - return User(userId, openedAnnounces) + return User(userId, openedAnnounces, user.joinedAt) } override fun save(user: User) { + val userDao = UserDao.findById(user.userId.value) + if (userDao == null) { + UserDao.new(user.userId.value) { + this.joinedAt = user.firstJoin + } + } AnnounceOpens.deleteWhere { userId eq user.userId.value } val list = mutableListOf>() for (announceId in user.openedAnnounceIds) { diff --git a/src/main/kotlin/jp/xhw/noticebox/presenter/gui/BoxMenu.kt b/src/main/kotlin/jp/xhw/noticebox/presenter/gui/BoxMenu.kt index 131012a..5e91344 100644 --- a/src/main/kotlin/jp/xhw/noticebox/presenter/gui/BoxMenu.kt +++ b/src/main/kotlin/jp/xhw/noticebox/presenter/gui/BoxMenu.kt @@ -3,6 +3,7 @@ package jp.xhw.noticebox.presenter.gui import de.themoep.inventorygui.* import jp.xhw.noticebox.NoticeBoxPlugin import jp.xhw.noticebox.application.dto.AnnounceSampleDto +import jp.xhw.noticebox.application.exception.UserNotFoundException import jp.xhw.noticebox.application.service.* import jp.xhw.noticebox.presenter.shared.Constants import org.bukkit.Material @@ -185,34 +186,40 @@ class BoxMenu private constructor(plugin: NoticeBoxPlugin, menuTitle: String, pr if (readAnnounces.contains(sample.announceId)) ItemStack(Material.BOOK) else createBrokenWrittenBook(), { _ -> player.openBook(createBook(sample)) - val claimedReward = UserOpenAnnounceService( - NoticeBoxPlugin.plugin.userRepository, - NoticeBoxPlugin.plugin.announceRepository, - NoticeBoxPlugin.economy, - NoticeBoxPlugin.itemClaimLogic - ).open(player.uniqueId, sample.announceId) - claimedReward?.let { - if (claimedReward.money > 0.0 || claimedReward.items.isNotEmpty()) { - val messages = mutableListOf() + try { + val claimedReward = UserOpenAnnounceService( + NoticeBoxPlugin.plugin.userRepository, + NoticeBoxPlugin.plugin.announceRepository, + NoticeBoxPlugin.economy, + NoticeBoxPlugin.itemClaimLogic + ).open(player.uniqueId, sample.announceId) + claimedReward?.let { + if (claimedReward.money > 0.0 || claimedReward.items.isNotEmpty()) { + val messages = mutableListOf() - messages.add(Constants.MESSAGE_SEPARATOR) - messages.add("") - if (claimedReward.money > 0.0) messages.add("お金 §6%d§r".format(claimedReward.money)) - if (claimedReward.items.isNotEmpty()) messages.add("アイテム §a%d§r個".format(claimedReward.items.size)) - messages.add("") - messages.add(Constants.MESSAGE_SEPARATOR) + messages.add(Constants.MESSAGE_SEPARATOR) + messages.add("") + if (claimedReward.money > 0.0) messages.add("お金 §6%d§r".format(claimedReward.money)) + if (claimedReward.items.isNotEmpty()) messages.add("アイテム §a%d§r個".format(claimedReward.items.size)) + messages.add("") + messages.add(Constants.MESSAGE_SEPARATOR) - for (message in messages) { - player.sendMessage(message) + for (message in messages) { + player.sendMessage(message) + } } - } - player.playSound( - player, - Sound.ENTITY_PLAYER_LEVELUP, - 1.0f, - 1.0f - ) + player.playSound( + player, + Sound.ENTITY_PLAYER_LEVELUP, + 1.0f, + 1.0f + ) + } + } catch (e: UserNotFoundException) { + this.menu.close() + this.menu.destroy() + player.sendMessage("§c報酬の受け取り中にエラーが発生しました: ユーザーが見つかりませんでした") } true }, @@ -236,15 +243,32 @@ class BoxMenu private constructor(plugin: NoticeBoxPlugin, menuTitle: String, pr } private fun update() { - currentSamples = FetchAnnounceSamplesService(NoticeBoxPlugin.plugin.announceRepository).fetch( - ANNOUNCES_PER_PAGE * (currentPage - 1), - ANNOUNCES_PER_PAGE - ) - numOfAnnounces = GetNumberOfAnnounceService(NoticeBoxPlugin.plugin.announceRepository).get() - maxPage = if (numOfAnnounces == 0L) 1L else (numOfAnnounces + ANNOUNCES_PER_PAGE - 1) / ANNOUNCES_PER_PAGE - readAnnounces = FetchReadAnnouncesService(NoticeBoxPlugin.plugin.userRepository).fetch(player.uniqueId) + try { + if (player.hasPermission("noticebox.viewall")) { + currentSamples = FetchAnnounceSamplesService(NoticeBoxPlugin.plugin.announceRepository).fetch( + ANNOUNCES_PER_PAGE * (currentPage - 1), + ANNOUNCES_PER_PAGE + ) - menu.title = "ページ: $currentPage" + numOfAnnounces = GetNumberOfAnnouncesService(NoticeBoxPlugin.plugin.announceRepository).get() + } else { + currentSamples = FetchUserAnnounceSamplesService(NoticeBoxPlugin.plugin.announceRepository, NoticeBoxPlugin.plugin.userRepository).fetch( + player.uniqueId, + ANNOUNCES_PER_PAGE * (currentPage - 1), + ANNOUNCES_PER_PAGE + ) + + numOfAnnounces = GetNumberOfUserAnnouncesService(NoticeBoxPlugin.plugin.announceRepository, NoticeBoxPlugin.plugin.userRepository).get(player.uniqueId) + } + maxPage = if (numOfAnnounces == 0L) 1L else (numOfAnnounces + ANNOUNCES_PER_PAGE - 1) / ANNOUNCES_PER_PAGE + readAnnounces = FetchReadAnnouncesService(NoticeBoxPlugin.plugin.userRepository).fetch(player.uniqueId) + + menu.title = "ページ: $currentPage" + } catch (e: UserNotFoundException) { + this.menu.close() + this.menu.destroy() + player.sendMessage("§cお知らせの読み込み中にエラーが発生しました: ユーザーが見つかりませんでした") + } } private fun createBrokenWrittenBook(): ItemStack { diff --git a/src/main/kotlin/jp/xhw/noticebox/presenter/gui/DeleteAnnounceMenu.kt b/src/main/kotlin/jp/xhw/noticebox/presenter/gui/DeleteAnnounceMenu.kt index 03dcb70..3bf3a42 100644 --- a/src/main/kotlin/jp/xhw/noticebox/presenter/gui/DeleteAnnounceMenu.kt +++ b/src/main/kotlin/jp/xhw/noticebox/presenter/gui/DeleteAnnounceMenu.kt @@ -4,7 +4,7 @@ import de.themoep.inventorygui.* import jp.xhw.noticebox.NoticeBoxPlugin import jp.xhw.noticebox.application.dto.AnnounceSampleDto import jp.xhw.noticebox.application.service.FetchAnnounceSamplesService -import jp.xhw.noticebox.application.service.GetNumberOfAnnounceService +import jp.xhw.noticebox.application.service.GetNumberOfAnnouncesService import jp.xhw.noticebox.presenter.shared.Constants import org.bukkit.Material import org.bukkit.entity.Player @@ -196,7 +196,7 @@ class DeleteAnnounceMenu private constructor(plugin: NoticeBoxPlugin, menuTitle: ANNOUNCES_PER_PAGE * (currentPage - 1), ANNOUNCES_PER_PAGE ) - numOfAnnounces = GetNumberOfAnnounceService(NoticeBoxPlugin.plugin.announceRepository).get() + numOfAnnounces = GetNumberOfAnnouncesService(NoticeBoxPlugin.plugin.announceRepository).get() maxPage = if (numOfAnnounces == 0L) 1L else (numOfAnnounces + ANNOUNCES_PER_PAGE - 1) / ANNOUNCES_PER_PAGE menu.title = "ページ: $currentPage" From fee92586babc679072a6bae4fa7e578d4e43f793 Mon Sep 17 00:00:00 2001 From: howard127 Date: Sat, 2 Sep 2023 16:16:49 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[update]=20=E6=96=B0=E3=81=97=E3=81=84?= =?UTF-8?q?=E3=83=91=E3=83=BC=E3=83=9F=E3=83=83=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E8=AA=AC=E6=98=8E=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 78f16cb..245a31f 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,18 @@ ### 💬 コマンド -| コマンド | 引数 | 説明 | パーミッション | -| --- | --- | --- | --- | -| /noticebox add | | お知らせを作成するための本を取得します | `noticebox.add` | -| /noticebox remove | | お知らせを削除するためのGUIを表示します | `noticebox.remove` | -| /noticebox open | | お知らせ一覧のGUIを表示します | `noticebox.open` | -| /noticebox open | `` | ``に対してお知らせ一覧のGUIを表示します | `noticebox.open-other` | +| コマンド | 引数 | 説明 | パーミッション | +|-------------------|------------|--------------------------------|------------------------| +| /noticebox add | | お知らせを作成するための本を取得します | `noticebox.add` | +| /noticebox remove | | お知らせを削除するためのGUIを表示します | `noticebox.remove` | +| /noticebox open | | お知らせ一覧のGUIを表示します | `noticebox.open` | +| /noticebox open | `` | ``に対してお知らせ一覧のGUIを表示します | `noticebox.open-other` | + +### 💬 その他のパーミッション + +| パーミッション | 説明 | +|-------------------|---------------------| +| noticebox.viewall | すべてのお知らせが見れるようになります | ### 👦 お知らせ作成の流れ From 26683a683adc60ae7838a264624f34f9e136d716 Mon Sep 17 00:00:00 2001 From: howard127 Date: Sat, 2 Sep 2023 16:17:36 +0900 Subject: [PATCH 3/3] [fix] remove unused import --- .../infrastructure/repository/AnnounceSqliteRepository.kt | 1 - .../infrastructure/repository/UserSqliteRepository.kt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt index 8cde003..679176a 100644 --- a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/AnnounceSqliteRepository.kt @@ -6,7 +6,6 @@ import jp.xhw.noticebox.infrastructure.dao.AnnounceRewards import jp.xhw.noticebox.infrastructure.dao.Announces import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq -import org.jetbrains.exposed.sql.SqlExpressionBuilder.greater import org.jetbrains.exposed.sql.statements.api.ExposedBlob import java.time.LocalDateTime import jp.xhw.noticebox.infrastructure.dao.Announce as AnnounceDao diff --git a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt index 3068cd2..0d8e9cd 100644 --- a/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt +++ b/src/main/kotlin/jp/xhw/noticebox/infrastructure/repository/UserSqliteRepository.kt @@ -8,14 +8,13 @@ import jp.xhw.noticebox.infrastructure.dao.AnnounceOpens import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.deleteWhere -import java.time.LocalDateTime import jp.xhw.noticebox.infrastructure.dao.AnnounceOpen as AnnounceOpensDao import jp.xhw.noticebox.infrastructure.dao.User as UserDao class UserSqliteRepository : UserRepository { override fun find(userId: UserId): User? { - val user = UserDao.findById(userId.value)?: return null + val user = UserDao.findById(userId.value) ?: return null val openedAnnounces = mutableListOf() AnnounceOpensDao .find { AnnounceOpens.userId eq userId.value }