From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 8 Dec 2022 10:12:23 -0700 Subject: [PATCH] Add WaterBottleSplashEvent diff --git a/src/main/java/io/papermc/paper/event/entity/WaterBottleSplashEvent.java b/src/main/java/io/papermc/paper/event/entity/WaterBottleSplashEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 --- /dev/null +++ b/src/main/java/io/papermc/paper/event/entity/WaterBottleSplashEvent.java @@ -0,0 +0,0 @@ +package io.papermc.paper.event.entity; + +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.ThrownPotion; +import org.bukkit.event.entity.PotionSplashEvent; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +/** + * Called when a splash water potion "splashes" and affects + * different entities in different ways. + */ +public class WaterBottleSplashEvent extends PotionSplashEvent { + + private final @NotNull Set rehydrate; + private final @NotNull Set extinguish; + + @ApiStatus.Internal + public WaterBottleSplashEvent( + final @NotNull ThrownPotion potion, + final @Nullable Entity hitEntity, + final @Nullable Block hitBlock, + final @Nullable BlockFace hitFace, + final @NotNull Map affectedEntities, + final @NotNull Set rehydrate, + final @NotNull Set extinguish + ) { + super(potion, hitEntity, hitBlock, hitFace, affectedEntities); + this.rehydrate = rehydrate; + this.extinguish = extinguish; + } + + /** + * Gets an immutable collection of entities that + * will take damage as a result of this event. Use + * other methods on this class to modify which entities + * take damage. + * + * @return an immutable collection of entities + * @see #doNotDamageAsWaterSensitive(LivingEntity) + * @see #damageAsWaterSensitive(LivingEntity) + */ + @NotNull + public @Unmodifiable Collection getToDamage() { + return this.affectedEntities.entrySet().stream().filter(entry -> entry.getValue() > 0).map(Map.Entry::getKey).collect(Collectors.toUnmodifiableSet()); + } + + /** + * Removes this entity from the group that + * will be damaged. + * + * @param entity entity to remove + */ + public void doNotDamageAsWaterSensitive(final @NotNull LivingEntity entity) { + this.affectedEntities.remove(entity); + } + + /** + * Adds this entity to the group that + * will be damaged + * + * @param entity entity to add + */ + public void damageAsWaterSensitive(final @NotNull LivingEntity entity) { + this.affectedEntities.put(entity, 1.0); + } + + /** + * Get a mutable collection of entities + * that will be rehydrated by this. + *

+ * As of 1.19.3 this only will contain Axolotls as they + * are the only entity type that can be rehydrated, but + * it may change in the future. + * + * @return the entities + */ + @NotNull + public Collection getToRehydrate() { + return this.rehydrate; + } + + /** + * Get a mutable collection of entities that will + * be extinguished as a result of this event. + * + * @return entities to be extinguished + */ + @NotNull + public Collection getToExtinguish() { + return this.extinguish; + } + + /** + * @return a confusing collection, don't use it + * @deprecated Use {@link #getToDamage()} + */ + @Deprecated(since = "1.19.3") + @Override + public @NotNull Collection getAffectedEntities() { + return super.getAffectedEntities(); + } + + /** + * Doesn't make sense for this event as intensity doesn't vary. + * + * @return a confusing value + * @deprecated check if {@link #getToDamage()} contains an entity + */ + @Deprecated(since = "1.19.3") + @Override + public double getIntensity(final @NotNull LivingEntity entity) { + return super.getIntensity(entity); + } + + /** + * Doesn't make sense for this event as intensity doesn't vary. + * + * @deprecated use {@link #damageAsWaterSensitive(LivingEntity)} + * or {@link #doNotDamageAsWaterSensitive(LivingEntity)} to change which entities are + * damaged + */ + @Deprecated(since = "1.19.3") + @Override + public void setIntensity(final @NotNull LivingEntity entity, final double intensity) { + super.setIntensity(entity, intensity); + } +} diff --git a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java +++ b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java @@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable; public class PotionSplashEvent extends ProjectileHitEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - private final Map affectedEntities; + protected final Map affectedEntities; // Paper @Deprecated public PotionSplashEvent(@NotNull final ThrownPotion potion, @NotNull final Map affectedEntities) {