diff --git a/build.sbt b/build.sbt index e7449cc962..7e9bb80dad 100644 --- a/build.sbt +++ b/build.sbt @@ -8,7 +8,7 @@ import java.io._ ThisBuild / scalaVersion := "2.13.1" // ThisBuild / version はGitHub Actionsによって取得/自動更新される。 // 次の行は ThisBuild / version := "(\d*)" の形式でなければならない。 -ThisBuild / version := "37" +ThisBuild / version := "38" ThisBuild / organization := "click.seichi" ThisBuild / description := "ギガンティック☆整地鯖の独自要素を司るプラグイン" diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/System.scala index acffef1c83..0d7e7b7cb9 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/System.scala @@ -4,9 +4,11 @@ import cats.effect.{Clock, ConcurrentEffect, SyncEffect} import com.github.unchama.concurrent.NonServerThreadContextShift import com.github.unchama.datarepository.KeyedDataRepository import com.github.unchama.datarepository.bukkit.player.BukkitRepositoryControls +import com.github.unchama.datarepository.template.RepositoryDefinition import com.github.unchama.fs2.workaround.fs3.Fs3Topic import com.github.unchama.generic.ContextCoercion import com.github.unchama.generic.effect.concurrent.ReadOnlyRef +import com.github.unchama.generic.ratelimiting.RateLimiter import com.github.unchama.minecraft.actions.OnMinecraftServerThread import com.github.unchama.seichiassist.meta.subsystem.Subsystem import com.github.unchama.seichiassist.subsystems.buildcount.application.actions.{ @@ -14,13 +16,17 @@ import com.github.unchama.seichiassist.subsystems.buildcount.application.actions IncrementBuildExpWhenBuiltByHand, IncrementBuildExpWhenBuiltWithSkill } -import com.github.unchama.seichiassist.subsystems.buildcount.application.application.BuildAmountDataRepositoryDefinition +import com.github.unchama.seichiassist.subsystems.buildcount.application.application.{ + BuildAmountDataRepositoryDefinition, + RateLimiterRepositoryDefinitions +} import com.github.unchama.seichiassist.subsystems.buildcount.application.{ BuildExpMultiplier, Configuration } import com.github.unchama.seichiassist.subsystems.buildcount.bukkit.actions.ClassifyBukkitPlayerWorld import com.github.unchama.seichiassist.subsystems.buildcount.bukkit.listeners.BuildExpIncrementer +import com.github.unchama.seichiassist.subsystems.buildcount.domain.explevel.BuildExpAmount import com.github.unchama.seichiassist.subsystems.buildcount.domain.playerdata.BuildAmountData import com.github.unchama.seichiassist.subsystems.buildcount.infrastructure.{ JdbcBuildAmountDataPersistence, @@ -31,6 +37,8 @@ import io.chrisdavenport.log4cats.ErrorLogger import org.bukkit.entity.Player import org.bukkit.event.Listener +import java.util.UUID + trait System[F[_], G[_]] extends Subsystem[F] { val api: BuildCountAPI[F, G, Player] @@ -58,6 +66,18 @@ object System { val createSystem: F[System[F, G]] = for { buildCountTopic <- Fs3Topic[F, (Player, BuildAmountData)] + rateLimiterRepositoryControls <- + ContextCoercion( + BukkitRepositoryControls.createHandles( + RepositoryDefinition + .Phased + .SinglePhased + .withoutTappingAction[G, Player, RateLimiter[G, BuildExpAmount]]( + RateLimiterRepositoryDefinitions.initialization[G], + RateLimiterRepositoryDefinitions.finalization[G, UUID] + ) + ) + ) buildAmountDataRepositoryControls <- ContextCoercion( @@ -71,6 +91,7 @@ object System { new ClassifyBukkitPlayerWorld[G] implicit val incrementBuildExp: IncrementBuildExpWhenBuiltByHand[G, Player] = IncrementBuildExpWhenBuiltByHand.using( + rateLimiterRepositoryControls.repository, buildAmountDataRepositoryControls.repository, buildCountTopic ) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/application/actions/IncrementBuildExpWhenBuiltByHand.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/application/actions/IncrementBuildExpWhenBuiltByHand.scala index 8f45055e3e..848286499e 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/application/actions/IncrementBuildExpWhenBuiltByHand.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/buildcount/application/actions/IncrementBuildExpWhenBuiltByHand.scala @@ -7,6 +7,7 @@ import com.github.unchama.datarepository.KeyedDataRepository import com.github.unchama.fs2.workaround.fs3.Fs3Topic import com.github.unchama.generic.ContextCoercion import com.github.unchama.generic.effect.EffectExtra +import com.github.unchama.generic.ratelimiting.RateLimiter import com.github.unchama.seichiassist.subsystems.buildcount.application.BuildExpMultiplier import com.github.unchama.seichiassist.subsystems.buildcount.domain.explevel.BuildExpAmount import com.github.unchama.seichiassist.subsystems.buildcount.domain.playerdata.BuildAmountData @@ -34,6 +35,7 @@ object IncrementBuildExpWhenBuiltByHand { F, *[_] ], Player]( + rateLimiterRepository: KeyedDataRepository[Player, RateLimiter[F, BuildExpAmount]], dataRepository: KeyedDataRepository[Player, Ref[F, BuildAmountData]], dataTopic: Fs3Topic[G, (Player, BuildAmountData)] )( @@ -45,10 +47,11 @@ object IncrementBuildExpWhenBuiltByHand { F.ifM(ClassifyPlayerWorld[F, Player].isInBuildWorld(player))( for { - newData <- - dataRepository(player).updateAndGet(_.addExpAmount(by)) + limitedNewData <- rateLimiterRepository(player).requestPermission(by) + incremented <- + dataRepository(player).updateAndGet(_.addExpAmount(limitedNewData)) _ <- EffectExtra.runAsyncAndForget[G, F, Unit] { - dataTopic.publish1((player, newData)).void + dataTopic.publish1((player, incremented)).void } } yield (), F.unit