Skip to content

Commit

Permalink
Merge pull request #1374 from GiganticMinecraft/develop
Browse files Browse the repository at this point in the history
バージョン 32 リリース
  • Loading branch information
Lucky3028 authored Feb 25, 2022
2 parents 6821901 + bae8f3f commit 253b183
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 85 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.io._
ThisBuild / scalaVersion := "2.13.1"
// ThisBuild / version はGitHub Actionsによって自動更新される。
// 次の行は ThisBuild / version := "(\d*)" の形式でなければならない。
ThisBuild / version := "31"
ThisBuild / version := "32"
ThisBuild / organization := "click.seichi"
ThisBuild / description := "ギガンティック☆整地鯖の独自要素を司るプラグイン"

Expand Down Expand Up @@ -141,6 +141,7 @@ lazy val root = (project in file("."))
"-deprecation",
"-Ypatmat-exhaust-depth", "320",
"-Ymacro-annotations",
"-Ywarn-unused",
),
javacOptions ++= Seq("-encoding", "utf8")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS build_count_rate_limit(
uuid CHAR(36) PRIMARY KEY NOT NULL,
-- 注: DECIMALは(全体の桁数, 小数点以下の桁数)というフォーマットである
available_permission DECIMAL(17, 5) UNSIGNED NOT NULL,
updated_date DATETIME NOT NULL
);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ object RefDictBackedRepositoryDefinition {
RepositoryDefinition.Phased.SinglePhased.withoutTappingAction(initialization, finalization)
}

def usingUuidRefDictWithoutDefault[
F[_] : Monad, Player, R
](refDict: RefDict[F, UUID, R]): RepositoryDefinition.Phased.SinglePhased[F, Player, Option[R]] = {
val initialization: SinglePhasedRepositoryInitialization[F, Option[R]] =
(uuid, _) => refDict
.read(uuid)
.map(PrefetchResult.Success.apply)

val finalization: RepositoryFinalization[F, UUID, Option[R]] =
RepositoryFinalization.withoutAnyFinalization(
(uuid, optR) =>
optR.fold(Monad[F].pure(()))(r => refDict.write(uuid, r))
)

RepositoryDefinition.Phased.SinglePhased.withoutTappingAction(initialization, finalization)
}


def usingUuidRefDict[F[_] : Monad, Player, R](refDict: RefDict[F, UUID, R])
(defaultValue: R): RepositoryDefinition.Phased.SinglePhased[F, Player, R] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cats.effect.concurrent.Ref
import cats.effect.{Concurrent, ConcurrentEffect, IO, Sync, Timer}
import com.github.unchama.generic.ContextCoercion
import com.github.unchama.generic.algebra.typeclasses.OrderedMonus
import com.github.unchama.generic.algebra.typeclasses.OrderedMonus._

