1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

3.4 skript-reflect: Handling events

Discussion in 'skUnity Pages' started by TPGamesNL, Jul 20, 2020.

  1. TPGamesNL

    Supporter Addon Developer Dev Programme

    Joined:
    Jan 20, 2018
    Messages:
    1,500
    Likes Received:
    102
    Medals:
    Listening to events
    You may listen to any Bukkit-based event (including events added by other plugins) by referencing the imported class. For example, if you wanted to listen to org.bukkit.event.entity.EnderDragonChangePhaseEvent:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EnderDragonChangePhaseEvent
    3.  
    4. on EnderDragonChangePhaseEvent:
    5.   # your code

    Some plugins use their own event handling system or do not pass their events through Bukkit's event executor (which is the case with some of Skript's internal events).

    In order to listen to an event, it must extend org.bukkit.event.Event and be executed by Bukkit's event executor.


    You may also listen to multiple events with the same handler. The events do not have to be related, but you should take appropriate precautions if you try to access methods that are available in one event but not in the other. For example, if you want to listen to both org.bukkit.event.entity.ProjectileLaunchEvent and org.bukkit.event.entity.ProjectileHitEvent

    Example:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.ProjectileLaunchEvent
    3.   org.bukkit.event.entity.ProjectileHitEvent
    4.  
    5. on ProjectileLaunchEvent and ProjectileHitEvent:
    6.   # your code
    Using the event expression
    skript-reflect exposes an event expression, allowing you to access event values using reflection.

    Syntax:
    Code (Text):
    1. [the] event
    Example:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EnderDragonChangePhaseEvent
    3.   org.bukkit.entity.EnderDragon$Phase as EnderDragonPhase
    4.  
    5. on EnderDragonChangePhaseEvent:
    6.   if event.getNewPhase() is EnderDragonPhase.CIRCLING:
    7.     event.setNewPhase(EnderDragonPhase.CHARGE_PLAYER)

    The event expression may also be used in normal Skript events.



    Setting a priority level
    The priority level of an event may be set to control when a particular event handler is run relative to other event handlers.

    Example:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EnderDragonChangePhaseEvent
    3.  
    4. on EnderDragonChangePhaseEvent with priority highest:
    5.   # your code
    Any event priorities defined in org.bukkit.event.EventPriority may be used. Lower priority event handlers are run before higher priority event handlers.

    Event priorities:
    Code (Text):
    1. lowest
    2. low
    3. normal
    4. high
    5. highest
    6. monitor

    highest is the highest priority event handler you should use if you are modifying the contents of an event. If you only care about the final result of the event, use monitor.



    Handling cancelled events
    By default, event handlers will not be called if an event is cancelled by a lower priority handler. This behavior can be changed by specifying that the handler should handle all events.

    Example:
    Code (Text):
    1. import:
    2.   org.bukkit.event.block.BlockBreakEvent
    3.  
    4. on all BlockBreakEvent:
    5.   uncancel event
     
    • Informative Informative x 1

Share This Page

Loading...