Skip to content

Commit

Permalink
Merge pull request #6 from XiaoJie-150/master
Browse files Browse the repository at this point in the history
增加物品和怪物的注册注销
  • Loading branch information
FxRayHughes authored Jul 29, 2024
2 parents a705d80 + e698e97 commit 246db5e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
39 changes: 39 additions & 0 deletions project/common/src/main/kotlin/ink/ptms/um/Mythic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.io.File

interface Mythic {

Expand Down Expand Up @@ -76,6 +77,44 @@ interface Mythic {
power: Float = 1f,
): Boolean

/**
* 注册物品
*
* @param file 文件
* @param node 节点名
*
* @return 如果物品存在则返回false
*/
fun registerItem(file: File, node: String): Boolean

/**
* 移除已注册物品
*
* @param node 节点名
*
* @return 当不存在物品时,返回false
*/
fun unregisterItem(node: String): Boolean

/**
* 注册怪物
*
* @param file 怪物文件
* @param node 怪物节点名
*
* @return 如果已存在则返回false
*/
fun registerMob(file: File, node: String): Boolean

/**
* 移除已注册的怪物
*
* @param node 节点名
*
* @return 如果不存在则返回false
*/
fun unregisterMob(node: String): Boolean

companion object {

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package ink.ptms.um.impl4

import ink.ptms.um.*
import ink.ptms.um.Mythic
import ink.ptms.um.Skill
import io.lumine.xikage.mythicmobs.MythicMobs
import io.lumine.xikage.mythicmobs.io.MythicConfig
import io.lumine.xikage.mythicmobs.io.MythicLineConfig
import io.lumine.xikage.mythicmobs.items.ItemManager
import io.lumine.xikage.mythicmobs.items.MythicItem
import io.lumine.xikage.mythicmobs.mobs.MobManager
import io.lumine.xikage.mythicmobs.mobs.MythicMob
import io.lumine.xikage.mythicmobs.skills.SkillManager
import io.lumine.xikage.mythicmobs.skills.SkillTrigger
import io.lumine.xikage.mythicmobs.util.MythicUtil
import io.lumine.xikage.mythicmobs.utils.config.file.YamlConfiguration
import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
Expand All @@ -17,7 +21,10 @@ import org.bukkit.inventory.ItemStack
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.util.unsafeLazy
import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.module.nms.getName
import java.io.File
import java.util.concurrent.ConcurrentHashMap

/**
* universal-mythic ink.ptms.um.impl4.Mythic4
Expand All @@ -36,6 +43,8 @@ internal class Mythic4 : Mythic {

val skillManager: SkillManager by unsafeLazy { api.skillManager }

internal val mmList: ConcurrentHashMap<String, MythicMob> = mobManager.getProperty<ConcurrentHashMap<String, MythicMob>>("mmList")!!

override val isLegacy = true

override fun getTargetedEntity(player: Player): LivingEntity? {
Expand Down Expand Up @@ -99,6 +108,33 @@ internal class Mythic4 : Mythic {
return api.apiHelper.castSkill(caster, skillName, trigger, origin, et, lt, power)
}

override fun registerItem(file: File, node: String): Boolean {
return itemManager.registerItem(node, MythicItem(file.name, node, MythicConfig(node, file, YamlConfiguration.loadConfiguration(file))))
}

override fun unregisterItem(node: String): Boolean {
return itemManager.getProperty<ConcurrentHashMap<String, MythicItem>>("items")!!.let {
if (it.contains(node)) {
it.remove(node)
true
} else false
}
}

override fun registerMob(file: File, node: String): Boolean {
return if (!mmList.contains(node)) {
mmList[node] = MythicMob(file.name, node, MythicConfig(node, file, YamlConfiguration.loadConfiguration(file)))
true
} else false
}

override fun unregisterMob(node: String): Boolean {
return if (mmList.contains(node)) {
mmList.remove(node)
true
} else false
}

object Loader {

@Awake(LifeCycle.ENABLE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
package ink.ptms.um.impl5

import ink.ptms.um.*
import ink.ptms.um.Mythic
import ink.ptms.um.Skill
import io.lumine.mythic.api.MythicProvider
import io.lumine.mythic.api.mobs.MythicMob
import io.lumine.mythic.api.skills.SkillTrigger
import io.lumine.mythic.bukkit.MythicBukkit
import io.lumine.mythic.core.config.MythicConfigImpl
import io.lumine.mythic.core.config.MythicLineConfigImpl
import io.lumine.mythic.core.items.MythicItem
import io.lumine.mythic.core.mobs.MobExecutor
import io.lumine.mythic.core.utils.MythicUtil
import org.bukkit.Location
import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.common.LifeCycle
import taboolib.common.platform.Awake
import taboolib.common.util.orNull
import taboolib.library.reflex.Reflex.Companion.getProperty
import taboolib.module.nms.getItemTag
import java.io.File

/**
* universal-mythic ink.ptms.um.impl4.Mythic4
Expand All @@ -29,6 +35,8 @@ internal class Mythic5 : Mythic {
val api: MythicBukkit
get() = MythicProvider.get() as MythicBukkit

val mmList: HashMap<String, MythicMob> = api.mobManager.getProperty<HashMap<String, MythicMob>>("mmList")!!

override val isLegacy = false

override fun getItem(name: String): ink.ptms.um.Item? {
Expand Down Expand Up @@ -91,6 +99,42 @@ internal class Mythic5 : Mythic {
return api.apiHelper.castSkill(caster, skillName, trigger, origin, et, lt, power)
}

override fun registerItem(file: File, node: String): Boolean {
return api.itemManager.registerItem(
node,
MythicItem(null, file, node, MythicConfigImpl(node, file, YamlConfiguration.loadConfiguration(file)))
)
}

override fun unregisterItem(node: String): Boolean {
return api.itemManager.getProperty<HashMap<String, MythicItem>>("items")!!.let {
if (it.containsKey(node)) {
it.remove(node)
true
} else false
}
}

override fun registerMob(file: File, node: String): Boolean {
return if (!mmList.containsKey(node)) {
mmList[node] = io.lumine.mythic.core.mobs.MobType(
MythicBukkit.inst().mobManager,
null,
file,
node,
MythicConfigImpl(node, file, YamlConfiguration.loadConfiguration(file))
)
true
} else false
}

override fun unregisterMob(node: String): Boolean {
return if (mmList.containsKey(node)) {
mmList.remove(node)
true
} else false
}

object Loader {

@Awake(LifeCycle.ENABLE)
Expand Down

0 comments on commit 246db5e

Please sign in to comment.