2022-12-09 01:33:22 +01:00
|
|
|
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
|
2024-09-29 21:52:13 +02:00
|
|
|
index 0000000000000000000000000000000000000000..1f74ea11c726273c3c2a7fc6f381716e230ef5c9
|
2022-12-09 01:33:22 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/io/papermc/paper/event/entity/WaterBottleSplashEvent.java
|
2024-09-29 21:52:13 +02:00
|
|
|
@@ -0,0 +1,135 @@
|
2022-12-09 01:33:22 +01:00
|
|
|
+package io.papermc.paper.event.entity;
|
|
|
|
+
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
2024-02-10 20:27:29 +01:00
|
|
|
+import org.bukkit.block.Block;
|
|
|
|
+import org.bukkit.block.BlockFace;
|
|
|
|
+import org.bukkit.entity.Entity;
|
2022-12-09 01:33:22 +01:00
|
|
|
+import org.bukkit.entity.LivingEntity;
|
|
|
|
+import org.bukkit.entity.ThrownPotion;
|
|
|
|
+import org.bukkit.event.entity.PotionSplashEvent;
|
2024-02-01 10:15:57 +01:00
|
|
|
+import org.jetbrains.annotations.ApiStatus;
|
2022-12-09 01:33:22 +01:00
|
|
|
+import org.jetbrains.annotations.Unmodifiable;
|
2024-09-29 21:52:13 +02:00
|
|
|
+import org.jspecify.annotations.NullMarked;
|
|
|
|
+import org.jspecify.annotations.Nullable;
|
2022-12-09 01:33:22 +01:00
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Called when a splash water potion "splashes" and affects
|
|
|
|
+ * different entities in different ways.
|
|
|
|
+ */
|
2024-09-29 21:52:13 +02:00
|
|
|
+@NullMarked
|
2022-12-09 01:33:22 +01:00
|
|
|
+public class WaterBottleSplashEvent extends PotionSplashEvent {
|
2024-02-01 10:15:57 +01:00
|
|
|
+
|
2024-09-29 21:52:13 +02:00
|
|
|
+ private final Set<LivingEntity> rehydrate;
|
|
|
|
+ private final Set<LivingEntity> extinguish;
|
2022-12-09 01:33:22 +01:00
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ @ApiStatus.Internal
|
2022-12-09 01:33:22 +01:00
|
|
|
+ public WaterBottleSplashEvent(
|
2024-09-29 21:52:13 +02:00
|
|
|
+ final ThrownPotion potion,
|
2024-02-10 20:27:29 +01:00
|
|
|
+ final @Nullable Entity hitEntity,
|
|
|
|
+ final @Nullable Block hitBlock,
|
|
|
|
+ final @Nullable BlockFace hitFace,
|
2024-09-29 21:52:13 +02:00
|
|
|
+ final Map<LivingEntity, Double> affectedEntities,
|
|
|
|
+ final Set<LivingEntity> rehydrate,
|
|
|
|
+ final Set<LivingEntity> extinguish
|
2022-12-09 01:33:22 +01:00
|
|
|
+ ) {
|
2024-02-10 20:27:29 +01:00
|
|
|
+ super(potion, hitEntity, hitBlock, hitFace, affectedEntities);
|
2022-12-09 01:33:22 +01:00
|
|
|
+ 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)
|
|
|
|
+ */
|
|
|
|
+ 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
|
|
|
|
+ */
|
2024-09-29 21:52:13 +02:00
|
|
|
+ public void doNotDamageAsWaterSensitive(final LivingEntity entity) {
|
2022-12-09 01:33:22 +01:00
|
|
|
+ this.affectedEntities.remove(entity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Adds this entity to the group that
|
|
|
|
+ * will be damaged
|
|
|
|
+ *
|
|
|
|
+ * @param entity entity to add
|
|
|
|
+ */
|
2024-09-29 21:52:13 +02:00
|
|
|
+ public void damageAsWaterSensitive(final LivingEntity entity) {
|
2022-12-09 01:33:22 +01:00
|
|
|
+ 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
|
|
|
|
+ */
|
|
|
|
+ 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
|
|
|
|
+ */
|
|
|
|
+ public Collection<LivingEntity> getToExtinguish() {
|
|
|
|
+ return this.extinguish;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return a confusing collection, don't use it
|
|
|
|
+ * @deprecated Use {@link #getToDamage()}
|
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.19.3")
|
2022-12-09 01:33:22 +01:00
|
|
|
+ @Override
|
2024-09-29 21:52:13 +02:00
|
|
|
+ public Collection<LivingEntity> getAffectedEntities() {
|
2022-12-09 01:33:22 +01:00
|
|
|
+ return super.getAffectedEntities();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Doesn't make sense for this event as intensity doesn't vary.
|
2024-02-01 10:15:57 +01:00
|
|
|
+ *
|
2022-12-09 01:33:22 +01:00
|
|
|
+ * @return a confusing value
|
|
|
|
+ * @deprecated check if {@link #getToDamage()} contains an entity
|
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.19.3")
|
2022-12-09 01:33:22 +01:00
|
|
|
+ @Override
|
2024-09-29 21:52:13 +02:00
|
|
|
+ public double getIntensity(final LivingEntity entity) {
|
2022-12-09 01:33:22 +01:00
|
|
|
+ return super.getIntensity(entity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Doesn't make sense for this event as intensity doesn't vary.
|
2024-02-01 10:15:57 +01:00
|
|
|
+ *
|
2022-12-09 01:33:22 +01:00
|
|
|
+ * @deprecated use {@link #damageAsWaterSensitive(LivingEntity)}
|
|
|
|
+ * or {@link #doNotDamageAsWaterSensitive(LivingEntity)} to change which entities are
|
|
|
|
+ * damaged
|
|
|
|
+ */
|
2024-06-04 21:40:18 +02:00
|
|
|
+ @Deprecated(since = "1.19.3")
|
2022-12-09 01:33:22 +01:00
|
|
|
+ @Override
|
2024-09-29 21:52:13 +02:00
|
|
|
+ public void setIntensity(final LivingEntity entity, final double intensity) {
|
2022-12-09 01:33:22 +01:00
|
|
|
+ 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
|
2023-10-29 00:02:13 +02:00
|
|
|
index bc6ba6c4c07cacfc6ab7a2a72b12dfba110ba911..2e58b716fdb21026d2ee838e81559601344c8a00 100644
|
2022-12-09 01:33:22 +01:00
|
|
|
--- a/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
|
|
|
|
+++ b/src/main/java/org/bukkit/event/entity/PotionSplashEvent.java
|
2023-10-29 00:02:13 +02:00
|
|
|
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
|
2022-12-09 01:33:22 +01:00
|
|
|
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
|
|
|
|
|
2023-10-29 00:02:13 +02:00
|
|
|
@Deprecated
|
2022-12-09 01:33:22 +01:00
|
|
|
public PotionSplashEvent(@NotNull final ThrownPotion potion, @NotNull final Map<LivingEntity, Double> affectedEntities) {
|