Skip to content

S | Auto‐Registration System

Sartaj Singh edited this page May 31, 2025 · 1 revision

S | Auto-Registration System


Table of Contents


1. Overview

The Auto-Registration System in FXItems automates the process of registering custom items, foods, commands, and events.
Instead of manually registering each new class, simply placing your content in the correct package will trigger automatic detection and registration at plugin startup.

This system greatly reduces boilerplate and ensures all your content is registered consistently.


2. How Auto-Registration Works

  • FXItems uses the Reflections library to scan specific packages at startup.
  • It looks for classes that implement or extend certain base interfaces (e.g., FXItemDefinition, FXFoodDefinition, CommandExecutor, Listener).
  • When found, instances are created (if needed) and registered with the appropriate registry automatically.
  • This applies to both core plugin content and any addons that follow the structure.

3. Supported Content Types

The following types can be auto-registered:

  • Custom Items (FXItemDefinition):
    Place your custom item classes in the designated item package (usually com.noctify.Custom.ItemAttributes).
  • Custom Foods (FXFoodDefinition, FXFoodBehavior):
    Place your food definitions and behaviors in the food package.
  • Commands (CommandExecutor):
    Place your command classes in the command package.
  • Event Listeners (Listener):
    Place your event classes in the event package.

Note: Check the Getting Started page for the latest package structure.


4. How to Use Auto-Registration

Step-by-step

  1. Create your content class in the correct package (e.g., com.noctify.Custom.ItemAttributes for items).
  2. Extend/implement the correct base type (FXItemDefinition, FXFoodDefinition, etc).
  3. (Optional) Use annotations if your content requires special treatment (see below).
  4. Restart or reload the server. FXItems will auto-detect and register your content at startup.

Example:

package com.noctify.Custom.ItemAttributes;

public class LightningSword extends FXItemDefinition {
    // Define properties, abilities, etc.
}

No manual registration needed!


5. Advanced: Custom Annotations & Patterns

  • For advanced cases, FXItems may allow for custom annotations (e.g., @RegisterAs("MY_CUSTOM_ITEM")) to override detection defaults or provide metadata.
  • If you need to exclude a class from auto-registration, use an @IgnoreRegistration annotation or remove it from the scanned package.
  • Some content (such as legacy or experimental items) can be placed in subpackages that are not scanned if you want to keep them unregistered.

6. Troubleshooting & Gotchas

  • Class not registered?

    • Ensure it's in the right package.
    • Make sure it extends/implements the correct base class/interface.
    • Check for constructor errors—classes must have a no-arg constructor if instantiated automatically.
    • Ensure you have reloaded or restarted the server after adding new content.
  • Duplicate registration?

    • Avoid manual registration and auto-registration for the same class.
    • Remove duplicates from the package or blacklist with annotation if supported.
  • Addon content not registered?

    • Make sure your addon uses the same package conventions, or document/register manually if needed.
  • Performance:

    • Scanning is fast but does happen on startup—avoid extremely large packages with unrelated classes.

7. See Also


Clone this wiki locally