Package net.ess3.api
Interface IItemDb
- All Superinterfaces:
IItemDb
- All Known Implementing Classes:
AbstractItemDb
,FlatItemDb
,LegacyItemDb
Provides access to the current item alias registry, and allows registration of custom item resolvers.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A service capable of resolving custom item names to items and vice versa, as well as adding extra item names to tab complete suggestions. -
Method Summary
Modifier and TypeMethodDescriptionCreate a stack from the given name with the maximum stack size for that material.getResolver
(Plugin plugin, String name) Get the resolver function with the given name from the given plugin.Get all registered resolvers.getResolvers
(Plugin plugin) Get all registered resolvers from the given plugin.boolean
isResolverPresent
(Plugin plugin, String name) Check whether a resolver with a given name from a given plugin has been registered.void
registerResolver
(Plugin plugin, String name, IItemDb.ItemResolver resolver) Add an item resolver that is called before looking up the item in the item database.Deprecated.This will soon be replaced with a new two-way API.void
unregisterResolver
(Plugin plugin, String name) Remove an item resolver from the given plugin with the given name.Methods inherited from interface com.earth2me.essentials.api.IItemDb
get, get, getFromLegacy, getFromLegacy, getFromLegacyId, getLegacyId, getMatching, isReady, listNames, name, nameList, names, serialize
-
Method Details
-
registerResolver
Add an item resolver that is called before looking up the item in the item database.- Parameters:
plugin
- The owning pluginname
- The name of the resolverresolver
- The resolver accepting a String and returning an ItemStack, or null if none was found- Throws:
Exception
- If a resolver with a conflicting name is found
-
unregisterResolver
Remove an item resolver from the given plugin with the given name.- Parameters:
plugin
- The owning pluginname
- The name of the resolver- Throws:
Exception
- If no matching resolver was found
-
isResolverPresent
Check whether a resolver with a given name from a given plugin has been registered.- Parameters:
plugin
- The owning pluginname
- The name of the resolver- Returns:
- Whether the resolver could be found
-
getResolvers
Map<PluginKey,IItemDb.ItemResolver> getResolvers()Get all registered resolvers.- Returns:
- A map of all registered resolvers
-
getResolvers
Get all registered resolvers from the given plugin.- Parameters:
plugin
- The owning plugin- Returns:
- A map of all matching resolvers
-
getResolver
Get the resolver function with the given name from the given plugin.- Parameters:
plugin
- The owning pluginname
- The name of the resolver- Returns:
- The resolver function, or null if not found
-
get
Create a stack from the given name with the maximum stack size for that material. Note: it is unlikely that external plugins will need to call this method directly. In most cases,IItemDb.get(String)
andIItemDb.get(String, int)
should be sufficient. However, if you intend to perform an item lookup inside aIItemDb.ItemResolver
implementation, you must call this method with useResolvers as false to prevent recursion.- Parameters:
name
- Item name to look up in the databaseuseResolvers
- Whether to call other plugins' resolver functions before looking the item up in the database- Returns:
- The requested item stack with the maximum stack size
- Throws:
Exception
- if the item stack cannot be created
-
serialize
Deprecated.This will soon be replaced with a new two-way API. It should not be relied upon by external plugins!Converts the givenItemStack
to a string representation that can be saved. This is typically used for /createkit but may be used by other plugins for various purposes too.- Parameters:
itemStack
- The stack to serializeuseResolvers
- Whether to call other plugins' item resolvers before looking the item up in the database- Returns:
- A string representation of the given item stack
-