Package io.papermc.paper.datapack
Interface DatapackRegistrar
- All Superinterfaces:
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 its own jar is below,
assuming the datapack is included under resources/pack folder:
public class YourPluginBootstrap implements PluginBootstrap {
@Override
public void bootstrap(BootstrapContext 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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceConfigures additional, optional, details about a datapack. -
Method Summary
Modifier and TypeMethodDescriptiondiscoverPack(PluginMeta pluginMeta, URI uri, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedURIwith the id.discoverPack(PluginMeta pluginMeta, Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedPathwith the id.default @Nullable DiscoveredDatapackdiscoverPack(URI uri, String id) Discovers a datapack at the specifiedURIwith the id.discoverPack(URI uri, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedURIwith the id.default @Nullable DiscoveredDatapackdiscoverPack(Path path, String id) Discovers a datapack at the specifiedPathwith the id.discoverPack(Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedPathwith the id.getDiscoveredPack(String name) Gets a discovered datapack by its name.Gets all discovered datapacks.booleanhasPackDiscovered(String name) Checks if a datapack with the specified name has been discovered.booleanremoveDiscoveredPack(String name) Removes a discovered datapack by its name.
-
Method Details
-
hasPackDiscovered
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
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
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
Discovers a datapack at the specifiedURIwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
uri- the location of the packid- 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
@Nullable DiscoveredDatapack discoverPack(URI uri, String id, Consumer<DatapackRegistrar.Configurer> configurer) throws IOException Discovers a datapack at the specifiedURIwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
uri- the location of the packid- 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
Discovers a datapack at the specifiedPathwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
path- the location of the packid- 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
@Nullable DiscoveredDatapack discoverPack(Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) throws IOException Discovers a datapack at the specifiedPathwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
path- the location of the packid- 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 specifiedURIwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
pluginMeta- the plugin which will be the "owner" of this datapackuri- the location of the packid- 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 specifiedPathwith the id.Symlinks obey the
allowed_symlinks.txtin the server root directory.- Parameters:
pluginMeta- the plugin which will be the "owner" of this datapackpath- the location of the packid- 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
-