Detect on breath meter change?

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.
Oct 3, 2017
19
2
3
25
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:
on [event needing meter change]:
    [do code]
 
with skript-reflect:
Code:
import:
  org.bukkit.event.entity.EntityAirChangeEvent
on EntityAirChangeEvent:
  broadcast "%event.getAmount()%" # current amount of air 
  broadcast "%event.setAmount(100)%" # Sets the amount of air remaining for the entity (measured in ticks.)
  broadcast "%event.getEntity()%" # what entity called event
 
Last edited:
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
 
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

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:
import:
  org.bukkit.event.entity.EntityAirChangeEvent
on EntityAirChangeEvent:
  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:
import:
  org.bukkit.event.entity.EntityAirChangeEvent
  org.bukkit.entity.EntityType
on EntityAirChangeEvent:
  if event.getEntityType() is EntityType.PLAYER:
    set {_player} to event.getEntity()
    broadcast "Its player: %{_player}%!!!"
 
Last edited:
Status
Not open for further replies.