Custom Registry API
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 3.5k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Description
Is your feature request related to a problem?
A Custom Registry API would allow plugins to share custom data through the use of Custom Registries. Developers would be able to create custom registries via a new RegistryKey.custom method, use it in a RegistryEvent through a RegistryEvents.custom(RegistryKey) method, and access it through RegistryAccess.
While niche, this could help plugins depending on eachother share data between them.
Describe the solution you'd like.
I'm not sure on what the exact semantics should be, what I have here is just a concept, but I would like to propose a new RegistryEvents.custom(RegistryKey) and RegistryKey.custom(NamespacedKey). This would allow you to modify a custom registry introduced by a plugin. If a registry of the name does not already exist, a new one should be transparently created behind the scenes. The custom registries behind the scenes could just be simple HashMap<NamespacedKey, T> where T is the value type of the custom registry.
For an example, let's say a plugin wanted people to allow registering custom items to a Registry<T>. These custom items have a type dedicated to them:
record CustomItem(String name, Material type) {}
A plugin creator could then create a registry for these:
RegistryKey rgk = RegistryKey.custom("plugin:custom_items");
BootstrapContext bctx = /* placeholder */ 0;
bctx.getLifecycleManager().registerEventHandler(RegistryEvents.custom(rgk), ctx -> {
ctx.registry().register(
TypedKey.create(rgk, Key.key("plugin:cool_sword")),
new CustomItem("cool sword", Material.STONE_SWORD)
);
});
Then, another plugin could use the same registry later and register something else into the same custom registry.
bctx.getLifecycleManager().registerEventHandler(RegistryEvents.custom(rgk), ctx -> {
ctx.registry().register(
TypedKey.create(rgk, Key.key("other_plugin:coolest_sword")),
new CustomItem("coolest sword", Material.NETHERITE_SWORD)
);
});
After that, RegistryAccess could be used to access an entry from the new custom registry:
Registry<CustomItem> registry = RegistryAccess.registryAccess().getRegistry(rgk);
// do stuff with registry...
Describe alternatives you've considered.
An alternative is each plugin that wants this kind of interop can offer their own static Map somewhere that maybe even implements the Registry<T> interface. However, this honestly seems sketchy in my opinion since this means each plugin will have their own way of handling this and there is a lack of standardization.
A plugin could also implement the Registry<T> interface themselves, but now no one can access it using RegistryAccess.
Other
I think something to note is that this feature would likely require a dependency on being a Paper Plugin & Paper Plugins interacting with eachother. I'm not sure how big of a problem this is though.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing RegistryKey, RegistryEvents, RegistryAccess, Registry, and TypedKey entry points, along with the Paper Plugin lifecycle mentioned in the proposal. The issue does not define the required semantics or identify tests; first establish the custom-registry lifecycle, typing, access, and plugin-interoperability requirements before implementation can be considered done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100