use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onLingeringApply.
@EventHandler(ignoreCancelled = true)
public void onLingeringApply(AreaEffectCloudApplyEvent event) {
AreaEffectCloud entity = event.getEntity();
List<PotionEffect> effects = new ArrayList<>();
PotionEffectType baseEffectType = entity.getBasePotionData().getType().getEffectType();
if (baseEffectType != null) {
effects.add(new PotionEffect(baseEffectType, 0, 0));
}
if (entity.hasCustomEffects()) {
effects.addAll(entity.getCustomEffects());
}
if (!Materials.hasDamageEffect(effects)) {
return;
}
Cause cause = create(event.getEntity());
event.getAffectedEntities().removeIf(victim -> Events.fireAndTestCancel(new DamageEntityEvent(event, cause, victim)));
}
use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onVehicleDamage.
@EventHandler(ignoreCancelled = true)
public void onVehicleDamage(VehicleDamageEvent event) {
Entity attacker = event.getAttacker();
Events.fireToCancel(event, new DamageEntityEvent(event, create(attacker), event.getVehicle()));
}
use of com.sk89q.worldguard.bukkit.event.entity.DamageEntityEvent in project WorldGuard by EngineHub.
the class EventAbstractionListener method onPotionSplash.
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
Entity entity = event.getEntity();
ThrownPotion potion = event.getPotion();
World world = entity.getWorld();
Cause cause = create(potion);
// Fire item interaction event
Events.fireToCancel(event, new UseItemEvent(event, cause, world, potion.getItem()));
// Fire entity interaction event
if (!event.isCancelled()) {
int blocked = 0;
int affectedSize = event.getAffectedEntities().size();
boolean hasDamageEffect = Materials.hasDamageEffect(potion.getEffects());
for (LivingEntity affected : event.getAffectedEntities()) {
DelegateEvent delegate = hasDamageEffect ? new DamageEntityEvent(event, cause, affected) : new UseEntityEvent(event, cause, affected);
// Consider the potion splash flag
delegate.getRelevantFlags().add(Flags.POTION_SPLASH);
if (Events.fireAndTestCancel(delegate)) {
event.setIntensity(affected, 0);
blocked++;
}
}
if (affectedSize > 0 && blocked == affectedSize) {
// server does weird things with this if the event is modified, so use cached number
event.setCancelled(true);
}
}
}
Aggregations