Change damage to use events system

Should provide a fix for issue #39

Also update pom and removed an unused import.
This commit is contained in:
NuclearW
2012-01-28 01:24:29 -05:00
parent 9bd4a0a707
commit 299f440f63
7 changed files with 49 additions and 21 deletions

View File

@@ -16,6 +16,7 @@
*/
package com.gmail.nossr50;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -352,17 +353,42 @@ public class Combat
Skills.XpCheckSkill(SkillType.ARCHERY, attacker);
}
}
public static void dealDamage(Entity target, int dmg){
if(target instanceof Player){
((Player) target).damage(dmg);
}
if(target instanceof Animals){
((Animals) target).damage(dmg);
}
if(target instanceof Monster){
((Monster) target).damage(dmg);
}
/**
* Attempt to damage target for value dmg with reason CUSTOM
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
*/
public static void dealDamage(LivingEntity target, int dmg){
EntityDamageEvent ede = new EntityDamageEvent(target, EntityDamageEvent.DamageCause.CUSTOM, dmg);
Bukkit.getPluginManager().callEvent(ede);
}
/**
* Attempt to damage target for value dmg with reason cause
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
* @param cause DamageCause to pass to damage event
*/
public static void dealDamage(LivingEntity target, int dmg, DamageCause cause) {
EntityDamageEvent ede = new EntityDamageEvent(target, cause, dmg);
Bukkit.getPluginManager().callEvent(ede);
}
/**
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
public static void dealDamage(LivingEntity target, int dmg, Player attacker) {
EntityDamageEvent ede = new EntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
Bukkit.getPluginManager().callEvent(ede);
}
public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world)
{
if(!event.getEntity().getWorld().getPVP())