DataAddon abstract class is the contract every addon must implement. It declares the required methods that tell Nexus Core how to identify the addon, where to persist data, how to key the cache, and whether to process a given request. All methods are called by the framework; you never invoke them directly from your addon.
Required Abstract Methods
addonId()
protocol field in their packets. Nexus Core uses it to look up the addon in the registry.
addonName()
getDatabase()
As of v1.7.0, the persistence layer supports multiple database adapters.
getDatabase() is interpreted by the active driver for this addon. MongoDB addons using the default data source work without changes.getCollection()
cacheKeyHeaderTag()
{tag}_{idFieldValue}. Use a distinctive, addon-specific prefix to prevent key collisions with other addons.
getCacheTTL()
EX parameter on every SET call. Choosing an appropriate TTL per addon prevents stale data and controls memory consumption in both cache layers.
l1CacheEnabled()
true. Override and return false to bypass L1 entirely; reads will always pass through to Redis L2 first. Use this for large payloads or rarely-accessed data where holding a deserialized copy in memory is not worth the overhead.
handleRequest()
true to allow dispatch to the registered RequestHandler; return false to stop processing and discard the request silently.
source— the ID of the Spigot server that sent the packet (e.g."pvp-1")requestType— the operation being requested (GET_DATA,SET_DATA,REMOVE_DATA, etc.)data— the payload container from the incoming packet
handleRequest() runs synchronously on the inbound processing thread. Keep it fast: perform only lightweight validation. Never call external APIs, sleep, or query a database inside it.Handler Registry (New in v1.6.2)
As of v1.6.2, each request type is handled by a registeredRequestHandler instead of a monolithic method body. Nexus Core calls addon.dispatch(source, type, data) after handleRequest() returns true, routing to the correct handler automatically.
Default Handlers
DataAddon registers the following handlers in its constructor via registerDefaultHandlers():
registerHandler()
super()) to override a default handler or add support for a new request type.
RequestHandler is a functional interface:
supportedRequestTypes()
RequestType values for which a handler is currently registered.
Per-Addon Validation (New in v1.6.1)
OverrideadditionalValidators() to enforce custom message rules for your addon. The validators run after the global security chain (signature, timestamp, nonce) passes, and before handleRequest() is called.
getAdditionalValidationChain() and reused for every subsequent request. See Security for the full MessageValidator interface and ValidationResult API.
NexusJsonDataContainer
NexusJsonDataContainer is the payload wrapper used throughout the request pipeline. It holds the fields from the incoming packet’s data object as a typed key-value map. Key methods:
Complete Example
Related Topics
- Annotations Reference — the
@DbDataModelssyntax and supported types - Security —
MessageValidationChain,MessageValidator, and per-addon validation - Best Practices — ID constants, UUID keys, fast
handleRequest, and more - Request Types — all
RequestTypevalues and their semantics