Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.unchama.generic.effect.concurrent

import cats.Monad
import cats.effect.concurrent.Semaphore
import cats.effect.{Bracket, Concurrent, Sync, Timer}

Expand All @@ -17,19 +16,17 @@ final class RecoveringSemaphore[F[_]: Timer: Concurrent] private (semaphore: Sem
/**
* このセマフォが利用可能であれば `action` を実行し、 `recoverTime` の間使用不能にする。
*/
def tryUse[U](action: F[U])(recoverTime: FiniteDuration): F[Unit] = {
def tryUse[U](action: F[U], default: => F[U])(recoverTime: FiniteDuration): F[U] = {
// セマフォを`recoverTime` の間使用不能にし、その後解放する作用
val releaseProgram: F[Unit] = Timer[F].sleep(recoverTime) >> semaphore.release

semaphore.tryAcquire.flatMap { acquired =>
if (acquired)
Bracket[F, Throwable]
.guarantee(action) {
releaseProgram.start.as(())
}
.as(())
Bracket[F, Throwable].guarantee(action) {
releaseProgram.start.as(())
}
else
Monad[F].unit
default
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ import java.util.UUID
import java.util.logging.LogManager
import scala.collection.mutable
import scala.jdk.CollectionConverters._
import com.github.unchama.seichiassist.subsystems.tradesystems.subsystems.gachatrade.GachaTradeAPI

class SeichiAssist extends JavaPlugin() {

Expand Down Expand Up @@ -442,11 +443,15 @@ class SeichiAssist extends JavaPlugin() {
: subsystems.tradesystems.subsystems.gttosiina.System[IO, ItemStack] =
subsystems.tradesystems.subsystems.gttosiina.System.wired[IO]

private lazy val gachaTradeSystem: Subsystem[IO] = {
private lazy val gachaTradeSystem
: subsystems.tradesystems.subsystems.gachatrade.System[IO, Player, ItemStack] = {
import PluginExecutionContexts.timer

implicit val effectEnvironment: EffectEnvironment = DefaultEffectEnvironment
implicit val gachaPointApi: GachaPointApi[IO, SyncIO, Player] = gachaPointSystem.api
implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] = playerHeadSkinSystem.api

subsystems.tradesystems.subsystems.gachatrade.System.wired[IO, SyncIO]
subsystems.tradesystems.subsystems.gachatrade.System.wired[IO, SyncIO].unsafeRunSync()
}

private lazy val lastQuitSystem: subsystems.lastquit.System[IO] =
Expand Down Expand Up @@ -774,6 +779,8 @@ class SeichiAssist extends JavaPlugin() {
implicit val breakSuppressionPreferenceAPI: BreakSuppressionPreferenceAPI[IO, Player] =
breakSuppressionPreferenceSystem.api
implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] = playerHeadSkinSystem.api
implicit val gachaTradeAPI: GachaTradeAPI[IO, Player, ItemStack] =
gachaTradeSystem.api

val menuRouter = TopLevelRouter.apply
import SeichiAssist.Scopes.globalChatInterceptionScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import com.github.unchama.seichiassist.menus.nicknames.NicknameCombinationMenu
import com.github.unchama.seichiassist.menus.nicknames.NicknameShopMenu
import com.github.unchama.seichiassist.subsystems.tradesystems.subsystems.gachatrade.GachaTradeAPI
import com.github.unchama.seichiassist.menus.trade.GachaTradeFromMineStackMenu
import com.github.unchama.seichiassist.menus.trade.TradeSelector

trait TopLevelRouter[F[_]] {

Expand Down Expand Up @@ -106,7 +109,8 @@ object TopLevelRouter {
gridRegionAPI: GridRegionAPI[IO, Player, Location, World],
breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player],
breakSuppressionPreferenceAPI: BreakSuppressionPreferenceAPI[IO, Player],
playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player]
playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player],
gachaTradeAPI: GachaTradeAPI[IO, Player, ItemStack]
): TopLevelRouter[IO] = new TopLevelRouter[IO] {
import assortedRankingApi._

Expand Down Expand Up @@ -164,6 +168,11 @@ object TopLevelRouter {
implicit lazy val gridTemplateMenuEnv: GridTemplateMenu.Environment =
new GridTemplateMenu.Environment

implicit lazy val gachaTradeSelectorMenuEnv: TradeSelector.Environment =
new TradeSelector.Environment
implicit lazy val gachaTradeFromMineStackMenuEnv: GachaTradeFromMineStackMenu.Environment =
new GachaTradeFromMineStackMenu.Environment

implicit lazy val stickMenuEnv: FirstPage.Environment = new FirstPage.Environment

implicit lazy val ioCanOpenVoteMenu: IO CanOpen VoteMenu.type = _.open
Expand Down Expand Up @@ -212,6 +221,9 @@ object TopLevelRouter {

override implicit lazy val canOpenStickMenu: IO CanOpen FirstPage.type = _.open
override implicit lazy val canOpenAchievementMenu: IO CanOpen AchievementMenu.type = _.open

implicit lazy val canOpenGachaTradeSelectorMenu: IO CanOpen TradeSelector.type = _.open
implicit lazy val canOpenGachaTradeMenu: IO CanOpen GachaTradeFromMineStackMenu = _.open
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.bukkit.ChatColor._
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.{Material, Sound}
import com.github.unchama.seichiassist.menus.trade.TradeSelector

/**
* 木の棒メニュー1ページ目
Expand Down Expand Up @@ -95,6 +96,7 @@ object FirstPage extends Menu {
val ioCanOpenPassiveSkillMenu: IO CanOpen PassiveSkillMenu.type,
val ioCanOpenRankingRootMenu: IO CanOpen RankingRootMenu.type,
val ioCanOpenVoteMenu: IO CanOpen VoteMenu.type,
val ioCanOpenGachaTradeMenu: IO CanOpen TradeSelector.type,
val enderChestAccessApi: AnywhereEnderChestAPI[IO],
val gachaTicketAPI: GachaTicketAPI[IO],
val voteAPI: VoteAPI[IO, Player],
Expand Down Expand Up @@ -636,7 +638,9 @@ object FirstPage extends Menu {
StickMenu.secondPage
)

val gachaPrizeExchangeButton: Button = {
def gachaPrizeExchangeButton(
implicit ioCanOpenGachaTradeSelectorMenu: IO CanOpen TradeSelector.type
): Button = {
val iconItemStack =
new IconItemStackBuilder(Material.NOTE_BLOCK)
.title(s"$YELLOW$UNDERLINE${BOLD}不要ガチャ景品交換システム")
Expand All @@ -658,12 +662,7 @@ object FirstPage extends Menu {
iconItemStack,
LeftClickButtonEffect(
FocusedSoundEffect(Sound.BLOCK_CHEST_OPEN, 1.0f, 0.5f),
openInventoryEffect(
InventoryUtil.createInventory(
size = 6.chestRows,
title = Some(s"$LIGHT_PURPLE${BOLD}交換したい景品を入れてください")
)
)
ioCanOpenGachaTradeSelectorMenu.open(TradeSelector)
)
)
}
Expand Down
Loading