@DbDataModels annotations, controls its own Redis cache key prefix, and can optionally gate or intercept incoming requests via handleRequest(). Splitting your data model into focused addons keeps the orchestration layer modular and easy to maintain.
Creating a DataAddon in Three Steps
1
Extend DataAddon and implement the abstract methods
Create a class that extends
DataAddon and implement five required methods: addonId(), addonName(), getDatabase(), getCollection(), cacheKeyHeaderTag(), and handleRequest(). These tell Nexus Core which MongoDB database and collection to use, how to prefix Redis cache keys, and whether to allow or reject a given request.2
Annotate fields with @DbDataModels
Declare your document fields as class members and annotate each one with
@DbDataModels. Use isId = true on the primary key field (exactly one per addon) and defaultValue on all other fields to specify fallback values for incoming packets that omit them.3
Register the addon on startup
Call
NexusApplication.getInstance().getProtocolHandler().registerAddon(new YourAddon()) during application startup. After registration, Nexus Core automatically routes all matching requests to your addon’s MongoDB collection and Redis keyspace.Complete Example: PlayerStatsAddon
The following addon stores player statistics in theplayer_stats collection inside the nexus_core_db database. It uses the player UUID as the primary key and prefixes Redis cache entries with stats.
Registering the Addon
GET_DATA, SET_DATA, REMOVE_DATA, INCREMENT_DATA, and other request types for protocol ID 100 against the player_stats collection automatically.
Next Steps
DataAddon API Reference
Full reference for every abstract method, the handleRequest lifecycle, and NexusJsonDataContainer.
Annotations Reference
The complete @DbDataModels syntax, supported field types, and validation rules.