From 1a951c6d38889c2e36acfd8401c43a4ec96c5efc Mon Sep 17 00:00:00 2001 From: KisaragiEffective Date: Sun, 1 May 2022 23:41:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=BF=98=E3=82=8C=E5=8E=BB=E3=82=89?= =?UTF-8?q?=E3=82=8C=E3=81=9FRateLimiter=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subsystems/buildcount/System.scala | 23 ++++++++++++++++++- .../IncrementBuildExpWhenBuiltByHand.scala | 9 +++++--- 2 files changed, 28 insertions(+), 4 deletions(-) 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 From 08ec8b4964527ca6214ac6d0e2c189f434bd4f99 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 2 May 2022 08:08:24 +0000 Subject: [PATCH 2/2] [bump] 37 -> 38 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 := "ギガンティック☆整地鯖の独自要素を司るプラグイン"