Interface ViewResources


public interface ViewResources
Resource manager for an open DocumentView
  • Method Details

    • getModule

      ResourceModule getModule()
      Gets the resource module.
      Returns:
      Resource module
    • getModuleName

      String getModuleName()
      Gets the name of the resource module
      Returns:
      Resource module name
    • getView

      DocumentView getView()
      Gets the document view these resource belong to.
      Returns:
      View
    • resolve

      Parse a URI into a resource path.

      Using the ./ as a path prefix means the path will be relative to the currently open menu file instead of the module's root.

      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      Parameters:
      uri - URI string
      Returns:
      A successful result if the URI was parsed, an erroneous result otherwise.
    • loadBuffer

      Load a string buffer from the getModule().
      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_API_MODULE If the module is not an IoModule.
      ERR_NO_FILE Module threw a NoSuchFileException
      ERR_ACCESS_DENIED Module threw a AccessDeniedException
      ERR_IO_ERROR Module threw an IOException
      Parameters:
      uri - File path
      Returns:
      Successful result, if the buffer was loaded, or an erroneous one
    • loadItemStack

      Result<org.bukkit.inventory.ItemStack, DelphiException> loadItemStack(String uri)
      Loads an item stack from a JSON file.

      Any errors thrown during the method's execution will be caught and returned in the result.

      If the underlying module is not an IoModule then an erroneous result is returned, otherwise IoModule.loadString(ResourcePath) is called, and it attempts to parse JSON from the returned buffer.

      The item is loaded from minecraft's JSON format. Example:

      
       {
         "id": "minecraft:netherite_sword",
         "count": 1,
         "components": {
           "minecraft:enchantments": {
             "levels": {
               "minecraft:sharpness": 5
             }
           }
         }
       } 
      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_API_MODULE If the module is not an IoModule.
      ERR_NO_FILE Module threw a NoSuchFileException
      ERR_ACCESS_DENIED Module threw a AccessDeniedException
      ERR_IO_ERROR Module threw an IOException
      ERR_SYNTAX Failed to parse JSON from file contents
      ERR_SCHEMA_ERROR If the item fails to load from the loaded JSON
      Parameters:
      uri - file path
      Returns:
      Loaded item, or an erroneous result, if the item cannot be loaded for any reason
    • parseItemStack

      Result<org.bukkit.inventory.ItemStack, DelphiException> parseItemStack(String json)
      Loads an item stack from the specified JSON string.

      Any errors thrown during the method's execution will be caught and returned in the result.

      The item is loaded from minecraft's JSON format. Example:

      
       {
         "id": "minecraft:netherite_sword",
         "count": 1,
         "components": {
           "minecraft:enchantments": {
             "levels": {
               "minecraft:sharpness": 5
             }
           }
         }
       } 
      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_SYNTAX Failed to parse JSON from file contents
      ERR_SCHEMA_ERROR If the item fails to load from the loaded JSON
      Parameters:
      json - Item JSON data
      Returns:
      Loaded item, or an erroneous result, if the item cannot be loaded for any reason
    • loadDocument

      Result<Document, DelphiException> loadDocument(String uri)
      Attempts to load a document from the specified resource path.

      Any errors thrown during the method's execution will be caught and returned in the result.

      If getModule() is a IoModule then this method attempts to use the IoModule.loadString(ResourcePath) to load the document's XML content. If the underlying module is a ApiModule, then ApiModule.loadDocument(ResourcePath, DocumentContext) is called.

      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_MODULE_ERROR If getModule() is an ApiModule and it returned an erroneous result.
      ERR_NO_FILE Module threw a NoSuchFileException
      ERR_ACCESS_DENIED Module threw a AccessDeniedException
      ERR_IO_ERROR Module threw an IOException
      ERR_SAX_PARSER_INIT Failed to instantiate SAX parser to parse the XML document.
      ERR_DOC_PARSE Unrecoverable failure trying to parse the XML data
      ERR_MISSING_PLUGINS One or more of the document's required plugins are missing.The returned exception's message will contain a comma separated list of plugins that it failed to find.
      ERR_UNKNOWN An unknown error caused the document parser to return a null document
      Parameters:
      uri - file path
      Returns:
      Loaded document, or an erroneous result if the document cannot be loaded for any reason.
    • loadStylesheet

      Result<Stylesheet, DelphiException> loadStylesheet(String uri)
      Attempts to load a stylesheet from the specified resource path.

      Any errors thrown during the method's execution will be caught and an erroneous result returned.

      If getModule() is a IoModule then this method attempts to use the IoModule.loadString(ResourcePath) to load the stylesheet. If the underlying module is a ApiModule, then an erroneous result is returned.

      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_API_MODULE The underlying module is an ApiModule, stylesheet loading not supported.
      ERR_NO_FILE Module threw a NoSuchFileException
      ERR_ACCESS_DENIED Module threw a AccessDeniedException
      ERR_IO_ERROR Module threw an IOException
      ERR_SYNTAX Unrecoverable failure trying to parse the stylesheet data.
      Parameters:
      uri - file path
      Returns:
      Loaded stylesheet, or an empty result if the stylesheet could not be loaded for any reason
      See Also:
    • loadComponent

      Result<net.kyori.adventure.text.Component, DelphiException> loadComponent(@NotNull @NotNull String uri, @Nullable @Nullable ViewResources.ComponentFormat format)
      Attempts to load a chat component.

      Any errors thrown during the methods execution will be caught and an erroneous result returned.

      If getModule() is a IoModule then this method attempts to use the IoModule.loadString(ResourcePath) to load the chat component. If the underlying module is a ApiModule, then an erroneous result is returned.

      Result errors
      Error code Description
      ERR_INVALID_PATH The uri could not be parsed into a resource path.
      ERR_API_MODULE The underlying module is an ApiModule, stylesheet loading not supported.
      ERR_NO_FILE Module threw a NoSuchFileException
      ERR_ACCESS_DENIED Module threw a AccessDeniedException
      ERR_IO_ERROR Module threw an IOException
      ERR_SYNTAX Unrecoverable failure trying to parse the component data.
      ERR_SCHEMA_ERROR Only thrown when reading JSON, means the JSON is incorrect.
      Parameters:
      uri - Path to the component data.
      format - Format to load from, if null, uses ViewResources.ComponentFormat.JSON
      Returns:
      Loaded component, or an empty resul, if the component couldn't be loaded for any reason.
    • parseComponent

      Result<net.kyori.adventure.text.Component, DelphiException> parseComponent(@NotNull @NotNull String data, @Nullable @Nullable ViewResources.ComponentFormat format)
      Parses the specified data string into a component.

      Any errors thrown during the methods execution will be caught and an erroneous result returned.

      Result errors
      Error code Description
      ERR_SYNTAX Unrecoverable failure trying to parse the component data.
      ERR_SCHEMA_ERROR Only thrown when reading JSON, means the JSON is incorrect.
      Parameters:
      data -
      format -
      Returns: