I have seen sometimes when people ask for code on how to find if the player is damaged. It's really easy. Just follow these steps. 1. In your event listener class, implement Listener at (org.bukkit.event.Listener) and create a new constructor and make sure it looks something like this. Code:java package me.Name.Plugin; public class EventListener implements Listener { public Plugin plugin; public EventListener(Plugin instance) {plugin = instance;Bukkit.getServer().getPluginManager().registerEvents(this, plugin);}} This will create a new instance of EventListener connected to your main class and register the events. All you have to do is 'new EventListener(this)'. Change the class name to your main class. Using this outside your package, you'll need to import it. 2. Now you'll want to create the event method, which will be called. Earlier in this year, Bukkit has done a major overhaul on the Event system, possibly breaking thousands of plugins. Good thing they let us have time to fix our plugins. Code:java @EventHandler(priority = EventPriority.NORMAL) This must be in the class before the event method. Now you'll want to do the following.. Code:java public void dmg(final EntityDamageEvent event) {} This will register the EntityDamageEvent event onto that method. Now you'll want to catch the entity that has been damaged. 3. So, you have setted up your class and your method, let's run down! Code:java @EventHandler(priority = EventPriority.NORMAL)public void dmg(final EntityDamageEvent event) {Entity e = event.getEntity();} This code will return a warning for the variable 'e' because it has been never used locally. Ignore this. You will want to do some checking. If you are using god mode for all players, I'd prefer doing this: Code:java if(e instanceof Player) event.setCancelled(true); The code above will save you some trouble. You'll want to do this then cast Player to Entity. Code:java @EventHandler(priority = EventPriority.NORMAL)public void dmg(final EntityDamageEvent event) {Entity e = event.getEntity();if(e instanceof Player) {Player player = (Player)e;}} Now you can mess around what you can do with it. Good luck! Think outside the 'block' and make wacky plugins. EDIT: thehutch was nice for us to provide some more specific causes of damage. It's the post directly under this one.
There are also sub events for this one eg: EntityDamageByEntityEvent (Entities) EntityDamageByProjectileEvent (Arrows/ idk about eggs/snowballs) EntityDamageByBlockEvent (Gravel/sand falling on player) To check if this event is used use: Code: if (event instanceof EntityDamageBy...Event) { // do stuff }
No, closest thing you have is checking if the damage is fall damage . Now, if they take 2.5 hearts of damage right after throwing an enderpearl, which has ProjectileLaunchEvent...
To keep the hurt aanimation, use event.set damage(0). To do absolutely nothing (no hurt animation or damage) Use event.set cancelled(true)