Repository navigation
Expand file tree
/
Copy pathItemsRegistry.kt
More file actions
65 lines (54 loc) · 2.86 KB
/
Copy pathItemsRegistry.kt
File metadata and controls
65 lines (54 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2020 Osip Fatkullin, EndlessCode Group and contributors
// SPDX-License-Identifier: MIT
package ru.endlesscode.mimic.items
import ru.endlesscode.mimic.MimicService
/**
* Service for getting items by their ID. Also, can be used to match ID with item.
*
* Mimic uses [resource locations](https://minecraft.wiki/w/Resource_location) to identify items,
* where the namespace is the ID of an items registry: `[namespace]:[itemId]`, e.g. `minecraft:acacia_boat`.
* IDs without namespace or with the `mimic:` namespace are searched over all registries.
*
* ### Implementation Notes
*
* Implementations receive and return IDs without the registry namespace:
* lowercase paths of `a-z`, `0-9`, `.`, `_`, `-` and `/`.
* Mapping them to the plugin's own IDs is up to the implementation: `itemsadder:ruby_sword` -> `itemsadder/ruby_sword`.
* Invalid IDs are ignored.
*/
@Deprecated("Use Items API from mimic-bukkit-api instead, it identifies items by their owner and creates them for a player.")
public interface ItemsRegistry<ItemStackT : Any> : MimicService {
/** Returns all known item IDs. */
public val knownIds: Collection<String>
/** Returns `true` if given [item] represented with given [itemId]. */
public fun isSameItem(item: ItemStackT, itemId: String): Boolean = getItemId(item) == itemId
/** Returns `true` if item with given [itemId] exists. */
public fun isItemExists(itemId: String): Boolean
/** Returns ID representing given [item], or `null` if the ID not found in this registry. */
public fun getItemId(item: ItemStackT): String?
/** Returns item by given [itemId], or `null` if the ID not found in this registry. */
public fun getItem(itemId: String): ItemStackT? = getItem(itemId, payload = null, amount = 1)
/**
* Returns item stack with specified [payload] by given [itemId], or `null` if the ID not found in this registry.
*
* If [payload] is not `null`, item will be configured using it.
*/
public fun getItem(itemId: String, payload: Any?): ItemStackT? = getItem(itemId, payload, amount = 1)
/**
* Returns item stack with specified [amount] by given [itemId], or `null` if ID not found in this registry.
*
* If given [amount] is greater than maximum possible, will use maximum possible amount.
* Amount shouldn't be less than `1`.
*/
public fun getItem(itemId: String, amount: Int): ItemStackT? = getItem(itemId, payload = null, amount)
/**
* Returns item stack with specified [amount] and [payload] by given [itemId],
* or `null` if ID not found in this registry.
*
* If given [amount] is greater than maximum possible, will use maximum possible amount.
* Amount shouldn't be less than `1`.
*
* Given [payload] may be used to configure item.
*/
public fun getItem(itemId: String, payload: Any?, amount: Int): ItemStackT?
}