diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a4e5adc..7d4ee518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,11 @@ See [Blocks](https://github.com/EndlessCodeGroup/Mimic/blob/develop/mimic-bukkit - Config option `disabled-block-registries` is renamed to `disabled-block-providers`, the old value is moved automatically. - `/mimic blocks` requires block IDs with a namespace, `payload` argument of `/mimic blocks set` is renamed to `state`. +### Integrations + +- Added MythicMobs integration: item provider, including items of MythicCrucible ([#38](https://github.com/EndlessCodeGroup/Mimic/issues/38)). + Mythic IDs are lowercased: `mythicmobs:skeletonkingsword`. + ## [v0.10.0] (2026-11-15) ### Levels API diff --git a/MODRINTH.md b/MODRINTH.md index 8c91f29b..e88d64ca 100644 --- a/MODRINTH.md +++ b/MODRINTH.md @@ -20,7 +20,7 @@ That's it. Mimic detects installed RPG plugins automatically. | **Levels** | Vanilla experience, AuraSkills, mcMMO, ValhallaMMO, Jobs Reborn, MMOCore, Heroes, Fabled | | **Classes** | MMOCore, Heroes, Fabled | | **Resources** | Vanilla health, food and air, MMOCore, Heroes, AuraSkills, Fabled | -| **Items** | Vanilla items, CraftEngine, MMOItems, CustomItems, ItemsAdder¹, RPGInventory¹ | +| **Items** | Vanilla items, CraftEngine, MMOItems, CustomItems, MythicMobs, ItemsAdder¹, RPGInventory¹ | | **Blocks** | Vanilla blocks, CraftEngine | | **Inventory** | Vanilla inventory, RPGInventory¹ | diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f864590e..7ea626f9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,7 @@ fabled = "1.1.0" codex = "1.2.0" valhallammo = "premium_1.14.1" valhallammo-free = "1.10.4" +mythicmobs = "5.14.0" junit = "6.1.3" kotest = "6.2.6" @@ -56,6 +57,7 @@ rpgplugins-cmilib = { module = "com.github.Zrips:CMILib", version.ref = "cmilib" rpgplugins-fabled = { module = "studio.magemonkey:fabled", version.ref = "fabled" } rpgplugins-codex = { module = "studio.magemonkey:codex", version.ref = "codex" } rpgplugins-valhallammo = { module = "me.athlaeos:valhallammo-core", version.ref = "valhallammo" } +rpgplugins-mythicmobs = { module = "io.lumine:Mythic-Dist", version.ref = "mythicmobs" } # Test dependencies junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } @@ -92,4 +94,5 @@ rpgplugins = [ "rpgplugins-fabled", "rpgplugins-codex", "rpgplugins-valhallammo", + "rpgplugins-mythicmobs", ] diff --git a/mimic-bukkit/README.md b/mimic-bukkit/README.md index 3e281bc7..bf59b250 100644 --- a/mimic-bukkit/README.md +++ b/mimic-bukkit/README.md @@ -107,6 +107,13 @@ Providers marked with _(deprecated API)_ are provided by the plugin itself via t **Payload:** *Not supported*\ An item given to a player is built by MMOItems for this player. +#### [MythicMobs] + +**ID Format:** `mythicmobs:[id]`, Mythic ID is lowercased and characters not allowed in IDs are replaced with `_`, +for example `mythicmobs:skeletonkingsword`\ +**Payload:** *Not supported*\ +Items of MythicCrucible are supported too. An item given to a player is generated by MythicMobs for this player. + #### [ProRPGItems] _(deprecated API)_ **ID Format:** `prorpgitems:[type]/[id]`\ @@ -150,6 +157,7 @@ A block belongs to the provider with the highest priority that recognizes it, va [rpginventory]: https://www.spigotmc.org/resources/12498/ [itemsadder]: https://www.spigotmc.org/resources/73355/ [craftengine]: https://modrinth.com/plugin/craftengine +[mythicmobs]: https://modrinth.com/plugin/mythicmobs [auraskills]: https://modrinth.com/plugin/auraskills [mcmmo]: https://www.spigotmc.org/resources/64348/ [jobs reborn]: https://www.spigotmc.org/resources/4216/ diff --git a/mimic-bukkit/build.gradle.kts b/mimic-bukkit/build.gradle.kts index 840c3097..7eca32be 100644 --- a/mimic-bukkit/build.gradle.kts +++ b/mimic-bukkit/build.gradle.kts @@ -33,6 +33,7 @@ bukkit { "Jobs", "Fabled", "ValhallaMMO", + "MythicMobs", ) } @@ -76,6 +77,11 @@ repositories { includeGroup("me.athlaeos") } } + maven(url = "https://mvn.lumine.io/repository/maven-public/") { + content { + includeModule("io.lumine", "Mythic-Dist") + } + } aikar() codemc() // Uncomment if you want to get Heroes from maven repo @@ -109,6 +115,7 @@ dependencies { testImplementation(libs.rpgplugins.mythiclib) { isTransitive = false } testImplementation(libs.rpgplugins.fabled) { isTransitive = false } testImplementation(libs.rpgplugins.codex) { isTransitive = false } + testImplementation(libs.rpgplugins.mythicmobs) { isTransitive = false } } kotlin { diff --git a/mimic-bukkit/src/main/kotlin/MimicPlugin.kt b/mimic-bukkit/src/main/kotlin/MimicPlugin.kt index 7f50b192..a436854a 100644 --- a/mimic-bukkit/src/main/kotlin/MimicPlugin.kt +++ b/mimic-bukkit/src/main/kotlin/MimicPlugin.kt @@ -41,6 +41,7 @@ import ru.endlesscode.mimic.impl.mmocore.MmoCoreLevelSystem import ru.endlesscode.mimic.impl.mmocore.MmoCoreResourceProvider import ru.endlesscode.mimic.impl.mmoitems.MmoItemsItemProvider import ru.endlesscode.mimic.impl.mmoitems.MmoItemsRegistry +import ru.endlesscode.mimic.impl.mythicmobs.MythicMobsItemProvider import ru.endlesscode.mimic.impl.valhallammo.ValhallaMmoLevelProvider import ru.endlesscode.mimic.impl.vanilla.* import ru.endlesscode.mimic.internal.Log @@ -126,6 +127,10 @@ public class MimicPlugin : JavaPlugin() { hookBlocks(::CraftEngineBlockProvider) } + pluginHooks("MythicMobs", "io.lumine.mythic.bukkit.MythicBukkit") { + hookItems(::MythicMobsItemProvider) + } + pluginHooks("AuraSkills", "dev.aurelium.auraskills.api.AuraSkillsApi") { hookLevels(::AuraSkillsLevelProvider) hookResources(::AuraSkillsResourceProvider) diff --git a/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsItemProvider.kt b/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsItemProvider.kt new file mode 100644 index 00000000..db6c3d5a --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsItemProvider.kt @@ -0,0 +1,60 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.mythicmobs + +import net.kyori.adventure.key.Key +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.internal.Log +import ru.endlesscode.mimic.items.ItemProvider +import java.util.concurrent.ConcurrentHashMap + +/** + * Item provider for MythicMobs items, including items of MythicCrucible. + * Mythic IDs are lowercased and characters not allowed in item IDs are replaced with `_`: + * `SkeletonKingSword` -> `skeletonkingsword`. + * If several Mythic IDs become the same item ID, the one equal to the item ID is used, otherwise the first one. + * Takes no payload. An item created for a player is generated by MythicMobs for this player. + */ +internal class MythicMobsItemProvider( + private val mythicMobs: MythicMobsWrapper = MythicMobsWrapper(), +) : ItemProvider { + + private val reportedDuplicates = ConcurrentHashMap.newKeySet() + + override val id: String = ID + override val isEnabled: Boolean get() = mythicMobs.isEnabled + + override val allItems: Collection + get() { + val idsByMimicId = mythicMobs.itemIds.groupBy(String::toMimicId) + for ((mimicId, sameIds) in idsByMimicId) { + if (sameIds.size > 1 && reportedDuplicates.add(mimicId)) { + val usedId = if (mimicId in sameIds) mimicId else sameIds.first() + Log.w("[MythicMobs] Items $sameIds have the same Mimic ID '$mimicId', only '$usedId' is used.") + } + } + return idsByMimicId.keys.toList() + } + + override fun hasItem(itemId: String): Boolean = findMythicId(itemId) != null + + override fun getItemId(item: ItemStack): String? = mythicMobs.getItemId(item)?.toMimicId() + + override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? { + val mythicId = findMythicId(itemId) ?: return null + return mythicMobs.createItem(mythicId, amount, player) + } + + private fun findMythicId(itemId: String): String? = + itemId.takeIf(mythicMobs::hasItem) ?: mythicMobs.itemIds.find { it.toMimicId() == itemId } + + companion object { + const val ID: String = "mythicmobs" + } +} + +private fun String.toMimicId(): String = buildString { + for (char in this@toMimicId.lowercase()) append(if (Key.allowedInValue(char)) char else '_') +} diff --git a/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsWrapper.kt b/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsWrapper.kt new file mode 100644 index 00000000..a75eebaa --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/mythicmobs/MythicMobsWrapper.kt @@ -0,0 +1,46 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.mythicmobs + +import io.lumine.mythic.api.items.ItemManager +import io.lumine.mythic.api.mobs.GenericCaster +import io.lumine.mythic.bukkit.BukkitAdapter +import io.lumine.mythic.bukkit.MythicBukkit +import io.lumine.mythic.core.drops.DropMetadataImpl +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +/** + * Wraps MythicMobs API. All IDs are Mythic internal names of items. + * [createItem] builds drop metadata the same way as `/mm items give`, the API has no shortcut for it. + */ +internal class MythicMobsWrapper { + + val isEnabled: Boolean get() = Bukkit.getPluginManager().isPluginEnabled("MythicMobs") + + private val itemManager: ItemManager get() = MythicBukkit.inst().itemManager + + val itemIds: List get() = itemManager.itemNames.toList() + + fun hasItem(id: String): Boolean = itemManager.getItem(id).isPresent + + /** Returns ID of the Mythic item the given [item] was generated from, if this Mythic item still exists. */ + fun getItemId(item: ItemStack): String? { + if (item.isEmpty) return null + return itemManager.getMythicTypeFromItem(item)?.takeIf(::hasItem) + } + + /** Generates item with the given [amount]. The [player], if given, is the caster and the trigger of the drop. */ + fun createItem(id: String, amount: Int, player: Player?): ItemStack? { + val mythicItem = itemManager.getItem(id).orElse(null) ?: return null + val item = if (player != null) { + val mythicPlayer = BukkitAdapter.adapt(player) + mythicItem.generateItemStack(DropMetadataImpl(GenericCaster(mythicPlayer), mythicPlayer), amount) + } else { + mythicItem.generateItemStack(amount) + } + return BukkitAdapter.adapt(item) + } +} diff --git a/mimic-bukkit/src/test/kotlin/impl/mythicmobs/MythicMobsItemProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/mythicmobs/MythicMobsItemProviderTest.kt new file mode 100644 index 00000000..2a66b752 --- /dev/null +++ b/mimic-bukkit/src/test/kotlin/impl/mythicmobs/MythicMobsItemProviderTest.kt @@ -0,0 +1,86 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.mythicmobs + +import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.nulls.shouldBeNull +import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.BukkitTestBase +import kotlin.test.Test + +internal class MythicMobsItemProviderTest : BukkitTestBase() { + + private val mythicMobs: MythicMobsWrapper = mockk { + every { itemIds } returns listOf("ruby", "KingSword") + every { hasItem(any()) } answers { firstArg() in itemIds } + every { getItemId(any()) } returns null + every { createItem(any(), any(), any()) } returns null + every { createItem("ruby", any(), any()) } answers { ItemStack(Material.EMERALD, secondArg()) } + every { createItem("KingSword", any(), any()) } answers { ItemStack(Material.DIAMOND_SWORD, secondArg()) } + } + + // SUT + private val provider = MythicMobsItemProvider(mythicMobs) + + @Test + fun `when get all items - should return lowercased Mythic ids`() { + provider.allItems shouldContainExactly listOf("ruby", "kingsword") + } + + @Test + fun `when check item exists - should find it by converted id`() { + provider.hasItem("ruby") shouldBe true + provider.hasItem("kingsword") shouldBe true + provider.hasItem("unknown") shouldBe false + } + + @Test + fun `when create item - should create it for the player and ignore payload`() { + val item = provider.createItem("kingsword", amount = 2, player, payload = "payload") + + item?.type shouldBe Material.DIAMOND_SWORD + item?.amount shouldBe 2 + verify { mythicMobs.createItem("KingSword", 2, player) } + } + + @Test + fun `when create unknown item - should return null`() { + provider.createItem("unknown", amount = 1, player = null, payload = null).shouldBeNull() + } + + @Test + fun `when get item id - should return converted Mythic id`() { + every { mythicMobs.getItemId(any()) } returns "King Sword" + + provider.getItemId(ItemStack(Material.DIAMOND_SWORD)) shouldBe "king_sword" + } + + @Test + fun `when get id of not Mythic item - should return null`() { + provider.getItemId(ItemStack(Material.EMERALD)).shouldBeNull() + } + + @Test + fun `when Mythic ids become the same - should use the exact one`() { + every { mythicMobs.itemIds } returns listOf("Ruby", "ruby", "RUBY") + + provider.allItems shouldContainExactly listOf("ruby") + provider.createItem("ruby", amount = 1, player = null, payload = null)?.type shouldBe Material.EMERALD + verify { mythicMobs.createItem("ruby", 1, null) } + } + + @Test + fun `when Mythic ids become the same and none is exact - should use the first one`() { + every { mythicMobs.itemIds } returns listOf("Ruby", "RUBY") + every { mythicMobs.createItem("Ruby", any(), any()) } answers { ItemStack(Material.REDSTONE) } + + provider.allItems shouldContainExactly listOf("ruby") + provider.createItem("ruby", amount = 1, player = null, payload = null)?.type shouldBe Material.REDSTONE + } +}