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

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId> <groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId> <artifactId>mcMMO</artifactId>
<version>1.2.08</version> <version>1.2.09-dev</version>
<name>mcMMO</name> <name>mcMMO</name>
<url>https://github.com/TheYeti/mcMMO</url> <url>https://github.com/TheYeti/mcMMO</url>
<issueManagement> <issueManagement>

View File

@ -16,6 +16,7 @@
*/ */
package com.gmail.nossr50; package com.gmail.nossr50;
import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
@ -352,17 +353,42 @@ public class Combat
Skills.XpCheckSkill(SkillType.ARCHERY, attacker); Skills.XpCheckSkill(SkillType.ARCHERY, attacker);
} }
} }
public static void dealDamage(Entity target, int dmg){
if(target instanceof Player){ /**
((Player) 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);
} }
if(target instanceof Animals){
((Animals) target).damage(dmg); /**
} * Attempt to damage target for value dmg with reason cause
if(target instanceof Monster){ *
((Monster) target).damage(dmg); * @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) public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world)
{ {
if(!event.getEntity().getWorld().getPVP()) if(!event.getEntity().getWorld().getPVP())

View File

@ -17,6 +17,7 @@
package com.gmail.nossr50.runnables; package com.gmail.nossr50.runnables;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
@ -60,7 +61,7 @@ public class mcTimer implements Runnable
*/ */
if(thecount % 2 == 0 && PP.getBleedTicks() >= 1) if(thecount % 2 == 0 && PP.getBleedTicks() >= 1)
{ {
player.damage(2); Combat.dealDamage(player, 2);
PP.decreaseBleedTicks(); PP.decreaseBleedTicks();
} }

View File

@ -25,6 +25,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
@ -152,7 +153,7 @@ public class Axes {
continue; continue;
if(targets >= 1 && derp.getWorld().getPVP()) if(targets >= 1 && derp.getWorld().getPVP())
{ {
target.damage(event.getDamage() / 2); Combat.dealDamage(target, event.getDamage() / 2, attacker);
target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!"); target.sendMessage(ChatColor.DARK_RED+"Struck by CLEAVE!");
targets--; targets--;
continue; continue;
@ -161,7 +162,7 @@ public class Axes {
else else
{ {
LivingEntity target = (LivingEntity)derp; LivingEntity target = (LivingEntity)derp;
target.damage(event.getDamage() / 2); Combat.dealDamage(target, event.getDamage() / 2, attacker);
targets--; targets--;
} }
} }

View File

@ -9,6 +9,7 @@ import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
@ -671,7 +672,7 @@ public class Fishing {
if(le instanceof Player) if(le instanceof Player)
return; return;
le.damage(1); Combat.dealDamage(le, 1, event.getPlayer());
World world = le.getWorld(); World world = le.getWorld();
/* Neutral Mobs */ /* Neutral Mobs */

View File

@ -151,7 +151,7 @@ public class Swords
continue; continue;
if(targets >= 1 && derp.getWorld().getPVP()) if(targets >= 1 && derp.getWorld().getPVP())
{ {
target.damage(event.getDamage() / 4); Combat.dealDamage(target, event.getDamage() / 4, attacker);
target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!"); target.sendMessage(ChatColor.DARK_RED+"Struck by Serrated Strikes!");
Users.getProfile(target).addBleedTicks(5); Users.getProfile(target).addBleedTicks(5);
targets--; targets--;
@ -164,7 +164,7 @@ public class Swords
pluginx.misc.addToBleedQue((LivingEntity)derp); pluginx.misc.addToBleedQue((LivingEntity)derp);
LivingEntity target = (LivingEntity)derp; LivingEntity target = (LivingEntity)derp;
target.damage(event.getDamage() / 4); Combat.dealDamage(target, event.getDamage() / 4, attacker);
targets--; targets--;
} }
} }
@ -193,7 +193,7 @@ public class Swords
{ {
if(Math.random() * 2000 <= 600) if(Math.random() * 2000 <= 600)
{ {
Combat.dealDamage(f, event.getDamage() / 2); Combat.dealDamage((LivingEntity) f, event.getDamage() / 2);
defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**"); defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**");
if(f instanceof Player) if(f instanceof Player)
((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!"); ((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!");
@ -201,7 +201,7 @@ public class Swords
} }
else if (Math.random() * 2000 <= PPd.getSkillLevel(SkillType.SWORDS)) else if (Math.random() * 2000 <= PPd.getSkillLevel(SkillType.SWORDS))
{ {
Combat.dealDamage(f, event.getDamage() / 2); Combat.dealDamage((LivingEntity) f, event.getDamage() / 2);
defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**"); defender.sendMessage(ChatColor.GREEN+"**COUNTER-ATTACKED**");
if(f instanceof Player) if(f instanceof Player)
((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!"); ((Player) f).sendMessage(ChatColor.DARK_RED+"Hit with counterattack!");
@ -245,7 +245,7 @@ public class Swords
} }
else else
{ {
x.damage(2); Combat.dealDamage(x, 2);
} }
} }
} }

View File

@ -16,7 +16,6 @@
*/ */
package com.gmail.nossr50.skills; package com.gmail.nossr50.skills;
import org.bukkit.craftbukkit.CraftOfflinePlayer;
import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;