Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ExecutableItems integration: item provider ([#111](https://github.com/EndlessCodeGroup/Mimic/issues/111)).
ExecutableItems IDs are lowercased: `executableitems:free_hammer`. An item created for a player gets this player as its owner.

## [v0.10.0] (2026-11-15)

### Levels API
Expand Down
2 changes: 1 addition & 1 deletion MODRINTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, ExecutableItems, ItemsAdder¹, RPGInventory¹ |
| **Blocks** | Vanilla blocks, CraftEngine |
| **Inventory** | Vanilla inventory, RPGInventory¹ |

Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fabled = "1.1.0"
codex = "1.2.0"
valhallammo = "premium_1.14.1"
valhallammo-free = "1.10.4"
score = "5.25.3.9"

junit = "6.1.3"
kotest = "6.2.6"
Expand Down Expand Up @@ -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-score = { module = "com.github.Ssomar-Developement:SCore", version.ref = "score" }

# Test dependencies
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
Expand Down Expand Up @@ -92,4 +94,5 @@ rpgplugins = [
"rpgplugins-fabled",
"rpgplugins-codex",
"rpgplugins-valhallammo",
"rpgplugins-score",
]
7 changes: 7 additions & 0 deletions mimic-bukkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ Providers marked with _(deprecated API)_ are provided by the plugin itself via t
**ID Format:** `customitems:[id]`\
**Payload:** *Not supported*

#### [ExecutableItems]

**ID Format:** `executableitems:[id]`, ExecutableItems ID is lowercased and characters not allowed in IDs are replaced with `_`\
**Payload:** *Not supported*\
An item given to a player is built by ExecutableItems with this player as its owner.

#### [MMOItems]

**ID Format:** `mmoitems:[type]/[id]`, for example `mmoitems:sword/excalibur`\
Expand Down Expand Up @@ -150,6 +156,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
[executableitems]: https://www.spigotmc.org/resources/77578/
[auraskills]: https://modrinth.com/plugin/auraskills
[mcmmo]: https://www.spigotmc.org/resources/64348/
[jobs reborn]: https://www.spigotmc.org/resources/4216/
Expand Down
3 changes: 3 additions & 0 deletions mimic-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bukkit {
"Jobs",
"Fabled",
"ValhallaMMO",
"ExecutableItems",
)
}

Expand Down Expand Up @@ -64,6 +65,7 @@ repositories {
maven(url = "https://jitpack.io") {
content {
includeGroup("com.github.Zrips")
includeGroup("com.github.Ssomar-Developement")
}
}
maven(url = "https://repo.travja.dev/releases/") {
Expand Down Expand Up @@ -109,6 +111,7 @@ dependencies {
testImplementation(libs.rpgplugins.mythiclib) { isTransitive = false }
testImplementation(libs.rpgplugins.fabled) { isTransitive = false }
testImplementation(libs.rpgplugins.codex) { isTransitive = false }
testImplementation(libs.rpgplugins.score) { isTransitive = false }
}

kotlin {
Expand Down
5 changes: 5 additions & 0 deletions mimic-bukkit/src/main/kotlin/MimicPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ru.endlesscode.mimic.impl.craftengine.CraftEngineItemProvider
import ru.endlesscode.mimic.impl.craftengine.CraftEngineItemsRegistry
import ru.endlesscode.mimic.impl.customitems.CustomItemsItemProvider
import ru.endlesscode.mimic.impl.customitems.CustomItemsRegistry
import ru.endlesscode.mimic.impl.executableitems.ExecutableItemsItemProvider
import ru.endlesscode.mimic.impl.fabled.FabledClassProvider
import ru.endlesscode.mimic.impl.fabled.FabledLevelProvider
import ru.endlesscode.mimic.impl.fabled.FabledResourceProvider
Expand Down Expand Up @@ -126,6 +127,10 @@ public class MimicPlugin : JavaPlugin() {
hookBlocks(::CraftEngineBlockProvider)
}

pluginHooks("ExecutableItems", "com.ssomar.score.api.executableitems.ExecutableItemsAPI") {
hookItems(::ExecutableItemsItemProvider)
}

pluginHooks("AuraSkills", "dev.aurelium.auraskills.api.AuraSkillsApi") {
hookLevels(::AuraSkillsLevelProvider)
hookResources(::AuraSkillsResourceProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT

package ru.endlesscode.mimic.impl.executableitems

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 ExecutableItems.
* ExecutableItems IDs are lowercased and characters not allowed in item IDs are replaced with `_`:
* `Free_Hammer` -> `free_hammer`.
* If several ExecutableItems 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 built by ExecutableItems with this player as its owner.
*/
internal class ExecutableItemsItemProvider(
private val executableItems: ExecutableItemsWrapper = ExecutableItemsWrapper(),
) : ItemProvider {

private val reportedDuplicates = ConcurrentHashMap.newKeySet<String>()

override val id: String = ID
override val isEnabled: Boolean get() = executableItems.isEnabled

override val allItems: Collection<String>
get() {
val idsByMimicId = executableItems.itemIds.groupBy { it.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("[ExecutableItems] IDs $sameIds have the same Mimic ID '$mimicId', only '$usedId' is used.")
}
}
return idsByMimicId.keys.toList()
}

override fun hasItem(itemId: String): Boolean = findExecutableItemsId(itemId) != null

override fun getItemId(item: ItemStack): String? = executableItems.getItemId(item)?.toMimicId()

override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? {
val executableItemsId = findExecutableItemsId(itemId) ?: return null
return executableItems.createItem(executableItemsId, amount, player)
}

/** Returns ExecutableItems ID for the given [itemId], or `null` if there is no such item. */
private fun findExecutableItemsId(itemId: String): String? =
itemId.takeIf(executableItems::hasItem) ?: executableItems.itemIds.find { it.toMimicId() == itemId }

private fun String.toMimicId(): String = buildString {
for (char in this@toMimicId.lowercase()) append(if (Key.allowedInValue(char)) char else '_')
}

companion object {
const val ID: String = "executableitems"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT

package ru.endlesscode.mimic.impl.executableitems

import com.ssomar.score.api.executableitems.ExecutableItemsAPI
import com.ssomar.score.api.executableitems.config.ExecutableItemsManagerInterface
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import java.util.Optional
import kotlin.jvm.optionals.getOrNull

/** Wraps ExecutableItems static API, which is a part of SCore. All IDs are ExecutableItems IDs. */
internal class ExecutableItemsWrapper {

val isEnabled: Boolean get() = Bukkit.getPluginManager().isPluginEnabled("ExecutableItems")

private val manager: ExecutableItemsManagerInterface get() = ExecutableItemsAPI.getExecutableItemsManager()

val itemIds: List<String> get() = manager.executableItemIdsList

fun hasItem(id: String): Boolean = manager.isValidID(id)
fun getItemId(item: ItemStack): String? = manager.getExecutableItem(item).getOrNull()?.id

/** Creates item with the given [amount]. The [player] becomes the owner of the item if it is given. */
fun createItem(id: String, amount: Int, player: Player?): ItemStack? =
manager.getExecutableItem(id).getOrNull()?.buildItem(amount, Optional.ofNullable(player))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT

package ru.endlesscode.mimic.impl.executableitems

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 org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.ValueSource
import ru.endlesscode.mimic.BukkitTestBase
import kotlin.test.Test

internal class ExecutableItemsItemProviderTest : BukkitTestBase() {

private val itemIds = mutableListOf("Free_Hammer", "Ruby Sword", "ruby_sword", "Ruby_Sword")

private val executableItems: ExecutableItemsWrapper = mockk {
every { itemIds } answers { this@ExecutableItemsItemProviderTest.itemIds }
every { hasItem(any()) } answers { firstArg<String>() in this@ExecutableItemsItemProviderTest.itemIds }
every { getItemId(any()) } returns null
every { createItem(any(), any(), any()) } answers { ItemStack(Material.STICK, secondArg()) }
}

// SUT
private val provider = ExecutableItemsItemProvider(executableItems)

@Test
fun `when get all items - should return converted ids without duplicates`() {
provider.allItems shouldContainExactly listOf("free_hammer", "ruby_sword")
}

@ParameterizedTest
@CsvSource(
"free_hammer, Free_Hammer",
"ruby_sword, ruby_sword",
)
fun `when create item - should use ExecutableItems id`(itemId: String, executableItemsId: String) {
val item = provider.createItem(itemId, amount = 2, player, payload = "ignored")

item?.amount shouldBe 2
verify { executableItems.createItem(executableItemsId, 2, player) }
}

@Test
fun `when create item and ids collide without exact id - should use the first id`() {
itemIds.remove("ruby_sword")

provider.createItem("ruby_sword", amount = 1, player = null, payload = null)

verify { executableItems.createItem("Ruby Sword", 1, null) }
}

@ParameterizedTest
@ValueSource(strings = ["unknown", "free_hammer/extra"])
fun `when create unknown item - should return null`(itemId: String) {
provider.createItem(itemId, amount = 1, player = null, payload = null).shouldBeNull()
}

@ParameterizedTest
@CsvSource(
"free_hammer, true",
"ruby_sword, true",
"unknown, false",
)
fun `when check has item - should return if item exists`(itemId: String, expected: Boolean) {
provider.hasItem(itemId) shouldBe expected
}

@Test
fun `when get item id - should return converted id`() {
every { executableItems.getItemId(any()) } returns "Free_Hammer"

provider.getItemId(ItemStack(Material.STICK)) shouldBe "free_hammer"
}

@Test
fun `when get id of not ExecutableItems item - should return null`() {
provider.getItemId(ItemStack(Material.STICK)).shouldBeNull()
}
}
Loading