Paper/patches/api/0292-Add-WaterBottleSplashEvent.patch
Jake Potrebic ac554ad46d
Updated Upstream (Bukkit/CraftBukkit) (#10691)
Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
fa99e752 PR-1007: Add ItemMeta#getAsComponentString()
94a91782 Fix copy-pasted BlockType.Typed documentation
9b34ac8c Largely restore deprecated PotionData API
51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5
702d15fe Fix Javadoc reference
42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them
237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more
87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent

CraftBukkit Changes:
4af0f22e8 SPIGOT-7664: Item meta should prevail over block states
c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot
124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects
66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API
6118e5398 Fix regression listening to minecraft:brand custom payloads
c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check
12360a7ec Remove unused imports
147b098b4 PR-1397: Add ItemMeta#getAsComponentString()
428aefe0e Largely restore deprecated PotionData API
afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them
8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent
4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it
441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets
0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource
f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA
2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more
c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent
741b84480 PR-1390: Improve internal handling of damage sources
0364df4e1 SPIGOT-7657: Error when loading angry entities
2024-05-11 23:48:37 +02:00

163 lines
5.8 KiB
Diff

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..362afc28190dd6f0ed0407273f2be1aab73bb8f5
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/WaterBottleSplashEvent.java
@@ -0,0 +1,137 @@
+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<LivingEntity> rehydrate;
+ private final @NotNull Set<LivingEntity> extinguish;
+
+ @ApiStatus.Internal
+ public WaterBottleSplashEvent(
+ final @NotNull ThrownPotion potion,
+ final @Nullable Entity hitEntity,
+ final @Nullable Block hitBlock,
+ final @Nullable BlockFace hitFace,
+ final @NotNull Map<LivingEntity, Double> affectedEntities,
+ final @NotNull Set<LivingEntity> rehydrate,
+ final @NotNull Set<LivingEntity> 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<LivingEntity> 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.
+ * <p>
+ * 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<LivingEntity> 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<LivingEntity> getToExtinguish() {
+ return this.extinguish;
+ }
+
+ /**
+ * @return a confusing collection, don't use it
+ * @deprecated Use {@link #getToDamage()}
+ */
+ @Deprecated
+ @Override
+ public @NotNull Collection<LivingEntity> 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
+ @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
+ @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 bc6ba6c4c07cacfc6ab7a2a72b12dfba110ba911..2e58b716fdb21026d2ee838e81559601344c8a00 100644
--- a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
+++ b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
@@ -20,7 +20,7 @@ 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<LivingEntity, Double> affectedEntities;
+ protected final Map<LivingEntity, Double> affectedEntities; // Paper
@Deprecated
public PotionSplashEvent(@NotNull final ThrownPotion potion, @NotNull final Map<LivingEntity, Double> affectedEntities) {