diff --git a/project/common/src/main/kotlin/ink/ptms/um/Mythic.kt b/project/common/src/main/kotlin/ink/ptms/um/Mythic.kt index 4678c7c..03aa3c7 100644 --- a/project/common/src/main/kotlin/ink/ptms/um/Mythic.kt +++ b/project/common/src/main/kotlin/ink/ptms/um/Mythic.kt @@ -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 { @@ -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 diff --git a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/Mythic4.kt b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/Mythic4.kt index 533c3ef..c3dbca2 100644 --- a/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/Mythic4.kt +++ b/project/implementation-v4/src/main/kotlin/ink/ptms/um/impl4/Mythic4.kt @@ -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 @@ -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 @@ -36,6 +43,8 @@ internal class Mythic4 : Mythic { val skillManager: SkillManager by unsafeLazy { api.skillManager } + internal val mmList: ConcurrentHashMap = mobManager.getProperty>("mmList")!! + override val isLegacy = true override fun getTargetedEntity(player: Player): LivingEntity? { @@ -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>("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) diff --git a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/Mythic5.kt b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/Mythic5.kt index a35ea3e..62c2ea6 100644 --- a/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/Mythic5.kt +++ b/project/implementation-v5/src/main/kotlin/ink/ptms/um/impl5/Mythic5.kt @@ -1,14 +1,18 @@ 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 @@ -16,7 +20,9 @@ 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 @@ -29,6 +35,8 @@ internal class Mythic5 : Mythic { val api: MythicBukkit get() = MythicProvider.get() as MythicBukkit + val mmList: HashMap = api.mobManager.getProperty>("mmList")!! + override val isLegacy = false override fun getItem(name: String): ink.ptms.um.Item? { @@ -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>("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)