Skip to content

Commit

Permalink
fix: Fix animation not play
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed May 23, 2024
1 parent 4098be4 commit b9a5ee1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
*.iws
*.iml
*.ipr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.wheatstudio.animationcontrol.internal.cache

import org.bukkit.ChatColor
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.configuration.file.YamlConfiguration

class AnimationCache(config: FileConfiguration) {
private val animationList: MutableList<AnimationNode> = mutableListOf()
val checkItem: String = config.getString("check-item")
val checkItem: String = ChatColor.translateAlternateColorCodes('&', config.getString("check-item"))
val cooldown: Int = config.getInt("cooldown")

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PlayerListener : Listener {
CacheManager.playerCaches.remove(event.player.name)
}

@EventHandler(ignoreCancelled = true)
@EventHandler
fun onInteract(event: PlayerInteractEvent) {
if (event.action != Action.LEFT_CLICK_AIR && event.action != Action.LEFT_CLICK_BLOCK) {
return
Expand All @@ -49,13 +49,14 @@ class PlayerListener : Listener {
// 更新玩家动作冷却值, 并播放动作
val animationcache: AnimationCache? = CacheManager.animationCaches[it]
animationcache?.let { ac ->
event.isCancelled = true
val diff: Long = System.currentTimeMillis() - cache.animatCooldown
val animationNodes: List<AnimationCache.AnimationNode> = ac.getAnimationList()
if (cache.index >= animationNodes.size || diff > animationNodes[cache.index].connectDuration) {
cache.index = 0
}
val animationNode: AnimationCache.AnimationNode = animationNodes[cache.index]
cache.animatCooldown = System.currentTimeMillis() + (1000L * animationNode.millisecond)
cache.animatCooldown = System.currentTimeMillis() + animationNode.millisecond
// 播放动作
PacketSender.setPlayerAnimation(player, animationNode.animat)
// 调用 MythicMobs 技能
Expand All @@ -70,13 +71,13 @@ class PlayerListener : Listener {
fun onHeldItem(event: PlayerItemHeldEvent) {
val cache: PlayerCache? = CacheManager.playerCaches[event.player.name]
val animation: String? = cache?.currentAnimation
val heldItem: ItemStack? = event.player.inventory.itemInMainHand
val heldItem: ItemStack? = event.player.inventory.getItem(event.newSlot)
animation?.let {
val animationCache: AnimationCache? = CacheManager.animationCaches[animation]
val cooldown: Int = animationCache?.cooldown ?: return
CacheManager.heldCooldown[event.player.name] = System.currentTimeMillis() + (1000L * cooldown)
cache.currentAnimation = null
} ?: also {
} ?: run {
// 判断当前切换的是否为物品
if (heldItem?.type == Material.AIR) {
return
Expand Down

0 comments on commit b9a5ee1

Please sign in to comment.