Skip to content

Commit

Permalink
Merge pull request #68 from TownyAdvanced/fix/62_horse_damage
Browse files Browse the repository at this point in the history
Prevent contact and fire causing excessive damage to horses.
  • Loading branch information
LlmDl authored Dec 22, 2022
2 parents 9488cad + 4538247 commit ac65a24
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
Expand Down Expand Up @@ -132,7 +133,8 @@ public void on (PlayerJoinEvent event) {
public void on (EntityDamageEvent event) {
if (!TownyCombatSettings.isTownyCombatEnabled())
return;
if (event.getEntity() instanceof AbstractHorse) {
// When it is a horse and it is not being hurt by a bush/cactus, try to prevent the rearing.
if (event.getEntity() instanceof AbstractHorse && !instantHorseDeathCause(event.getCause())) {
//No rearing when horse is damaged. Do this by cancelling the event, then applying the same damage in a simple set operation.
if(TownyCombatSettings.isHorseRearingPreventionEnabled()
&& event.getEntity().getPassengers().size() > 0
Expand All @@ -145,6 +147,14 @@ public void on (EntityDamageEvent event) {
}
}

/**
* @param cause DamageCause
* @return true if this is a DamageCause that shreds horse health.
*/
private boolean instantHorseDeathCause(DamageCause cause) {
return cause.equals(DamageCause.CONTACT) || cause.equals(DamageCause.FIRE);
}

@EventHandler (ignoreCancelled = true)
public void on (EntityDamageByEntityEvent event) {
if (!TownyCombatSettings.isTownyCombatEnabled())
Expand Down

0 comments on commit ac65a24

Please sign in to comment.