import scala.concurrent.duration.FiniteDuration
import scala.ref.WeakReference
Expand All @@ -19,11 +20,12 @@ object FixedWindowRateLimiter {
F[_] : ConcurrentEffect : Timer,
G[_] : Sync : ContextCoercion[*[_], F],
A: OrderedMonus
](maxPermits: A, resetDuration: FiniteDuration): G[RateLimiter[G, A]] = {
](maxPermits: A, resetDuration: FiniteDuration, firstPermits: Option[A] = None): G[RateLimiter[G, A]] = {
val zero = OrderedMonus[A].empty
val initialCount = maxPermits |-| firstPermits.getOrElse(maxPermits)

for {
countRef <- Ref.of[G, A](zero)
countRef <- Ref.of[G, A](initialCount)

rateLimiter = RateLimiter.fromCountRef(countRef)(maxPermits)
refreshPermits = countRef.set(zero).coerceTo[F]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.unchama.generic.ratelimiting

import cats.Functor
import cats.effect.concurrent.Ref
import com.github.unchama.generic.algebra.typeclasses.OrderedMonus

Expand Down Expand Up @@ -34,6 +35,12 @@ trait RateLimiter[F[_], A] {
*/
def requestPermission(a: A): F[A]

/**
* 次にリセットされるまで送っても良いリクエスト量を取得する作用を返す。
* この作用の発火が、送って良いリクエスト量に影響することはない。
* @return [[A]] によって記述される、次にリセットされるまで送っても良いリクエスト量を取得する作用
*/
def peekAvailablePermissions: F[A]
}

object RateLimiter {
Expand All @@ -44,7 +51,7 @@ object RateLimiter {
/**
* 送信したリクエスト数を保持する参照セルの情報を見る [[RateLimiter]] を作成する。
*/
def fromCountRef[F[_], A: OrderedMonus](countRef: Ref[F, A])(maxCount: A): RateLimiter[F, A] =
def fromCountRef[F[_]: Functor, A: OrderedMonus](countRef: Ref[F, A])(maxCount: A): RateLimiter[F, A] =
new RateLimiter[F, A] {
override protected val A: OrderedMonus[A] = implicitly

Expand All @@ -53,6 +60,8 @@ object RateLimiter {
val newCount = (count |+| a) min maxCount
(newCount, newCount |-| count)
}

override def peekAvailablePermissions: F[A] = countRef.get.map(maxCount |-| _)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ object HasUuid {

def apply[T](implicit ev: HasUuid[T]): HasUuid[T] = ev

implicit val trivial: HasUuid[UUID] = x => x

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.github.unchama.seichiassist.MaterialSets.BlockBreakableBySkill
import com.github.unchama.seichiassist.SeichiAssist.seichiAssistConfig
import com.github.unchama.seichiassist.bungee.BungeeReceiver
import com.github.unchama.seichiassist.commands._
import com.github.unchama.seichiassist.commands.legacy.{DonationCommand, GachaCommand, VoteCommand}
import com.github.unchama.seichiassist.commands.legacy.{DonationCommand, GachaCommand}
import com.github.unchama.seichiassist.concurrent.PluginExecutionContexts
import com.github.unchama.seichiassist.concurrent.PluginExecutionContexts.asyncShift
import com.github.unchama.seichiassist.data.player.PlayerData
Expand Down Expand Up @@ -208,6 +208,8 @@ class SeichiAssist extends JavaPlugin() {
implicit val configuration: subsystems.buildcount.application.Configuration =
seichiAssistConfig.buildCountConfiguration

implicit val syncIoClock: Clock[SyncIO] = Clock.create

subsystems.buildcount.System.wired[IO, SyncIO](loggerF).unsafeRunSync()
}

Expand Down Expand Up @@ -508,7 +510,7 @@ class SeichiAssist extends JavaPlugin() {
// コマンドの登録
Map(
"gacha" -> new GachaCommand(),
"vote" -> new VoteCommand,
"vote" -> VoteCommand.executor,
"donation" -> new DonationCommand,
"map" -> MapCommand.executor,
"ef" -> new EffectCommand(fastDiggingEffectSystem.settingsApi).executor,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.unchama.seichiassist.commands

import cats.data.Kleisli
import cats.effect.IO
import com.github.unchama.contextualexecutor.builder.Parsers
import com.github.unchama.seichiassist.SeichiAssist
import com.github.unchama.seichiassist.commands.contextual.builder.BuilderTemplates.playerCommandBuilder
import com.github.unchama.seichiassist.util.Util
import com.github.unchama.targetedeffect.{TargetedEffect, UnfocusedEffect}
import com.github.unchama.targetedeffect.commandsender.MessageEffect
import org.bukkit.ChatColor.{GREEN, RED, YELLOW}
import org.bukkit.command.{CommandSender, TabExecutor}

object VoteCommand {
sealed trait Operation
case object Record extends Operation

val usageEchoEcexutor: TargetedEffect[CommandSender] = MessageEffect(List(
s"$RED/vote record <プレイヤー名>",
"投票特典配布用コマンドです"
))
val executor: TabExecutor = playerCommandBuilder
.argumentsParsers(
List(
Parsers.fromOptionParser({
case "record" => Some(Record)
case _ => None
}, usageEchoEcexutor),
Parsers.identity
)
)
.execution(context => {
val args = context.args.parsed
val command: Operation = args.head.asInstanceOf
val name: String = args(1).asInstanceOf
command match {
case Record => {
//引数が2つの時の処理
val lowerCasePlayerName = Util.getName(name)
//プレイヤーオンライン、オフラインにかかわらずsqlに送信(マルチ鯖におけるコンフリクト防止の為)
IO {
for {
_ <- MessageEffect(s"$YELLOW${lowerCasePlayerName}の投票特典配布処理開始…")
_ <- UnfocusedEffect {
SeichiAssist.databaseGateway.playerDataManipulator.incrementVotePoint(lowerCasePlayerName)
}
k = if (SeichiAssist.databaseGateway.playerDataManipulator.addChainVote(lowerCasePlayerName)) {
MessageEffect(s"${GREEN}連続投票数の記録に成功")
} else {
MessageEffect(s"${RED}連続投票数の記録に失敗")
}
} yield k
}
}
}
})
.build()
.asNonBlockingTabExecutor()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ class EntityListener(implicit effectEnvironment: EffectEnvironment,
//プレイヤーが整地ワールドに居ない場合終了
if (!player.getWorld.isSeichi) return
val GBTR = new GiganticBerserkTask
GBTR.PlayerKillEnemy(player, entity)
GBTR.PlayerKillEnemy(player)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ class PlayerInventoryListener(implicit effectEnvironment: EffectEnvironment,
} else if (itemstackcurrent.getType == Material.BOOK_AND_QUILL) {
// 投票リンク表示
player.sendMessage(RED.toString + "" + UNDERLINE + "https://minecraft.jp/servers/54d3529e4ddda180780041a7/vote")
player.sendMessage(RED.toString + "" + UNDERLINE + "https://monocraft.net/servers/Cf3BffNIRMERDNbAfWQm")
player.playSound(player.getLocation, Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1f, 1f)
player.closeInventory()
} else if (isSkull && itemstackcurrent.getItemMeta.asInstanceOf[SkullMeta].getOwner == "MHF_ArrowLeft") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package com.github.unchama.seichiassist.subsystems.buildcount

import cats.effect.{ConcurrentEffect, SyncEffect, Timer}
import cats.effect.{Clock, ConcurrentEffect, SyncEffect, Timer}
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.generic.ContextCoercion
import com.github.unchama.generic.effect.concurrent.ReadOnlyRef
import com.github.unchama.generic.ratelimiting.RateLimiter
import com.github.unchama.seichiassist.meta.subsystem.Subsystem
import com.github.unchama.seichiassist.subsystems.buildcount.application.actions.{ClassifyPlayerWorld, IncrementBuildExpWhenBuiltByHand, IncrementBuildExpWhenBuiltWithSkill}
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
import com.github.unchama.seichiassist.subsystems.buildcount.infrastructure.{JdbcBuildAmountDataPersistence, JdbcBuildAmountRateLimitPersistence}
import com.github.unchama.util.logging.log4cats.PrefixedLogger
import io.chrisdavenport.cats.effect.time.JavaTime
import io.chrisdavenport.log4cats.Logger
import org.bukkit.entity.Player
import org.bukkit.event.Listener
Expand All @@ -34,19 +37,21 @@ object System {

def wired[
F[_] : ConcurrentEffect : NonServerThreadContextShift : Timer,
G[_] : SyncEffect : ContextCoercion[*[_], F]
G[_] : SyncEffect : ContextCoercion[*[_], F] : Clock
](rootLogger: Logger[F])
(implicit configuration: Configuration): G[System[F, G]] = {
import com.github.unchama.minecraft.bukkit.actions.SendBukkitMessage._

implicit val expMultiplier: BuildExpMultiplier = configuration.multipliers
implicit val persistence: JdbcBuildAmountDataPersistence[G] = new JdbcBuildAmountDataPersistence[G]()
implicit val rateLimitPersistence: JdbcBuildAmountRateLimitPersistence[G, F] = new JdbcBuildAmountRateLimitPersistence[G, F]()
implicit val logger: Logger[F] = PrefixedLogger[F]("BuildAssist-BuildAmount")(rootLogger)
implicit val javaTimeG: JavaTime[G] = JavaTime.fromClock

for {
rateLimiterRepositoryControls <-
BukkitRepositoryControls.createHandles(
RepositoryDefinition.Phased.SinglePhased.withoutTappingAction(
RepositoryDefinition.Phased.SinglePhased.withoutTappingAction[G, Player, RateLimiter[G, BuildExpAmount]](
RateLimiterRepositoryDefinitions.initialization[F, G],
RateLimiterRepositoryDefinitions.finalization[G, UUID]
)
Expand Down
Loading

0 comments on commit 253b183

Please sign in to comment.