-
Notifications
You must be signed in to change notification settings - Fork 0
G | Creating Custom Events & Behaviors
Sartaj Singh edited this page May 31, 2025
·
2 revisions
- 1. Overview
- 2. What Are Custom Events and Behaviors?
- 3. Registering Custom Event Listeners
- 4. Writing Event Listener Classes
- 5. Integration With FXItems Behaviors
- 6. Common Use Cases
- 7. Troubleshooting & Tips
- 8. See Also
Custom events and behaviors allow you to add new functionality to your plugin or addon, react to in-game events, and extend FXItems in powerful ways.
FXItems lets you register Bukkit/Spigot event listeners and combine them with the FXItems behavior interfaces for complex logic.
-
Custom Event Listeners: Java classes that implement Bukkit’s
Listenerinterface and respond to Minecraft events (e.g., player movement, damage, crafting, etc.). - Behaviors: FXItems-specific logic attached to items or foods, responding to FXItems hooks and events (see E | Advanced: Custom Effects in FXItems).
You can use both systems together for deep integration and advanced features.
Register listeners using the FXItems Registry API:
Registry registry = new RegistryAPI();
registry.registerEvent(
this, // Your plugin instance
MyCustomListener.class // Your class (implements Listener)
);- Place registration in your plugin's
onEnable()or initialization code. - Listeners are active for as long as your plugin is enabled.
If you have many listeners, you can use a reflection-based registrar to auto-register all classes implementing Listener in a given package.
This is similar to behavior auto-registration.
public class PlayerJumpListener implements Listener {
@EventHandler
public void onPlayerJump(PlayerJumpEvent event) {
Player player = event.getPlayer();
player.sendMessage("§aYou jumped!");
// You can run any FXItems API calls here, e.g. give custom items, trigger effects, etc.
}
}- Each method handling an event must be annotated with
@EventHandler. - You can listen to any Bukkit/Spigot event, including custom ones from other plugins.
-
Conditional Logic: Only run code for players holding a specific FXItem.
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); ItemStack held = player.getInventory().getItemInMainHand(); if (CustomItemUtils.isCustomItem(held, "wind_boots")) { player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 40, 1)); } }
- Combining With Behaviors: Call methods on your FXItemBehavior from listeners for cross-feature logic.
- You can use event listeners to trigger FXItems abilities, apply cooldowns, modify mana, give/take items, and more.
- Use utility APIs (
CooldownUtils,ManaUtils, etc.) inside your event handlers for full feature support. - For passive effects (e.g., buffs while an item is in inventory), use
onPassiveinFXItemBehavior(see E | Advanced: Custom Effects in FXItems).
- Granting bonuses when players jump, sprint, or take damage while holding specific items.
- Blocking or customizing vanilla game events (e.g., preventing item drops, canceling teleportation).
- Creating new gameplay mechanics tied to FXItems (e.g., custom triggers, achievements, progression).
- Integrating with other plugins’ custom events.
-
Nothing happens?
- Ensure your class implements
Listenerand your methods use@EventHandler. - Confirm you registered your listener in
onEnable()(or via auto-registration). - Check server logs for errors.
- Ensure your class implements
-
Performance:
- Keep event logic efficient—avoid heavy computation in common events like
PlayerMoveEvent.
- Keep event logic efficient—avoid heavy computation in common events like
-
Conflicts:
- If you override vanilla behavior, test with other plugins for compatibility.
- B | The Registry System: Items, Foods, Commands, Events
- E | Advanced: Custom Effects in FXItems
- I | Utility: CustomItemUtils
- S | Auto-Registration System
- Home
- A | Getting Started & Plugin Overview
- B | The Registry System: Items, Foods, Commands, Events
- C | Creating Custom Items
- D | Creating Custom Foods
- E | Advanced: Custom Effects in FXItems
- F | Creating Custom Commands
- G | Creating Custom Events & Behaviors
- H | Utility: CooldownUtils
- I | Utility: CustomItemUtils
- J | Utility: EffectUtils
- K | Utility: ManaUtils
- L | Utility: OneTimeCraftUtils
- M | Utility: TeleportUtils
- N | Utility: ProjectileUtils
- O | Utility: GammaUtils
- P | Utility: EntitySizeUtils
- Q | FXItems API (com.noctify.API) & Making Addons
- R | Advanced Techniques, Gotchas & FAQ
- S | Auto-Registration System
- T | Migration Guide (v1.1 → v1.2+)
- U | Changelog