diff --git a/build.sbt b/build.sbt index 58838bfced..9c4b4510a9 100644 --- a/build.sbt +++ b/build.sbt @@ -6,7 +6,7 @@ import java.io._ ThisBuild / scalaVersion := "2.13.1" // ThisBuild / version はGitHub Actionsによって自動更新される。 // 次の行は ThisBuild / version := "(\d*)" の形式でなければならない。 -ThisBuild / version := "10" +ThisBuild / version := "12" ThisBuild / organization := "click.seichi" ThisBuild / description := "ギガンティック☆整地鯖の独自要素を司るプラグイン" diff --git a/src/main/scala/com/github/unchama/datarepository/definitions/SignallingRepositoryDefinition.scala b/src/main/scala/com/github/unchama/datarepository/definitions/SignallingRepositoryDefinition.scala index c4528c71d3..c7fa288528 100644 --- a/src/main/scala/com/github/unchama/datarepository/definitions/SignallingRepositoryDefinition.scala +++ b/src/main/scala/com/github/unchama/datarepository/definitions/SignallingRepositoryDefinition.scala @@ -34,7 +34,7 @@ object SignallingRepositoryDefinition { // - restart the stream when the downstream stream fails // - unsubscribe when the player exits // We should be able to achieve this by returning a CancelToken or something on this flatXmapWithPlayer - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[SignallingRepositoryDefinition]") { stream.map(player -> _).through(publishSink) } } diff --git a/src/main/scala/com/github/unchama/generic/effect/stream/StreamExtra.scala b/src/main/scala/com/github/unchama/generic/effect/stream/StreamExtra.scala index 5873f09fe6..c02789566f 100644 --- a/src/main/scala/com/github/unchama/generic/effect/stream/StreamExtra.scala +++ b/src/main/scala/com/github/unchama/generic/effect/stream/StreamExtra.scala @@ -1,8 +1,8 @@ package com.github.unchama.generic.effect.stream -import cats.Eq import cats.effect.concurrent.Ref -import cats.effect.{Async, Concurrent} +import cats.effect.{Concurrent, Sync} +import cats.{Eq, Monad} import com.github.unchama.generic.Diff import com.github.unchama.minecraft.algebra.HasUuid import fs2.{Chunk, Pull, Stream} @@ -92,17 +92,17 @@ object StreamExtra { /** * 与えられたストリームを、エラーが発生したときに再起動するストリームに変換してコンパイルする。 */ - def compileToRestartingStream[F[_] : Async : ErrorLogger, A](stream: Stream[F, _]): F[A] = { - stream - .handleErrorWith { error => - Stream.eval { - ErrorLogger[F] - .error(error)("fs2.Stream が予期せぬエラーで終了しました。再起動します。") + def compileToRestartingStream[F[_] : Sync : ErrorLogger, A](context: String)(stream: Stream[F, _]): F[A] = { + Monad[F].foreverM { + stream + .handleErrorWith { error => + Stream.eval { + ErrorLogger[F] + .error(error)(s"$context fs2.Stream が予期せぬエラーで終了しました。再起動します。") + } } - } - .repeat - .compile - .drain - .flatMap(_ => Async[F].never[A]) + .compile + .drain + } } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcount/subsystems/notification/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcount/subsystems/notification/System.scala index 9f74000229..e7ae1abeb6 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcount/subsystems/notification/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcount/subsystems/notification/System.scala @@ -18,7 +18,7 @@ object System { ](breakCountReadAPI: BreakCountReadAPI[F, G, Player]) : F[A] = { val action: NotifyLevelUp[F, Player] = BukkitNotifyLevelUp[F] - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[breakcount.notification]") { breakCountReadAPI .seichiLevelUpdates .either(breakCountReadAPI.seichiStarLevelUpdates) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcountbar/application/ExpBarSynchronizationRepositoryTemplate.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcountbar/application/ExpBarSynchronizationRepositoryTemplate.scala index 480df2ed31..fe26524515 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcountbar/application/ExpBarSynchronizationRepositoryTemplate.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakcountbar/application/ExpBarSynchronizationRepositoryTemplate.scala @@ -58,7 +58,7 @@ object ExpBarSynchronizationRepositoryTemplate { _ <- EffectExtra.runAsyncAndForget[F, G, Unit](bossBar.players.add(player)) _ <- EffectExtra.runAsyncAndForget[F, G, Unit] { - StreamExtra.compileToRestartingStream[F, Unit] { + StreamExtra.compileToRestartingStream[F, Unit]("[ExpBarSynchronizationRepositoryTemplate]") { switching.concurrently(synchronization) }.start >>= fiberPromise.complete } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/System.scala index 8448081859..d3fde4ba96 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/System.scala @@ -106,7 +106,7 @@ object System { } _ <- - StreamExtra.compileToRestartingStream[F, Unit] { + StreamExtra.compileToRestartingStream[F, Unit]("[FastDiggingEffect/EffectStatsNotification]") { EffectStatsNotification.using[F, Player](effectListDiffTopic.subscribe(1).mapFilter(identity)) }.start @@ -176,15 +176,15 @@ object System { implicit val api: FastDiggingEffectApi[F, Player] = system.effectApi List( - BreakCountEffectSynchronization.using[F, H, Player], - PlayerCountEffectSynchronization.using[F, Player], - SynchronizationProcess.using[F, Player]( + "BreakCountEffectSynchronization" -> BreakCountEffectSynchronization.using[F, H, Player], + "PlayerCountEffectSynchronization" -> PlayerCountEffectSynchronization.using[F, Player], + "SynchronizationProcess" -> SynchronizationProcess.using[F, Player]( system.settingsApi.currentSuppressionSettings, system.effectApi.effectClock ) - ).traverse( - StreamExtra.compileToRestartingStream(_).start - ) + ).traverse { case (str, stream) => + StreamExtra.compileToRestartingStream(s"[FastDiggingEffect/$str]")(stream).start + } } } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectListRepositoryDefinitions.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectListRepositoryDefinitions.scala index a0b8e8c049..ae6cb4331b 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectListRepositoryDefinitions.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectListRepositoryDefinitions.scala @@ -44,7 +44,7 @@ object EffectListRepositoryDefinitions { val (mutexRef, fiberPromise) = value val programToRun: F[Unit] = - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[EffectListRepositoryDefinitions]") { fs2.Stream .awakeEvery[F](1.second) .evalMap[F, FastDiggingEffectList](_ => ContextCoercion(mutexRef.readLatest)) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectStatsSettingsRepositoryDefinition.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectStatsSettingsRepositoryDefinition.scala index 98e68a8572..0effeb12ff 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectStatsSettingsRepositoryDefinition.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/fastdiggingeffect/application/repository/EffectStatsSettingsRepositoryDefinition.scala @@ -58,7 +58,9 @@ object EffectStatsSettingsRepositoryDefinition { } EffectExtra.runAsyncAndForget[F, G, Unit] { - StreamExtra.compileToRestartingStream(processStream).start >>= fiberPromise.complete + StreamExtra.compileToRestartingStream("[EffectStatsSettingsRepository]") { + processStream + }.start >>= fiberPromise.complete } } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/fourdimensionalpocket/application/PocketInventoryRepositoryDefinition.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/fourdimensionalpocket/application/PocketInventoryRepositoryDefinition.scala index 5ef6e094d5..40fd42e04f 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/fourdimensionalpocket/application/PocketInventoryRepositoryDefinition.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/fourdimensionalpocket/application/PocketInventoryRepositoryDefinition.scala @@ -54,7 +54,8 @@ object PocketInventoryRepositoryDefinition { } EffectExtra.runAsyncAndForget[F, G, Unit] { - StreamExtra.compileToRestartingStream(processStream).start >>= fiberPromise.complete + StreamExtra.compileToRestartingStream("[PocketInventoryRepository]")(processStream).start >>= + fiberPromise.complete } } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachapoint/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachapoint/System.scala index 87ff7a44c2..df2a870de4 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachapoint/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachapoint/System.scala @@ -59,7 +59,7 @@ object System { EffectExtra.runAsyncAndForget[F, G, Unit] { streams - .traverse(StreamExtra.compileToRestartingStream(_).start) + .traverse(StreamExtra.compileToRestartingStream("[GachaPoint]")(_).start) .as(()) } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/halfhourranking/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/halfhourranking/System.scala index 50d9721684..8805bca79a 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/halfhourranking/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/halfhourranking/System.scala @@ -31,7 +31,7 @@ object System { implicit val sendBukkitMessage: SendMinecraftMessage[F, Player] = SendBukkitMessage[F] implicit val broadcastBukkitMessage: BroadcastMinecraftMessage[F] = BroadcastBukkitMessage[F] - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[HalfHourRanking]") { breakCountReadAPI .batchedIncreases(30.minutes) .map(RankingRecord.apply) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/System.scala index 1568e78802..4ca7dea8ef 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/System.scala @@ -49,7 +49,7 @@ object System { _ <- List( UpdateManaCaps.using[F, G, Player](handles.repository), RefillToCap.using[F, G, Player](handles.repository) - ).traverse(StreamExtra.compileToRestartingStream[F, Unit](_).start) + ).traverse(StreamExtra.compileToRestartingStream[F, Unit]("[Mana]")(_).start) } yield new System[F, G, Player] { override val manaApi: ManaApi[F, G, Player] = new ManaApi[F, G, Player] { override val readManaAmount: KeyedDataRepository[Player, G[LevelCappedManaAmount]] = diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/manabar/application/ManaBarSynchronizationRepository.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/manabar/application/ManaBarSynchronizationRepository.scala index a93ff8e560..78278ec8e6 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/manabar/application/ManaBarSynchronizationRepository.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/manabar/application/ManaBarSynchronizationRepository.scala @@ -37,7 +37,7 @@ object ManaBarSynchronizationRepository { val programToRunAsync = bossBar.players.add(player) >> Concurrent[F].start[Nothing] { - StreamExtra.compileToRestartingStream[F, Nothing](synchronization) + StreamExtra.compileToRestartingStream("[ManaBarSynchronization]")(synchronization) } >>= promise.complete EffectExtra.runAsyncAndForget[F, G, Unit](programToRunAsync) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/ranking/application/GenericRefreshingRankingCache.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/ranking/application/GenericRefreshingRankingCache.scala index 6c915f8b05..e5271f9e5c 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/ranking/application/GenericRefreshingRankingCache.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/ranking/application/GenericRefreshingRankingCache.scala @@ -22,7 +22,7 @@ object GenericRefreshingRankingCache { initialRankingRecords <- persistence.getAllRankingRecords rankingRef <- Ref.of(new Ranking(initialRankingRecords)) _ <- - StreamExtra.compileToRestartingStream[F, Unit] { + StreamExtra.compileToRestartingStream[F, Unit]("[GenericRefreshingRankingCache]") { fs2.Stream .awakeEvery[F](30.seconds) .evalMap(_ => persistence.getAllRankingRecords) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupgift/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupgift/System.scala index 5222c69f43..1b3bd6dc47 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupgift/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupgift/System.scala @@ -33,7 +33,7 @@ object System { } } - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[SeichiLevelUpGift]") { breakCountReadApi .seichiLevelUpdates .evalTap { case (player, diff) => interpreter.onLevelDiff(diff).run(player) } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupmessage/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupmessage/System.scala index f31d7c46cd..475fa71e7f 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupmessage/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/seichilevelupmessage/System.scala @@ -14,7 +14,7 @@ object System { G[_], Player ](implicit breakCountReadAPI: BreakCountReadAPI[F, G, Player]): F[Nothing] = { - StreamExtra.compileToRestartingStream { + StreamExtra.compileToRestartingStream("[SeichiLevelUpMessage]") { breakCountReadAPI .seichiLevelUpdates .evalMap { case (player, diff) => diff --git a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala index bfeae97e63..d1decbd78a 100644 --- a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala +++ b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala @@ -20,7 +20,6 @@ import org.bukkit.entity.{Entity, EntityType, Player} import org.bukkit.inventory.ItemStack import org.bukkit.material.Dye -import java.time.LocalDate import java.util.Random import java.util.stream.IntStream @@ -280,14 +279,7 @@ object BreakUtil { def blockCountWeight(world: World): Double = { val managedWorld = ManagedWorld.fromBukkitWorld(world) val seichiWorldFactor = if (managedWorld.exists(_.isSeichi)) 1.0 else 0.0 - val sw01Penalty = - if (managedWorld.contains(ManagedWorld.WORLD_SW)) { - // 5周年記念企画のうち21億チャレンジ用の条件分岐 - // TODO: 終わったら消去する - if (LocalDate.now().isEqual(LocalDate.of(2021, 7, 22))) 2.5 - else 0.8 - } - else 1.0 + val sw01Penalty = if (managedWorld.contains(ManagedWorld.WORLD_SW)) 0.8 else 1.0 seichiWorldFactor * sw01Penalty } diff --git a/src/main/scala/com/github/unchama/seichiassist/util/Util.scala b/src/main/scala/com/github/unchama/seichiassist/util/Util.scala index 803ea24ff1..f95751edcd 100644 --- a/src/main/scala/com/github/unchama/seichiassist/util/Util.scala +++ b/src/main/scala/com/github/unchama/seichiassist/util/Util.scala @@ -300,12 +300,12 @@ object Util { if (itemstack.getAmount == count) { // アイテムをcount個使うので、プレイヤーの手を素手にする inventory.setItemInMainHand(new ItemStack(Material.AIR)) + true } else if (itemstack.getAmount > count) { // プレイヤーが持っているアイテムをcount個減らす itemstack.setAmount(itemstack.getAmount - count) - } else - return itemstack.getAmount >= count - true + true + } else false } def itemStackContainsOwnerName(itemstack: ItemStack, name: String): Boolean = {