Fix for enemy attacks healing people in their own territory, instead of correctly just giving reduced damage.
The problem is that Bukkit reports the amount of damage before armor calculations are made, so the actual damage will be less if the target is wearing armor. So, I switched it to using setDamage instead of healing the target.
This commit is contained in:
parent
1d26e18916
commit
2016f232ef
@ -1,6 +1,6 @@
|
|||||||
package com.bukkit.mcteam.factions.listeners;
|
package com.bukkit.mcteam.factions.listeners;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -53,12 +53,12 @@ public class FactionsEntityListener extends EntityListener {
|
|||||||
|
|
||||||
if (event instanceof EntityDamageByEntityEvent) {
|
if (event instanceof EntityDamageByEntityEvent) {
|
||||||
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
|
EntityDamageByEntityEvent sub = (EntityDamageByEntityEvent)event;
|
||||||
if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
|
if ( ! this.canDamagerHurtDamagee(sub)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} else if (event instanceof EntityDamageByProjectileEvent) {
|
} else if (event instanceof EntityDamageByProjectileEvent) {
|
||||||
EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event;
|
EntityDamageByProjectileEvent sub = (EntityDamageByProjectileEvent)event;
|
||||||
if ( ! this.canDamagerHurtDamagee(sub.getDamager(), sub.getEntity(), sub.getDamage())) {
|
if ( ! this.canDamagerHurtDamagee(sub)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,10 @@ public class FactionsEntityListener extends EntityListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canDamagerHurtDamagee(Entity damager, Entity damagee, int damage) {
|
public boolean canDamagerHurtDamagee(EntityDamageByEntityEvent sub) {
|
||||||
|
Entity damager = sub.getDamager();
|
||||||
|
Entity damagee = sub.getEntity();
|
||||||
|
int damage = sub.getDamage();
|
||||||
if ( ! (damager instanceof Player)) {
|
if ( ! (damager instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -112,13 +115,12 @@ public class FactionsEntityListener extends EntityListener {
|
|||||||
|
|
||||||
// Damage will be dealt. However check if the damage should be reduced.
|
// Damage will be dealt. However check if the damage should be reduced.
|
||||||
if (defender.isInOwnTerritory() && Conf.territoryShieldFactor > 0) {
|
if (defender.isInOwnTerritory() && Conf.territoryShieldFactor > 0) {
|
||||||
int toHeal = (int)(damage * Conf.territoryShieldFactor);
|
int newDamage = (int)(damage * Conf.territoryShieldFactor);
|
||||||
defender.heal(toHeal);
|
sub.setDamage(newDamage);
|
||||||
|
|
||||||
// Send message
|
// Send message
|
||||||
DecimalFormat formatter = new DecimalFormat("#.#");
|
String perc = MessageFormat.format("{0,number,#%}", (1.0 - Conf.territoryShieldFactor));
|
||||||
String hearts = formatter.format(toHeal / 2.0);
|
defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+perc+Conf.colorSystem+".");
|
||||||
defender.sendMessage(Conf.colorSystem+"Enemy damage reduced by "+ChatColor.RED+hearts+Conf.colorSystem+" hearts.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user