Package net.ess3.api

Interface IItemDb

All Superinterfaces:
IItemDb
All Known Implementing Classes:
AbstractItemDb, FlatItemDb, LegacyItemDb

public interface IItemDb extends IItemDb
Provides access to the current item alias registry, and allows registration of custom item resolvers.
  • Method Details

    • registerResolver

      void registerResolver(Plugin plugin, String name, IItemDb.ItemResolver resolver) throws Exception
      Add an item resolver that is called before looking up the item in the item database.
      Parameters:
      plugin - The owning plugin
      name - The name of the resolver
      resolver - 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

      void unregisterResolver(Plugin plugin, String name) throws Exception
      Remove an item resolver from the given plugin with the given name.
      Parameters:
      plugin - The owning plugin
      name - The name of the resolver
      Throws:
      Exception - If no matching resolver was found
    • isResolverPresent

      boolean isResolverPresent(Plugin plugin, String name)
      Check whether a resolver with a given name from a given plugin has been registered.
      Parameters:
      plugin - The owning plugin
      name - The name of the resolver
      Returns:
      Whether the resolver could be found
    • getResolvers

      Get all registered resolvers.
      Returns:
      A map of all registered resolvers
    • getResolvers

      Map<PluginKey,IItemDb.ItemResolver> getResolvers(Plugin plugin)
      Get all registered resolvers from the given plugin.
      Parameters:
      plugin - The owning plugin
      Returns:
      A map of all matching resolvers
    • getResolver

      IItemDb.ItemResolver getResolver(Plugin plugin, String name)
      Get the resolver function with the given name from the given plugin.
      Parameters:
      plugin - The owning plugin
      name - The name of the resolver
      Returns:
      The resolver function, or null if not found
    • get

      ItemStack get(String name, boolean useResolvers) throws Exception
      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) and IItemDb.get(String, int) should be sufficient. However, if you intend to perform an item lookup inside a IItemDb.ItemResolver implementation, you must call this method with useResolvers as false to prevent recursion.
      Parameters:
      name - Item name to look up in the database
      useResolvers - 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 String serialize(ItemStack itemStack, boolean useResolvers)
      Deprecated.
      This will soon be replaced with a new two-way API. It should not be relied upon by external plugins!
      Converts the given ItemStack 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 serialize
      useResolvers - Whether to call other plugins' item resolvers before looking the item up in the database
      Returns:
      A string representation of the given item stack