Handling events


world:
    type: world
    debug: false
    events:
        on internal bukkit event event:com.destroystokyo.paper.event.player.PlayerJumpEvent:
        - invoke <context.reflect_event>.setCancelled(true)

This example shows how to use Denizen-Reflect to work with internal Bukkit events in Denizen scripts. The on internal bukkit event event is a built-in Denizen event that allows you to listen to internal server events directly. With Denizen-Reflect, you can call methods, get any fields, and fully work with the event object, giving you complete control over the event's behavior and access to its data.

For comparison, objects of type JavaReflectedObjectTag, built into Denizen, use raw fields (getDeclaredFields) to provide access to data. Sometimes it can be extremely difficult to find the right field, which may be deeply hidden or protected. Information available in the event documentation may be completely absent from raw fields.

However, reflection via JavaReflectedObjectTag can be useful in some cases, for example, if you need to replace a raw field or access data that is not displayed in the event documentation. Despite its limitations, some raw fields can still be useful for rare or specific tasks.

Denizen-Reflect, on the other hand, solves these limitations: it allows you to work directly with the event object, get any fields, and call methods without restrictions. This makes interacting with internal Bukkit events much more convenient and powerful.

Thus, although Denizen's built-in reflection can be useful in rare or specific cases, for most tasks, especially when full access to the event object and its data is required, it is preferable to use Denizen-Reflect. Well, if you want, you can experiment with raw fields, but in practice, Denizen-Reflect is much more convenient and reliable.


Last updated