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.

Other Advanced event handling with skript-mirror

Discussion in 'Tutorials' started by btk5h, Jul 27, 2017.

  1. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    158
    skript-mirror offers robust event support for scripts that need to:
    • listen to events that aren't supported by Skript
    • listen to multiple (even unrelated) events under the same event handler
    • listen to events with a specific priority level

    Listening to custom events
    You can listen to any Bukkit event (even events added by other plugins) using the event's fully qualified name. For example, if you want to listen to org.bukkit.event.entity.EnderDragonChangePhaseEvent
    Code (Skript):
    1. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent":
    2.   # your code
    skript-mirror exposes an event expression, allowing you to get event values using reflection.
    Code (Skript):
    1. on script load:
    2.   import "org.bukkit.entity.EnderDragon$Phase"
    3.  
    4. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent":
    5.   if event.getNewPhase() is {Phase}.CIRCLING!:
    6.     event.setNewPhase({Phase}.CHARGE_PLAYER!);
    Listening to multiple events with the same handler
    You can 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 available in one event but not the other. For example, if you want to listen to both org.bukkit.event.entity.ProjectileLaunchEvent and org.bukkit.event.entity.ProjectileHitEvent
    Code (Skript):
    1. on "org.bukkit.event.entity.ProjectileLaunchEvent" and "org.bukkit.event.entity.ProjectileHitEvent":
    2.   # your code
    Setting a priority level
    You can specify a specific event priority to manually set which order your event handlers run. This allows you to coordinate when your event handlers run with respect to other plugins and other scripts.
    Code (Skript):
    1. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority lowest:
    2.   # your code
    3.  
    4. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority low:
    5.   # your code
    6.  
    7. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority normal:
    8.   # your code
    9.  
    10. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority high:
    11.   # your code
    12.  
    13. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority highest:
    14.   # your code
    15.  
    16. on "org.bukkit.event.entity.EnderDragonChangePhaseEvent" with priority monitor:
    17.   # your code
     
    #1 btk5h, Jul 27, 2017
    Last edited: Jul 27, 2017
    • Like Like x 7
  2. MeHow

    MeHow Active Member

    Joined:
    Feb 6, 2017
    Messages:
    140
    Likes Received:
    13
    Examples and more tutorials please
     
  3. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    154
    Likes Received:
    158
    Adding more examples wouldn't really have any benefits. The existing examples already cover the entirety of the feature. Even if I added more examples, they wouldn't showcase anything that would the documentation clearer.
     
  4. MeHow

    MeHow Active Member

    Joined:
    Feb 6, 2017
    Messages:
    140
    Likes Received:
    13
    So skript-mirror = spigot java?
     
    • Like Like x 1

Share This Page

Loading...