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 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:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Configures 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 specifiedURI
with the id.discoverPack
(PluginMeta pluginMeta, Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedPath
with the id.default @Nullable DiscoveredDatapack
discoverPack
(URI uri, String id) Discovers a datapack at the specifiedURI
with the id.discoverPack
(URI uri, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedURI
with the id.default @Nullable DiscoveredDatapack
discoverPack
(Path path, String id) Discovers a datapack at the specifiedPath
with the id.discoverPack
(Path path, String id, Consumer<DatapackRegistrar.Configurer> configurer) Discovers a datapack at the specifiedPath
with the id.getDiscoveredPack
(String name) Gets a discovered datapack by its name.Gets all discovered datapacks.boolean
hasPackDiscovered
(String name) Checks if a datapack with the specified name has been discovered.boolean
removeDiscoveredPack
(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 specifiedURI
with the id.Symlinks obey the
allowed_symlinks.txt
in 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 specifiedURI
with the id.Symlinks obey the
allowed_symlinks.txt
in 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 specifiedPath
with the id.Symlinks obey the
allowed_symlinks.txt
in 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 specifiedPath
with the id.Symlinks obey the
allowed_symlinks.txt
in 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 specifiedURI
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 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 specifiedPath
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 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
-