From e7e4e1cb0215ea5c4add6ec61b7cf025ef5896bc Mon Sep 17 00:00:00 2001 From: Jie <1503745098@qq.com> Date: Sat, 13 Jul 2024 11:38:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=A9=E5=93=81?= =?UTF-8?q?=E5=92=8C=E6=80=AA=E7=89=A9=E7=9A=84=E6=B3=A8=E5=86=8C=E6=B3=A8?= =?UTF-8?q?=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/ink/ptms/um/Mythic.kt | 39 ++++++++++++++++ .../main/kotlin/ink/ptms/um/impl4/Mythic4.kt | 38 ++++++++++++++- .../main/kotlin/ink/ptms/um/impl5/Mythic5.kt | 46 ++++++++++++++++++- 3 files changed, 121 insertions(+), 2 deletions(-) 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..0740b41 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( + MobExecutor(MythicBukkit.inst()), + 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) From e698e974a2ceae58d71a5b622c8e7895d119ce7f Mon Sep 17 00:00:00 2001 From: Jie <1503745098@qq.com> Date: Sat, 13 Jul 2024 21:35:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B7=AE=E7=82=B9=E5=B0=B1=E5=B9=B2?= =?UTF-8?q?=E5=9D=8F=E4=BA=8B=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/ink/ptms/um/impl5/Mythic5.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0740b41..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 @@ -118,7 +118,7 @@ internal class Mythic5 : Mythic { override fun registerMob(file: File, node: String): Boolean { return if (!mmList.containsKey(node)) { mmList[node] = io.lumine.mythic.core.mobs.MobType( - MobExecutor(MythicBukkit.inst()), + MythicBukkit.inst().mobManager, null, file, node,