Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ See [Resources](https://github.com/EndlessCodeGroup/Mimic/blob/develop/mimic-buk
- Added [Jobs Reborn](https://www.spigotmc.org/resources/4216/) levels provider ([#57](https://github.com/EndlessCodeGroup/Mimic/issues/57)).
- Added [Fabled](https://www.spigotmc.org/resources/91913/) levels and classes providers ([#48](https://github.com/EndlessCodeGroup/Mimic/issues/48)): class groups are slots and level tracks.
- Added [ValhallaMMO](https://modrinth.com/plugin/valhallammo) levels provider ([#99](https://github.com/EndlessCodeGroup/Mimic/issues/99)).
- Added [ItemsAdder](https://www.spigotmc.org/resources/73355/) items and blocks providers ([#49](https://github.com/EndlessCodeGroup/Mimic/issues/49)).
IDs are `itemsadder:ruby_sword` for the default `itemsadder` namespace and `itemsadder:my_items/ruby_sword` for others.
**Changed:** The `ia` items registry provided by ItemsAdder itself is not available via Items API, Mimic warns about it.
Use `itemsadder:ruby_sword` instead of `ia:itemsadder:ruby_sword`.
- MMOCore and Heroes support Levels and Classes API natively: class and profession levels, class slots and subclasses.
This fixes class IDs in MMOCore ([#78](https://github.com/EndlessCodeGroup/Mimic/issues/78)) and reporting class history as classes in Heroes ([#79](https://github.com/EndlessCodeGroup/Mimic/issues/79)).
- Fixed MMOCore experience to reach a level in the deprecated `LevelSystem` API ([#76](https://github.com/EndlessCodeGroup/Mimic/issues/76)).
Expand Down
4 changes: 2 additions & 2 deletions MODRINTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ 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¹ |
| **Blocks** | Vanilla blocks, CraftEngine |
| **Items** | Vanilla items, CraftEngine, MMOItems, CustomItems, ItemsAdder, RPGInventory¹ |
| **Blocks** | Vanilla blocks, CraftEngine, ItemsAdder |
| **Inventory** | Vanilla inventory, RPGInventory¹ |

¹ Support is provided by the plugin itself.
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"
itemsadder = "4.0.17"

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-itemsadder = { module = "beer.devs:itemsadder-api", version.ref = "itemsadder" }

# 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-itemsadder",
]
2 changes: 1 addition & 1 deletion mimic-bukkit-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ The path may contain lowercase letters, digits, `.`, `_`, `-` and `/`.
- **Resources:** the namespace is required, see [Resource IDs](#resource-ids).

> The deprecated `ItemsRegistry` API still searches an item ID without namespace, or with the `mimic` namespace, over all plugins.
> It also accepts item IDs with uppercase letters (`minecraft:DIAMOND_SWORD`), with more than one `:` (`ia:itemsadder:ruby_sword`)
> It also accepts item IDs with uppercase letters (`minecraft:DIAMOND_SWORD`), with more than one `:` (`craftengine:default:palm_log`)
> and MMOItems IDs without item type (`mmoitems:excalibur`), but logs a warning.

<details>
Expand Down
9 changes: 7 additions & 2 deletions mimic-bukkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ An item given to a player is built by MMOItems for this player.
**ID Format:** `rpginventory:[id]`\
**Payload:** *Not supported*

#### [ItemsAdder] _(deprecated API)_
#### [ItemsAdder]

**ID Format:** `ia:[id]`\
**ID Format:** `itemsadder:[id]` for the default `itemsadder` namespace, `itemsadder:[namespace]/[id]` for others\
**Payload:** *Not supported*

### [Block Providers][BlockProvider]
Expand All @@ -138,6 +138,11 @@ A block belongs to the provider with the highest priority that recognizes it, va
**ID Format:** `craftengine:[namespace]/[id]`\
**State:** Block state properties, for example `[facing=north]`

#### [ItemsAdder]

**ID Format:** `itemsadder:[id]` for the default `itemsadder` namespace, `itemsadder:[namespace]/[id]` for others\
**State:** *Not supported*

[minecraft-exp]: https://minecraft.fandom.com/wiki/Experience
[minecraft-inv]: https://minecraft.fandom.com/wiki/Inventory
[item-components]: https://minecraft.wiki/w/Data_component_format
Expand Down
2 changes: 2 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",
"ItemsAdder",
)
}

Expand Down Expand Up @@ -109,6 +110,7 @@ dependencies {
testImplementation(libs.rpgplugins.mythiclib) { isTransitive = false }
testImplementation(libs.rpgplugins.fabled) { isTransitive = false }
testImplementation(libs.rpgplugins.codex) { isTransitive = false }
testImplementation(libs.rpgplugins.itemsadder)
}

kotlin {
Expand Down
11 changes: 10 additions & 1 deletion mimic-bukkit/src/main/kotlin/MimicImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ru.endlesscode.mimic.blocks.Blocks
import ru.endlesscode.mimic.blocks.WrappedBlockProvider
import ru.endlesscode.mimic.classes.*
import ru.endlesscode.mimic.config.MimicConfig
import ru.endlesscode.mimic.impl.itemsadder.ItemsAdderItemProvider
import ru.endlesscode.mimic.impl.mimic.MimicBlocks
import ru.endlesscode.mimic.impl.mimic.MimicClasses
import ru.endlesscode.mimic.impl.mimic.MimicItems
Expand Down Expand Up @@ -164,7 +165,15 @@ internal class MimicImpl(
val itemsRegistry = itemsRegistries.tryRegister(apiLevel, plugin, priority) {
WrappedItemsRegistry(registry, plugin)
}
if (itemsRegistry != null) {
if (itemsRegistry == null) return null

// Items registry of ItemsAdder isn't bridged, otherwise its items would have two IDs
if (itemsRegistry.id == ItemsAdderItemProvider.REGISTRY_ID) {
Log.w(
"ItemsRegistry 'ia' by $plugin is deprecated and replaced with the 'itemsadder' item provider " +
"built into Mimic. Use 'itemsadder:<item>' instead of 'ia:itemsadder:<item>'."
)
} else {
itemProviders.registerBridge(ItemsRegistryItemProvider(itemsRegistry), plugin, priority) {
"ItemsRegistry '${itemsRegistry.id}' by $plugin uses deprecated ItemsRegistry API, " +
"so its items are available via Items API as '${itemsRegistry.id}:<item>'. " +
Expand Down
7 changes: 7 additions & 0 deletions mimic-bukkit/src/main/kotlin/MimicPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import ru.endlesscode.mimic.impl.heroes.HeroesClassSystem
import ru.endlesscode.mimic.impl.heroes.HeroesLevelProvider
import ru.endlesscode.mimic.impl.heroes.HeroesLevelSystem
import ru.endlesscode.mimic.impl.heroes.HeroesResourceProvider
import ru.endlesscode.mimic.impl.itemsadder.ItemsAdderBlockProvider
import ru.endlesscode.mimic.impl.itemsadder.ItemsAdderItemProvider
import ru.endlesscode.mimic.impl.jobs.JobsLevelProvider
import ru.endlesscode.mimic.impl.mcmmo.McMmoLevelProvider
import ru.endlesscode.mimic.impl.mimic.PermissionsClassSystem
Expand Down Expand Up @@ -148,6 +150,11 @@ public class MimicPlugin : JavaPlugin() {
pluginHooks("ValhallaMMO", "me.athlaeos.valhallammo.ValhallaMMO") {
hookLevels(::ValhallaMmoLevelProvider)
}

pluginHooks("ItemsAdder", "dev.lone.itemsadder.api.CustomBlock") {
hookItems(::ItemsAdderItemProvider)
hookBlocks(::ItemsAdderBlockProvider)
}
}

private fun pluginHooks(name: String, vararg requiredClasses: String, hooks: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT

package ru.endlesscode.mimic.impl.itemsadder

import org.bukkit.block.Block
import org.bukkit.inventory.ItemStack
import ru.endlesscode.mimic.blocks.BlockProvider
import ru.endlesscode.mimic.blocks.DropsConsumer
import ru.endlesscode.mimic.internal.Log

/**
* Block provider for ItemsAdder custom blocks.
* The default `itemsadder` namespace is dropped from block ID, other namespaces become the first path segment:
* `itemsadder:ruby_ore` -> `ruby_ore`, `my_blocks:ruby_ore` -> `my_blocks/ruby_ore`.
* A block has the same ID as the item placing it.
*
* ItemsAdder blocks have no states, so [setBlock] with a state sets nothing.
* Furniture is not a block.
*/
internal class ItemsAdderBlockProvider(
private val itemsAdder: ItemsAdderWrapper = ItemsAdderWrapper(),
) : BlockProvider {

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

override val allBlocks: Collection<String>
get() = itemsAdder.blockIds.map(String::toMimicId)

override fun hasBlock(blockId: String): Boolean = itemsAdder.hasBlock(itemsAdderId(blockId))

override fun getBlockId(block: Block): String? = itemsAdder.getCustomBlock(block)?.namespacedID?.toMimicId()

override fun getBlockIdFromItem(item: ItemStack): String? =
itemsAdder.getCustomBlock(item)?.namespacedID?.toMimicId()

override fun createBlockItem(blockId: String, amount: Int): ItemStack? {
val customBlock = itemsAdder.getCustomBlock(itemsAdderId(blockId)) ?: return null
return customBlock.itemStack.also { it.amount = amount }
}

override fun setBlock(block: Block, blockId: String, state: String?): Boolean {
val itemsAdderId = itemsAdderId(blockId)
if (state != null) {
if (itemsAdder.hasBlock(itemsAdderId)) {
Log.w("[$TAG] Invalid state for block $blockId: $state. ItemsAdder blocks have no states.")
}
return false
}
return itemsAdder.placeBlock(itemsAdderId, block.location)
}

override fun breakBlock(block: Block, tool: ItemStack?, dropsConsumer: DropsConsumer): Boolean {
val customBlock = itemsAdder.getCustomBlock(block) ?: return false

// The block itself is a part of the loot if ItemsAdder drops it on break
val drops = customBlock.getLoot(tool, /* includeSelfBlock = */ true)
if (!customBlock.remove()) return false

for (item in dropsConsumer.consume(drops)) {
block.world.dropItemNaturally(block.location, item)
}
return true
}

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

package ru.endlesscode.mimic.impl.itemsadder

import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import ru.endlesscode.mimic.items.ItemProvider

/**
* Item provider for ItemsAdder custom items.
* The default `itemsadder` namespace is dropped from item ID, other namespaces become the first path segment:
* `itemsadder:ruby_sword` -> `ruby_sword`, `my_items:ruby_sword` -> `my_items/ruby_sword`.
* Takes no payload. ItemsAdder can't create an item for a player, so the player is ignored.
*/
internal class ItemsAdderItemProvider(
private val itemsAdder: ItemsAdderWrapper = ItemsAdderWrapper(),
) : ItemProvider {

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

override val allItems: Collection<String>
get() = itemsAdder.itemIds.map(String::toMimicId)

override fun hasItem(itemId: String): Boolean = itemsAdder.hasItem(itemsAdderId(itemId))

override fun getItemId(item: ItemStack): String? = itemsAdder.getCustomStack(item)?.namespacedID?.toMimicId()

override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? {
val customStack = itemsAdder.getCustomStack(itemsAdderId(itemId)) ?: return null
return customStack.itemStack.also { it.amount = amount }
}

companion object {
const val ID: String = "itemsadder"

/** ID of the items registry provided by ItemsAdder itself. */
const val REGISTRY_ID: String = "ia"
}
}
50 changes: 50 additions & 0 deletions mimic-bukkit/src/main/kotlin/impl/itemsadder/ItemsAdderWrapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT

package ru.endlesscode.mimic.impl.itemsadder

import dev.lone.itemsadder.api.CustomBlock
import dev.lone.itemsadder.api.CustomStack
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.block.Block
import org.bukkit.inventory.ItemStack

/**
* Wraps ItemsAdder static API.
* ItemsAdder loads its data after the server start, its registries are empty until then.
*/
internal class ItemsAdderWrapper {

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

val itemIds: Set<String> get() = CustomStack.getNamespacedIdsInRegistry()
val blockIds: Set<String> get() = CustomBlock.getNamespacedIdsInRegistry()

fun hasItem(id: String): Boolean = CustomStack.isInRegistry(id)
fun hasBlock(id: String): Boolean = CustomBlock.isInRegistry(id)

/** Returns a new instance of the item with the given [id]. */
fun getCustomStack(id: String): CustomStack? = CustomStack.getInstance(id)
fun getCustomStack(item: ItemStack): CustomStack? = CustomStack.byItemStack(item)

/** Returns a new instance of the item placing the block with the given [id]. */
fun getCustomBlock(id: String): CustomBlock? = CustomBlock.getInstance(id)
fun getCustomBlock(item: ItemStack): CustomBlock? = CustomBlock.byItemStack(item)
fun getCustomBlock(block: Block): CustomBlock? = CustomBlock.byAlreadyPlaced(block)

fun placeBlock(id: String, location: Location): Boolean = CustomBlock.place(id, location) != null
}

private const val DEFAULT_NAMESPACE = "itemsadder"

/**
* Converts ItemsAdder ID to Mimic ID: `itemsadder:ruby_ore` -> `ruby_ore`, `my_blocks:ruby_ore` -> `my_blocks/ruby_ore`.
* The `itemsadder` namespace is kept if the ID has `/`, so the first path segment is always a namespace.
*/
internal fun String.toMimicId(): String =
(if ('/' in this) this else removePrefix("$DEFAULT_NAMESPACE:")).replaceFirst(':', '/')

/** Converts Mimic ID to ItemsAdder ID: `ruby_ore` -> `itemsadder:ruby_ore`, `my_blocks/ruby_ore` -> `my_blocks:ruby_ore`. */
internal fun itemsAdderId(id: String): String =
if ('/' in id) id.replaceFirst('/', ':') else "$DEFAULT_NAMESPACE:$id"
8 changes: 8 additions & 0 deletions mimic-bukkit/src/test/kotlin/MimicImplTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ internal class MimicImplTest : BukkitTestBase() {
mimic.items.getAllItems().map { it.asString() } shouldContainExactly listOf("custom:provider_item")
}

@Test
fun `when items registry of ItemsAdder is registered - should not bridge it`() {
mimic.registerItemsRegistry(TestItemsRegistry("ia"), MimicApiLevel.CURRENT, thirdParty, Normal)

mimic.items.getAllItems().shouldBeEmpty()
mimic.getAllItemsRegistries().keys shouldContainExactly listOf("ia")
}

@Test
fun `when plugin is disabled - should unregister its items registries and item providers`() {
mimic.registerItemsRegistry(TestItemsRegistry("legacy"), MimicApiLevel.CURRENT, thirdParty, Normal)
Expand Down
Loading
Loading