#how do i check if a player takes damage?

1 messages · Page 1 of 1 (latest)

manic mesa
manic mesa
#

it was just like 🥲

glass lake
#

Oh no dont worry

languid oar
#

not really sure how to check if the player takes damage or if the player does damage

#

so far ive made a event handler

#

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;

public class GodMode implements Listener {
    public GodMode(Main plugin){
        Bukkit.getPluginManager().registerEvents(this, plugin);
    }

    @EventHandler
    public void onPlayerDamage(EntityDamageEvent event){
        
    }
}
manic mesa
#

and to get player u can check if entity is instance of a player than u cast it

#

eg Player p = (Player) entity

languid oar
#

ty for the help but ive decided to do thos another way

#

i want to make a boolean and if the player runs the command the boolean will be set to true

#

and the plugin will keep on checking if its true and when it is true itll make the player not be able to take damage or cause damage

languid oar
manic mesa
#

I wouldn't know the most efficient way

manic mesa
#

e.setCancelled(true);

#

inside your check

languid oar
#

probably a if statement

#

or while

#

idk

manic mesa
#

you don't want that at all

languid oar
manic mesa
#

or set

languid oar
#

oh

#

not sure how i would pull all of the names of players that joined the server and put them in a array list

glass lake
#

@languid oar in that case we should recommend you to learn the basics of java

languid oar
#

i know how to make an array

#

just not how to get the player names

glass lake
#

Also

#

Why do you want to keep the player names

#

U should take in care that player names can change, uuid doesnt change

manic mesa
#

u said u want every player who ran the command to not take damage

#

so only put them in the list

glass lake
#

Then listen to the damage event and check if player is inside the list cancel the event, if not dont do anything

manic mesa
glass lake
#

Why would you save full player object when you dont need it

#

Also it would be an overkill without being required because you only need to know his uuid to cancel the damage!

manic mesa
#

🤦‍♂️

glass lake
#

Oh sorry

#

I didnt understand you