Java Code Examples for org.bukkit.event.entity.EntityDamageEvent.DamageCause#CUSTOM

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent.DamageCause#CUSTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerDeathListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onDeath2(final PlayerDeathEvent v2) {
      final GameMap gameMap = MatchManager.get().getPlayerMap(v2.getEntity());

      if (gameMap == null) {
          return;
      }
       
      final Player player = v2.getEntity();
      v2.getEntity().getInventory().clear();
      v2.getEntity().getInventory().setArmorContents(null);
      
      DamageCause damageCause = DamageCause.CUSTOM;
if (v2.getEntity().getLastDamageCause() != null) {
	damageCause = v2.getEntity().getLastDamageCause().getCause();
} 
final DamageCause dCause = damageCause;
v2.setDeathMessage("");

      MatchManager.get().playerLeave(player, dCause, false, true, true);
  }
 
Example 2
Source File: HealthUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
/** Apply damage to an entity
 * @param e Entity to apply damage to
 * @param d Amount of hearts to damage
 */
public static void damage(final Damageable e, final double d) {
	if (d < 0) {
		heal(e, -d);
		return;
	}
	EntityDamageEvent event = new EntityDamageEvent(e, DamageCause.CUSTOM, d * 2);
	Bukkit.getPluginManager().callEvent(event);
	if (event.isCancelled()) return;
	e.damage(event.getDamage());
}