2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 20 May 2021 20:40:53 -0700
2022-12-10 22:27:36 +01:00
Subject: [PATCH] Fix potions splash events
2021-06-11 14:02:28 +02:00
2022-12-10 22:27:36 +01:00
Fix PotionSplashEvent for water splash potions
2021-06-11 14:02:28 +02:00
Fixes SPIGOT-6221: https://hub.spigotmc.org/jira/projects/SPIGOT/issues/SPIGOT-6221
2022-12-10 22:27:36 +01:00
Fix splash events cancellation that still show particles/sound
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
2024-10-23 20:15:25 +02:00
index 224e768963d6969f25608065d37ad72d82acda68..d6ac07d9d5ee0430a1d91b7084b378aac1d047e5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
2024-10-23 20:15:25 +02:00
@@ -109,55 +109,76 @@ public class ThrownPotion extends ThrowableItemProjectile {
2024-04-24 16:29:12 +02:00
ItemStack itemstack = this.getItem();
PotionContents potioncontents = (PotionContents) itemstack.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY);
2022-12-10 22:27:36 +01:00
2024-04-24 16:29:12 +02:00
+ boolean showParticles = true; // Paper - Fix potions splash events
if (potioncontents.is(Potions.WATER)) {
2024-10-23 20:15:25 +02:00
- this.applyWater(worldserver);
+ showParticles = this.applyWater(worldserver, hitResult); // Paper - Fix potions splash events
2024-04-24 16:29:12 +02:00
} else if (true || potioncontents.hasEffects()) { // CraftBukkit - Call event even if no effects to apply
2022-12-10 22:27:36 +01:00
if (this.isLingering()) {
2024-04-24 16:29:12 +02:00
- this.makeAreaOfEffectCloud(potioncontents, hitResult); // CraftBukkit - Pass MovingObjectPosition
2024-04-25 01:25:57 +02:00
+ showParticles = this.makeAreaOfEffectCloud(potioncontents, hitResult); // CraftBukkit - Pass MovingObjectPosition // Paper
2022-12-10 22:27:36 +01:00
} else {
2024-10-23 20:15:25 +02:00
- this.applySplash(worldserver, potioncontents.getAllEffects(), hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null, hitResult); // CraftBukkit - Pass MovingObjectPosition
+ showParticles = this.applySplash(worldserver, potioncontents.getAllEffects(), hitResult.getType() == HitResult.Type.ENTITY ? ((EntityHitResult) hitResult).getEntity() : null, hitResult); // CraftBukkit - Pass MovingObjectPosition // Paper
2022-12-10 22:27:36 +01:00
}
}
2024-01-19 13:22:30 +01:00
+ if (showParticles) { // Paper - Fix potions splash events
2024-04-24 16:29:12 +02:00
int i = potioncontents.potion().isPresent() && ((Potion) ((Holder) potioncontents.potion().get()).value()).hasInstantEffects() ? 2007 : 2002;
2022-12-10 22:27:36 +01:00
2024-10-23 20:15:25 +02:00
worldserver.levelEvent(i, this.blockPosition(), potioncontents.getColor());
2024-01-19 13:22:30 +01:00
+ } // Paper - Fix potions splash events
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause
2021-12-06 02:56:55 +01:00
}
}
2024-10-23 20:15:25 +02:00
- private void applyWater(ServerLevel world) {
2024-01-19 13:22:30 +01:00
+ private static final Predicate<net.minecraft.world.entity.LivingEntity> APPLY_WATER_GET_ENTITIES_PREDICATE = ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE.or(Axolotl.class::isInstance); // Paper - Fix potions splash events
2024-10-23 20:15:25 +02:00
+ private boolean applyWater(ServerLevel world, @Nullable HitResult hitResult) { // Paper - Fix potions splash events
2021-06-11 14:02:28 +02:00
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
2023-06-08 04:04:01 +02:00
- List<net.minecraft.world.entity.LivingEntity> list = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.WATER_SENSITIVE_OR_ON_FIRE);
2024-01-19 13:22:30 +01:00
+ // Paper start - Fix potions splash events
2023-06-08 04:04:01 +02:00
+ List<net.minecraft.world.entity.LivingEntity> list = this.level().getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb, ThrownPotion.APPLY_WATER_GET_ENTITIES_PREDICATE);
2022-12-09 01:33:22 +01:00
+ Map<LivingEntity, Double> affected = new HashMap<>();
+ java.util.Set<LivingEntity> rehydrate = new java.util.HashSet<>();
+ java.util.Set<LivingEntity> extinguish = new java.util.HashSet<>();
2022-12-07 21:16:54 +01:00
Iterator iterator = list.iterator();
2021-06-11 14:02:28 +02:00
2022-12-07 21:16:54 +01:00
while (iterator.hasNext()) {
net.minecraft.world.entity.LivingEntity entityliving = (net.minecraft.world.entity.LivingEntity) iterator.next();
+ if (entityliving instanceof Axolotl axolotl) {
2022-12-09 01:33:22 +01:00
+ rehydrate.add(((org.bukkit.entity.Axolotl) axolotl.getBukkitEntity()));
2022-12-07 21:16:54 +01:00
+ }
double d0 = this.distanceToSqr((Entity) entityliving);
2021-06-11 14:02:28 +02:00
2022-12-07 21:16:54 +01:00
if (d0 < 16.0D) {
if (entityliving.isSensitiveToWater()) {
2024-10-23 20:15:25 +02:00
- entityliving.hurtServer(world, this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
2022-12-09 01:33:22 +01:00
+ affected.put(entityliving.getBukkitLivingEntity(), 1.0);
2021-06-11 14:02:28 +02:00
}
2022-12-07 21:16:54 +01:00
if (entityliving.isOnFire() && entityliving.isAlive()) {
2022-12-09 01:33:22 +01:00
- entityliving.extinguishFire();
+ extinguish.add(entityliving.getBukkitLivingEntity());
}
2021-06-11 14:02:28 +02:00
}
}
2023-06-08 04:04:01 +02:00
- List<Axolotl> list1 = this.level().getEntitiesOfClass(Axolotl.class, axisalignedbb);
2021-12-06 02:56:55 +01:00
- Iterator iterator1 = list1.iterator();
-
- while (iterator1.hasNext()) {
- Axolotl axolotl = (Axolotl) iterator1.next();
-
- axolotl.rehydrate();
2024-02-10 20:27:29 +01:00
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callWaterBottleSplashEvent(
+ this, hitResult, affected, rehydrate, extinguish
2022-12-09 01:33:22 +01:00
+ );
2024-02-10 20:27:29 +01:00
+ if (!event.isCancelled()) {
2022-12-09 01:33:22 +01:00
+ for (LivingEntity affectedEntity : event.getToDamage()) {
2024-10-23 20:15:25 +02:00
+ ((CraftLivingEntity) affectedEntity).getHandle().hurtServer(world, this.damageSources().indirectMagic(this, this.getOwner()), 1.0F);
2022-12-09 01:33:22 +01:00
+ }
+ for (LivingEntity toExtinguish : event.getToExtinguish()) {
+ ((CraftLivingEntity) toExtinguish).getHandle().extinguishFire();
+ }
+ for (LivingEntity toRehydrate : event.getToRehydrate()) {
+ if (((CraftLivingEntity) toRehydrate).getHandle() instanceof Axolotl axolotl) {
2021-12-06 02:56:55 +01:00
+ axolotl.rehydrate();
+ }
2021-06-11 14:02:28 +02:00
+ }
2024-01-19 13:22:30 +01:00
+ // Paper end - Fix potions splash events
2021-12-06 02:56:55 +01:00
}
2024-01-19 13:22:30 +01:00
+ return !event.isCancelled(); // Paper - Fix potions splash events
2021-06-11 14:02:28 +02:00
2021-12-06 02:56:55 +01:00
}
2022-12-10 22:27:36 +01:00
2024-10-23 20:15:25 +02:00
- private void applySplash(ServerLevel worldserver, Iterable<MobEffectInstance> iterable, @Nullable Entity entity, HitResult position) { // CraftBukkit - Pass MovingObjectPosition
+ private boolean applySplash(ServerLevel worldserver, Iterable<MobEffectInstance> iterable, @Nullable Entity entity, HitResult position) { // CraftBukkit - Pass MovingObjectPosition // Paper - Fix potions splash events
2022-12-10 22:27:36 +01:00
AABB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
2024-10-23 20:15:25 +02:00
List<net.minecraft.world.entity.LivingEntity> list = worldserver.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, axisalignedbb);
2022-12-10 22:27:36 +01:00
Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // CraftBukkit
2024-10-23 20:15:25 +02:00
@@ -175,6 +196,7 @@ public class ThrownPotion extends ThrowableItemProjectile {
2021-06-11 14:02:28 +02:00
if (d0 < 16.0D) {
2023-03-14 21:25:13 +01:00
double d1;
2021-06-11 14:02:28 +02:00
2023-03-14 21:25:13 +01:00
+ // Paper - diff on change, used when calling the splash event for water splash potions
2021-06-11 14:02:28 +02:00
if (entityliving == entity) {
2023-03-14 21:25:13 +01:00
d1 = 1.0D;
} else {
2024-10-23 20:15:25 +02:00
@@ -230,10 +252,11 @@ public class ThrownPotion extends ThrowableItemProjectile {
2022-12-10 22:27:36 +01:00
}
}
}
2024-01-19 13:22:30 +01:00
+ return !event.isCancelled(); // Paper - Fix potions splash events
2022-12-10 22:27:36 +01:00
}
2024-04-24 16:29:12 +02:00
- private void makeAreaOfEffectCloud(PotionContents potioncontents, HitResult position) { // CraftBukkit - Pass MovingObjectPosition
+ private boolean makeAreaOfEffectCloud(PotionContents potioncontents, HitResult position) { // CraftBukkit - Pass MovingObjectPosition
2023-06-08 04:04:01 +02:00
AreaEffectCloud entityareaeffectcloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
2022-12-10 22:27:36 +01:00
Entity entity = this.getOwner();
2024-10-23 20:15:25 +02:00
@@ -246,14 +269,16 @@ public class ThrownPotion extends ThrowableItemProjectile {
2024-04-24 16:29:12 +02:00
entityareaeffectcloud.setWaitTime(10);
entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float) entityareaeffectcloud.getDuration());
entityareaeffectcloud.setPotionContents(potioncontents);
+ boolean noEffects = potioncontents.hasEffects(); // Paper - Fix potions splash events
2022-12-10 23:52:37 +01:00
// CraftBukkit start
2023-10-29 00:02:13 +02:00
org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, position, entityareaeffectcloud);
2022-12-10 23:52:37 +01:00
- if (!(event.isCancelled() || entityareaeffectcloud.isRemoved())) {
2024-04-24 16:29:12 +02:00
+ if (!(event.isCancelled() || entityareaeffectcloud.isRemoved() || (noEffects && !entityareaeffectcloud.potionContents.hasEffects()))) { // Paper - don't spawn area effect cloud if the effects were empty and not changed during the event handling
2023-06-08 04:04:01 +02:00
this.level().addFreshEntity(entityareaeffectcloud);
2022-12-10 23:52:37 +01:00
} else {
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
entityareaeffectcloud.discard(null); // CraftBukkit - add Bukkit remove cause
2022-12-10 22:27:36 +01:00
}
// CraftBukkit end
2024-01-19 13:22:30 +01:00
+ return !event.isCancelled(); // Paper - Fix potions splash events
2022-12-10 22:27:36 +01:00
}
public boolean isLingering() {
2024-02-10 20:27:29 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
Rework async chunk api implementation
Firstly, the old methods all routed to the CompletableFuture method.
However, the CF method could not guarantee that if the caller
was off-main that the future would be "completed" on-main. Since
the callback methods used the CF one, this meant that the callback
methods did not guarantee that the callbacks were to be called on
the main thread.
Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb)
so that the methods with the callback are guaranteed to invoke
the callback on the main thread. The CF behavior remains unchanged;
it may still appear to complete on main if invoked off-main.
Secondly, remove the scheduleOnMain invocation in the async
chunk completion. This unnecessarily delays the callback
by 1 tick.
Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which
will load chunks within an area. This method is provided as a helper
as keeping all chunks loaded within an area can be complicated to
implement for plugins (due to the lacking ticket API), and is
already implemented internally anyways.
Fourthly, remove the ticket addition that occured with getChunkAt
and getChunkAtAsync. The ticket addition may delay the unloading
of the chunk unnecessarily. It also fixes a very rare timing bug
where the future/callback would be completed after the chunk
unloads.
2024-11-19 07:34:32 +01:00
index 49efae40345fcfca8f80fcc541dcfde1b8a8b07b..24f86724012bb8bcd6d24683a1c78ce66b42ca30 100644
2024-02-10 20:27:29 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-10-23 20:15:25 +02:00
@@ -884,6 +884,32 @@ public class CraftEventFactory {
2024-02-10 20:27:29 +01:00
return event;
}
+ // Paper start - Fix potions splash events
+ public static io.papermc.paper.event.entity.WaterBottleSplashEvent callWaterBottleSplashEvent(net.minecraft.world.entity.projectile.ThrownPotion potion, @Nullable HitResult hitResult, Map<LivingEntity, Double> affectedEntities, java.util.Set<LivingEntity> rehydrate, java.util.Set<LivingEntity> extinguish) {
+ ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();
+
+ Block hitBlock = null;
+ BlockFace hitFace = null;
+ org.bukkit.entity.Entity hitEntity = null;
+
+ if (hitResult != null) {
+ if (hitResult.getType() == HitResult.Type.BLOCK) {
+ BlockHitResult blockHitResult = (BlockHitResult) hitResult;
+ hitBlock = CraftBlock.at(potion.level(), blockHitResult.getBlockPos());
+ hitFace = CraftBlock.notchToBlockFace(blockHitResult.getDirection());
+ } else if (hitResult.getType() == HitResult.Type.ENTITY) {
+ hitEntity = ((EntityHitResult) hitResult).getEntity().getBukkitEntity();
+ }
+ }
+
+ io.papermc.paper.event.entity.WaterBottleSplashEvent event = new io.papermc.paper.event.entity.WaterBottleSplashEvent(
+ thrownPotion, hitEntity, hitBlock, hitFace, affectedEntities, rehydrate, extinguish
+ );
+ event.callEvent();
+ return event;
+ }
+ // Paper end - Fix potions splash events
+
/**
* BlockFadeEvent
*/