From b641628c57b855a1be98c575299ac2f1b3059945 Mon Sep 17 00:00:00 2001 From: Kory <6561358+kory33@users.noreply.github.com> Date: Fri, 23 Jul 2021 00:02:40 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=BF=85=E8=A6=81=E3=81=AA=E7=AE=87?= =?UTF-8?q?=E6=89=80=E3=81=ABOnMinecraftServerThread=E3=82=92=E6=B8=A1?= =?UTF-8?q?=E3=81=99=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 2 +- .../listener/PlayerClickListener.scala | 4 +- .../effect/ActiveSkillEffect.scala | 11 ++-- .../effect/arrow/ArrowEffects.scala | 51 +++++++++++-------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index bbd762268c..adcfd64d45 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -187,7 +187,7 @@ class PlayerBlockBreakListener(implicit effectEnvironment: EffectEnvironment, val effectPrograms = for { ((blocks, lavas), chunkIndex) <- multiBreakList.zip(multiLavaList).zipWithIndex - blockChunk = BukkitResources.vanishingBlockSetResource(blocks) + blockChunk = BukkitResources.vanishingBlockSetResource[IO, BlockBreakableBySkill](blocks) } yield { SeichiAssist.instance.lockedBlockChunkScope.useTracked(blockChunk) { blocks => for { diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerClickListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerClickListener.scala index beed9d979e..fb26df2a40 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerClickListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerClickListener.scala @@ -104,10 +104,10 @@ class PlayerClickListener(implicit effectEnvironment: EffectEnvironment, activeSkillAvailability(player).set(true).coerceTo[IO] >> soundEffectAfterCoolDown - val arrowEffect = playerData.skillEffectState.selection.arrowEffect(player) + val arrowEffect = playerData.skillEffectState.selection.arrowEffect effectEnvironment.unsafeRunEffectAsync("スキルのクールダウンの状態を戻す", controlSkillAvailability) - effectEnvironment.unsafeRunEffectAsync("ArrowEffectを非同期で実行する", arrowEffect) + effectEnvironment.unsafeRunEffectAsync("ArrowEffectを非同期で実行する", arrowEffect.run(player)) case _ => } } diff --git a/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/ActiveSkillEffect.scala b/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/ActiveSkillEffect.scala index 106e558639..7d67046830 100644 --- a/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/ActiveSkillEffect.scala +++ b/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/ActiveSkillEffect.scala @@ -25,7 +25,7 @@ import scala.util.Random sealed trait ActiveSkillEffect { val nameOnUI: String - val arrowEffect: TargetedEffect[Player] + def arrowEffect(implicit ioOnMainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] def runBreakEffect(player: Player, usedSkill: ActiveSkill, @@ -39,7 +39,8 @@ object ActiveSkillEffect { object NoEffect extends ActiveSkillEffect { override val nameOnUI: String = "未設定" - override val arrowEffect: TargetedEffect[Player] = ArrowEffects.normalArrowEffect + override def arrowEffect(implicit ioOnMainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = + ArrowEffects.normalArrowEffect override def runBreakEffect(player: Player, usedSkill: ActiveSkill, @@ -171,7 +172,7 @@ sealed abstract class ActiveSkillNormalEffect(stringId: String, /** * エフェクト選択時の遠距離エフェクト */ - lazy val arrowEffect: TargetedEffect[Player] = + override def arrowEffect(implicit ioOnMainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = this match { case Explosion => ArrowEffects.singleArrowExplosionEffect case Blizzard => ArrowEffects.singleArrowBlizzardEffect @@ -246,7 +247,7 @@ sealed abstract class ActiveSkillPremiumEffect(stringId: String, _ <- IO.sleep(period.ticks) _ <- SeichiAssist.instance.magicEffectEntityScope - .useTrackedForSome(BukkitResources.vanishingEntityResource(centerBreak, classOf[Chicken])) { e => + .useTrackedForSome(BukkitResources.vanishingEntityResource[IO, Chicken](centerBreak, classOf[Chicken])) { e => for { _ <- IO { e.playEffect(EntityEffect.WITCH_MAGIC) @@ -270,7 +271,7 @@ sealed abstract class ActiveSkillPremiumEffect(stringId: String, /** * エフェクト選択時の遠距離エフェクト */ - lazy val arrowEffect: TargetedEffect[Player] = + override def arrowEffect(implicit ioOnMainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = this match { case ActiveSkillPremiumEffect.MAGIC => ArrowEffects.singleArrowMagicEffect } diff --git a/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/arrow/ArrowEffects.scala b/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/arrow/ArrowEffects.scala index 311893ab6f..f685b006f2 100644 --- a/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/arrow/ArrowEffects.scala +++ b/src/main/scala/com/github/unchama/seichiassist/seichiskill/effect/arrow/ArrowEffects.scala @@ -2,6 +2,7 @@ package com.github.unchama.seichiassist.seichiskill.effect.arrow import cats.data.Kleisli import cats.effect.{IO, SyncIO} +import com.github.unchama.minecraft.actions.OnMinecraftServerThread import com.github.unchama.seichiassist.SeichiAssist import com.github.unchama.seichiassist.concurrent.PluginExecutionContexts import com.github.unchama.targetedeffect.player.FocusedSoundEffect @@ -24,22 +25,25 @@ object ArrowEffects { implicit val plugin: JavaPlugin = SeichiAssist.instance - val normalArrowEffect: TargetedEffect[Player] = arrowEffect[Arrow]( - ProjectileSpawnConfiguration( - 1.0, - (0.0, 1.6, 0.0) - ), - Some(Sound.ENTITY_ARROW_SHOOT) - ) - - val singleArrowBlizzardEffect: TargetedEffect[Player] = arrowEffect[Snowball]( - ProjectileSpawnConfiguration( - 1.0, - (0.0, 1.6, 0.0) - ), - Some(Sound.ENTITY_SNOWBALL_THROW) - ) - val singleArrowMagicEffect: TargetedEffect[Player] = { + def normalArrowEffect(implicit mainThread: OnMinecraftServerThread[IO]) : TargetedEffect[Player] = + arrowEffect[Arrow]( + ProjectileSpawnConfiguration( + 1.0, + (0.0, 1.6, 0.0) + ), + Some(Sound.ENTITY_ARROW_SHOOT) + ) + + def singleArrowBlizzardEffect(implicit mainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = + arrowEffect[Snowball]( + ProjectileSpawnConfiguration( + 1.0, + (0.0, 1.6, 0.0) + ), + Some(Sound.ENTITY_SNOWBALL_THROW) + ) + + def singleArrowMagicEffect(implicit mainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = { import scala.util.chaining._ val thrownPotionItem = new ItemStack(Material.SPLASH_POTION).tap { itemStack => itemStack.setItemMeta { @@ -60,7 +64,7 @@ object ArrowEffects { ) } - val singleArrowMeteoEffect: TargetedEffect[Player] = + def singleArrowMeteoEffect(implicit mainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = arrowEffect[Arrow]( ProjectileSpawnConfiguration( 1.0, @@ -70,7 +74,7 @@ object ArrowEffects { _.setGlowing(true) ) - val singleArrowExplosionEffect: TargetedEffect[Player] = + def singleArrowExplosionEffect(implicit mainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = arrowEffect[SmallFireball]( ProjectileSpawnConfiguration( 0.4, @@ -79,9 +83,12 @@ object ArrowEffects { Some(Sound.ENTITY_GHAST_SHOOT) ) - def arrowEffect[P <: Projectile : ClassTag](spawnConfiguration: ProjectileSpawnConfiguration, - sound: Option[Sound] = None, - projectileModifier: P => Unit = (_: P) => ()): TargetedEffect[Player] = { + def arrowEffect[ + P <: Projectile : ClassTag + ](spawnConfiguration: ProjectileSpawnConfiguration, + sound: Option[Sound] = None, + projectileModifier: P => Unit = (_: P) => ()) + (implicit mainThread: OnMinecraftServerThread[IO]): TargetedEffect[Player] = { val runtimeClass = implicitly[ClassTag[P]].runtimeClass.asInstanceOf[Class[P]] @@ -117,7 +124,7 @@ object ArrowEffects { * サーバーが停止したときにも開放するためである。 */ _ <- SeichiAssist.instance.arrowSkillProjectileScope - .useTracked(BukkitResources.vanishingEntityResource(spawnLocation, runtimeClass)) { projectile => + .useTracked(BukkitResources.vanishingEntityResource[IO, P](spawnLocation, runtimeClass)) { projectile => modifyProjectile(projectile) >> waitForCollision } } yield ()