Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix damage actions triggering for combustion #1380

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions core/src/main/java/tc/oc/pgm/damage/DamageMatchModule.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package tc.oc.pgm.damage;

import static org.bukkit.event.entity.EntityDamageEvent.DamageCause.CUSTOM;
import static org.bukkit.event.entity.EntityDamageEvent.DamageCause.ENTITY_ATTACK;
import static org.bukkit.event.entity.EntityDamageEvent.DamageCause.FIRE;
import static org.bukkit.event.entity.EntityDamageEvent.DamageCause.MAGIC;
import static tc.oc.pgm.util.Assert.assertNotNull;

import java.util.List;
Expand Down Expand Up @@ -166,10 +170,9 @@ public Filter.QueryResponse queryDamage(
}

/** Query the given damage event and cancel it if the result was denied. */
public Filter.QueryResponse processDamageEvent(
public void processDamageEvent(
Cancellable event, ParticipantState victim, DamageInfo damageInfo) {
Filter.QueryResponse response = queryDamage(assertNotNull(event), victim, damageInfo);
if (response.isDenied()) {
if (queryDamage(assertNotNull(event), victim, damageInfo).isDenied()) {
event.setCancelled(true);
} else if (attackerAction != null || victimAction != null) {
MatchPlayerState attacker;
Expand All @@ -184,7 +187,6 @@ public Filter.QueryResponse processDamageEvent(
.ifPresent(p -> victimAction.trigger(p, getQuery(event, victim, damageInfo)));
}
}
return response;
}

/** Search the rider stack for a participant */
Expand Down Expand Up @@ -216,35 +218,35 @@ public void onDamageVehicle(VehicleDamageEvent event) {
processDamageEvent(
event,
victim.getParticipantState(),
tracker()
.resolveDamage(
EntityDamageEvent.DamageCause.CUSTOM, event.getVehicle(), event.getAttacker()));
tracker().resolveDamage(CUSTOM, event.getVehicle(), event.getAttacker()));
}

@EventHandler(ignoreCancelled = true)
public void onIgnition(EntityCombustByEntityEvent event) {
MatchPlayer victim = getVictim(event.getEntity());
if (victim == null) return;

processDamageEvent(
event,
victim.getParticipantState(),
tracker()
.resolveDamage(
EntityDamageEvent.DamageCause.FIRE, event.getEntity(), event.getCombuster()));
if (queryDamage(
event,
victim.getParticipantState(),
tracker().resolveDamage(FIRE, event.getEntity(), event.getCombuster()))
.isDenied()) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
public void onIgnition(EntityCombustByBlockEvent event) {
MatchPlayer victim = getVictim(event.getEntity());
if (victim == null) return;

processDamageEvent(
event,
victim.getParticipantState(),
tracker()
.resolveDamage(
EntityDamageEvent.DamageCause.FIRE, event.getEntity(), event.getCombuster()));
if (queryDamage(
event,
victim.getParticipantState(),
tracker().resolveDamage(FIRE, event.getEntity(), event.getCombuster()))
.isDenied()) {
event.setCancelled(true);
}
}

@EventHandler(ignoreCancelled = true)
Expand All @@ -254,8 +256,7 @@ public void onPotionSplash(final PotionSplashEvent event) {

for (LivingEntity entity : event.getAffectedEntities()) {
ParticipantState victim = match.getParticipantState(entity);
DamageInfo damageInfo =
tracker().resolveDamage(EntityDamageEvent.DamageCause.MAGIC, entity, potion);
DamageInfo damageInfo = tracker().resolveDamage(MAGIC, entity, potion);

if (victim != null && queryDamage(event, victim, damageInfo).isDenied()) {
event.setIntensity(entity, 0);
Expand All @@ -278,9 +279,8 @@ public void onTarget(EntityTargetEvent event) {
}
if (victimState == null) return;

DamageInfo damageInfo = tracker()
.resolveDamage(
EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity());
DamageInfo damageInfo =
tracker().resolveDamage(ENTITY_ATTACK, event.getTarget(), event.getEntity());
if (queryHostile(victimState, damageInfo).isDenied()) {
event.setCancelled(true);
}
Expand Down