fixed compatibility issue with mmocore damage

This commit is contained in:
Indyuce 2019-08-30 17:46:51 +02:00
parent c7ccab52a6
commit 123b0443a8

View File

@ -96,7 +96,7 @@ public class EntityManager implements Listener {
Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> unregisterCustomEntity(event.getEntity())); Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> unregisterCustomEntity(event.getEntity()));
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler
public void b(EntityDamageByEntityEvent event) { public void b(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Projectile) || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC") || event.isCancelled()) if (!(event.getDamager() instanceof Projectile) || !(event.getEntity() instanceof LivingEntity) || event.getEntity().hasMetadata("NPC") || event.isCancelled())
return; return;
@ -109,13 +109,18 @@ public class EntityManager implements Listener {
LivingEntity target = (LivingEntity) event.getEntity(); LivingEntity target = (LivingEntity) event.getEntity();
TemporaryStats stats = data.getPlayerStats(); TemporaryStats stats = data.getPlayerStats();
AttackResult result = new AttackResult(stats.getStat(ItemStat.ATTACK_DAMAGE), DamageType.WEAPON, DamageType.PROJECTILE, DamageType.PHYSICAL).applyOnHitEffects(stats, target); AttackResult result = new AttackResult(data.isCustomWeapon() ? stats.getStat(ItemStat.ATTACK_DAMAGE) : event.getDamage(), DamageType.WEAPON, DamageType.PROJECTILE, DamageType.PHYSICAL).applyOnHitEffects(stats, target);
if (data.isCustomWeapon())
/*
* only modify the damage when the bow used is a custom weapon.
*/
if (data.isCustomWeapon()) {
result.applyElementalEffects(stats, data.getSourceItem(), target); result.applyElementalEffects(stats, data.getSourceItem(), target);
if (data.getSourceItem().getItem().hasItemMeta()) if (data.getSourceItem().getItem().hasItemMeta())
if (data.getSourceItem().getItem().getItemMeta().getEnchants().containsKey(Enchantment.ARROW_DAMAGE)) if (data.getSourceItem().getItem().getItemMeta().getEnchants().containsKey(Enchantment.ARROW_DAMAGE))
result.addRelativeDamage(.25 + (.25 * data.getSourceItem().getItem().getItemMeta().getEnchantLevel(Enchantment.ARROW_DAMAGE))); result.addRelativeDamage(.25 + (.25 * data.getSourceItem().getItem().getItemMeta().getEnchantLevel(Enchantment.ARROW_DAMAGE)));
}
event.setDamage(result.getDamage()); event.setDamage(result.getDamage());
unregisterCustomProjectile(arrow); unregisterCustomProjectile(arrow);