Interface DatapackRegistrar

All Superinterfaces:
Registrar

@NonExtendable @Experimental @NullMarked public interface DatapackRegistrar extends Registrar
The registrar for datapacks. The event for this registrar is called anytime the game tries to discover datapacks at any of the configured locations. This means that if a datapack should stay available to the server, it must always be discovered whenever this event fires.

An example of a plugin loading a datapack from within it's own jar is below


 public class YourPluginBootstrap implements PluginBootstrap {
     @Override
     public void bootstrap(BoostrapContext context) {
         final LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
         manager.registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> {
             DatapackRegistrar registrar = event.registrar();
             try {
                 final URI uri = Objects.requireNonNull(
                     YourPluginBootstrap.class.getResource("/pack")
                 ).toURI();
                 registrar.discoverPack(uri, "packId");
             } catch (final URISyntaxException | IOException e) {
                 throw new RuntimeException(e);
             }
         });
     }
 }
 
See Also:
  • Method Details

    • hasPackDiscovered

      @Contract(pure=true) boolean hasPackDiscovered(String name)
      Checks if a datapack with the specified name has been discovered.
      Parameters:
      name - the name of the pack
      Returns:
      true if the pack has been discovered
      See Also:
    • getDiscoveredPack

      @Contract(pure=true) DiscoveredDatapack getDiscoveredPack(String name)
      Gets a discovered datapack by its name.
      Parameters:
      name - the name of the pack
      Returns:
      the datapack
      Throws:
      NoSuchElementException - if the pack is not discovered
      See Also:
    • removeDiscoveredPack

      @Contract(mutates="this") boolean removeDiscoveredPack(String name)
      Removes a discovered datapack by its name.
      Parameters:
      name - the name of the pack
      Returns:
      true if the pack was removed
      See Also:
    • getDiscoveredPacks

      Gets all discovered datapacks.
      Returns:
      an unmodifiable map of discovered packs
    • discoverPack

      default @Nullable DiscoveredDatapack discoverPack(URI uri, String id) throws IOException
      Discovers a datapack at the specified URI with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      uri - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs
    • discoverPack

      Discovers a datapack at the specified URI with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      uri - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      configurer - a configurer for extra options
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs
    • discoverPack

      default @Nullable DiscoveredDatapack discoverPack(Path path, String id) throws IOException
      Discovers a datapack at the specified Path with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      path - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs
    • discoverPack

      Discovers a datapack at the specified Path with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      path - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      configurer - a configurer for extra options
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs
    • discoverPack

      @Nullable DiscoveredDatapack discoverPack(PluginMeta pluginMeta, URI uri, String id, Consumer<DatapackRegistrar.Configurer> configurer) throws IOException
      Discovers a datapack at the specified URI with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      pluginMeta - the plugin which will be the "owner" of this datapack
      uri - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      configurer - a configurer for extra options
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs
    • discoverPack

      @Nullable DiscoveredDatapack discoverPack(PluginMeta pluginMeta, Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) throws IOException
      Discovers a datapack at the specified Path with the id.

      Symlinks obey the allowed_symlinks.txt in the server root directory.

      Parameters:
      pluginMeta - the plugin which will be the "owner" of this datapack
      path - the location of the pack
      id - a unique id (will be combined with plugin for the datapacks name)
      configurer - a configurer for extra options
      Returns:
      the discovered datapack (or null if it failed)
      Throws:
      IOException - if any IO error occurs