Skip to content

Commit

Permalink
fix errors from non-deadly mobs in weapon_damage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 10, 2019
1 parent fabc44f commit 7e6ab8b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftAnimals;
Expand Down Expand Up @@ -44,7 +45,11 @@ public double getDamageTo(LivingEntity attacker, Entity target) {
else {
monsterType = EnumMonsterType.UNDEFINED;
}
double damage = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getValue();
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentManager.a(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock;
Expand Down Expand Up @@ -44,7 +45,11 @@ public double getDamageTo(LivingEntity attacker, Entity target) {
else {
monsterType = EnumMonsterType.UNDEFINED;
}
double damage = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getValue();
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentManager.a(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock;
Expand Down Expand Up @@ -63,7 +64,11 @@ public double getDamageTo(LivingEntity attacker, Entity target) {
else {
monsterType = EnumMonsterType.UNDEFINED;
}
double damage = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getValue();
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentManager.a(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
Expand Down

0 comments on commit 7e6ab8b

Please sign in to comment.