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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

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

Detect on breath meter change?

Discussion in 'Skript' started by SuperEpps22556, Sep 5, 2022.

Thread Status:
Not open for further replies.
  1. SuperEpps22556

    Joined:
    Oct 3, 2017
    Messages:
    17
    Likes Received:
    2
    I've been searching over documents, forums, and across the internet but I can't seem to find any answer anywhere. Is there an event to detect when a player's breath meter changes? I currently have Skript 2.6.3, SkQuery 4.1.7, and Skellet 2.0.7. If I need another addon, I have no issues using it!
    I'd love to know if there's a way through the addons or plain Skript to do something along the lines of:
    Code (Text):
    1. on [event needing meter change]:
    2.     [do code]
     
  2. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    with skript-reflect:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EntityAirChangeEvent
    3. on EntityAirChangeEvent:
    4.   broadcast "%event.getAmount()%" # current amount of air
    5.   broadcast "%event.setAmount(100)%" # Sets the amount of air remaining for the entity (measured in ticks.)
    6.   broadcast "%event.getEntity()%" # what entity called event
     
    #2 lotzy, Sep 5, 2022
    Last edited: Sep 5, 2022
  3. SuperEpps22556

    Joined:
    Oct 3, 2017
    Messages:
    17
    Likes Received:
    2
    I have skript reflect installed and working properly, but I haven't done much of minecraft java to understand it. I can't find the solution and the documents give no information on how to use it. I ran that code to make sure it works and it spams the chat with every single squid spawned in the game. No idea how to check for permissions/variables on a player and not just all enities. I need an effect for a player under water possibly without using a periodic timer
     
  4. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    139
    Likes Received:
    22
    Let's basics, in my code I imported some class - org.bukkit.event.entity.EntityAirChangeEvent
    Reflect allows us using 'on EntityAirChangeEvent' if class what we are using is Bukkit event. This class is Bukkit event because inherited from org.bukkit.event.Event
    spigot docs link

    upload_2022-9-6_1-2-52.png

    Lets go deeper:
    This event has many functions inside named 'methods'
    upload_2022-9-6_1-4-22.png
    Its like skript functions, but with java types. Reflect allow use Skript types as java types (auto convert)
    For example:
    method .setAmount(int amount) can be used as:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EntityAirChangeEvent
    3. on EntityAirChangeEvent:
    4.   event.setAmount(5)
    Class EntityAirChangeEvent also have methods inherited from parent classes:
    upload_2022-9-6_1-8-42.png
    In our case we need exclude all entities but player
    Lets check what doing method .getEntityType()
    upload_2022-9-6_1-9-21.png

    Its return EntityType, so we need get EntityType object for our compare, lets check what is EntityType:
    upload_2022-9-6_1-10-43.png
    Enum is something like constant values, like list with text index in Skript but cant be changed.
    For example EntityType.BAT return BAT type , but we need player, lets find: CTRL+F -> player
    upload_2022-9-6_1-13-21.png
    Okey, we can get EntityType.PLAYER, we have needed event, we have method to get EntityType of entity in event:
    Code (Text):
    1. import:
    2.   org.bukkit.event.entity.EntityAirChangeEvent
    3.   org.bukkit.entity.EntityType
    4. on EntityAirChangeEvent:
    5.   if event.getEntityType() is EntityType.PLAYER:
    6.     set {_player} to event.getEntity()
    7.     broadcast "Its player: %{_player}%!!!"
     
    #4 lotzy, Sep 5, 2022
    Last edited: Sep 5, 2022
Thread Status:
Not open for further replies.

Share This Page

Loading...