diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch index 158eec4464..a6087a3bc0 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch @@ -18,17 +18,27 @@ public class EntityPotion extends EntityProjectileThrowable implements ItemSupplier { public static final double SPLASH_RANGE = 4.0D; -@@ -99,7 +110,7 @@ +@@ -99,11 +110,11 @@ if (flag) { this.applyWater(); - } else if (!list.isEmpty()) { + } else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply if (this.isLingering()) { - this.makeAreaOfEffectCloud(itemstack, potionregistry); +- this.makeAreaOfEffectCloud(itemstack, potionregistry); ++ this.makeAreaOfEffectCloud(itemstack, potionregistry, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition } else { -@@ -148,6 +159,7 @@ - private void applySplash(List list, @Nullable Entity entity) { +- this.applySplash(list, movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null); ++ this.applySplash(list, movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition + } + } + +@@ -145,9 +156,10 @@ + + } + +- private void applySplash(List list, @Nullable Entity entity) { ++ private void applySplash(List list, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D); List list1 = this.level().getEntitiesOfClass(EntityLiving.class, axisalignedbb); + Map affected = new HashMap(); // CraftBukkit @@ -50,7 +60,7 @@ - while (iterator1.hasNext()) { - MobEffect mobeffect = (MobEffect) iterator1.next(); - MobEffectList mobeffectlist = mobeffect.getEffect(); -+ org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, affected); ++ org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, position, affected); + if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process + Entity entity1 = this.getEffectSource(); + for (LivingEntity victim : event.getAffectedEntities()) { @@ -100,13 +110,22 @@ } } } +@@ -194,7 +231,7 @@ + + } + +- private void makeAreaOfEffectCloud(ItemStack itemstack, PotionRegistry potionregistry) { ++ private void makeAreaOfEffectCloud(ItemStack itemstack, PotionRegistry potionregistry, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition + EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ()); + Entity entity = this.getOwner(); + @@ -221,7 +258,14 @@ entityareaeffectcloud.setFixedColor(nbttagcompound.getInt("CustomPotionColor")); } - this.level().addFreshEntity(entityareaeffectcloud); + // CraftBukkit start -+ org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, entityareaeffectcloud); ++ org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, position, entityareaeffectcloud); + if (!(event.isCancelled() || entityareaeffectcloud.isRemoved())) { + this.level().addFreshEntity(entityareaeffectcloud); + } else { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch index bf66baf4cb..4d2228fa51 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch @@ -10,7 +10,7 @@ int i = 3 + this.level().random.nextInt(5) + this.level().random.nextInt(5); + // CraftBukkit start -+ org.bukkit.event.entity.ExpBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callExpBottleEvent(this, i); ++ org.bukkit.event.entity.ExpBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callExpBottleEvent(this, movingobjectposition, i); + i = event.getExperience(); + if (event.getShowEffect()) { + this.level().levelEvent(2002, this.blockPosition(), PotionUtil.getColor(Potions.WATER)); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index f3fedf149a..7e2ee03cc0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -787,19 +787,45 @@ public class CraftEventFactory { /** * PotionSplashEvent */ - public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, Map affectedEntities) { + public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, MovingObjectPosition position, Map affectedEntities) { ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity(); - PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities); + Block hitBlock = null; + BlockFace hitFace = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { + MovingObjectPositionBlock positionBlock = (MovingObjectPositionBlock) position; + hitBlock = CraftBlock.at(potion.level(), positionBlock.getBlockPos()); + hitFace = CraftBlock.notchToBlockFace(positionBlock.getDirection()); + } + + org.bukkit.entity.Entity hitEntity = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) { + hitEntity = ((MovingObjectPositionEntity) position).getEntity().getBukkitEntity(); + } + + PotionSplashEvent event = new PotionSplashEvent(thrownPotion, hitEntity, hitBlock, hitFace, affectedEntities); Bukkit.getPluginManager().callEvent(event); return event; } - public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(EntityPotion potion, EntityAreaEffectCloud cloud) { + public static LingeringPotionSplashEvent callLingeringPotionSplashEvent(EntityPotion potion, MovingObjectPosition position, EntityAreaEffectCloud cloud) { ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity(); AreaEffectCloud effectCloud = (AreaEffectCloud) cloud.getBukkitEntity(); - LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, effectCloud); + Block hitBlock = null; + BlockFace hitFace = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { + MovingObjectPositionBlock positionBlock = (MovingObjectPositionBlock) position; + hitBlock = CraftBlock.at(potion.level(), positionBlock.getBlockPos()); + hitFace = CraftBlock.notchToBlockFace(positionBlock.getDirection()); + } + + org.bukkit.entity.Entity hitEntity = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) { + hitEntity = ((MovingObjectPositionEntity) position).getEntity().getBukkitEntity(); + } + + LingeringPotionSplashEvent event = new LingeringPotionSplashEvent(thrownPotion, hitEntity, hitBlock, hitFace, effectCloud); Bukkit.getPluginManager().callEvent(event); return event; } @@ -1344,9 +1370,23 @@ public class CraftEventFactory { return event; } - public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) { + public static ExpBottleEvent callExpBottleEvent(Entity entity, MovingObjectPosition position, int exp) { ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity(); - ExpBottleEvent event = new ExpBottleEvent(bottle, exp); + + Block hitBlock = null; + BlockFace hitFace = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { + MovingObjectPositionBlock positionBlock = (MovingObjectPositionBlock) position; + hitBlock = CraftBlock.at(entity.level(), positionBlock.getBlockPos()); + hitFace = CraftBlock.notchToBlockFace(positionBlock.getDirection()); + } + + org.bukkit.entity.Entity hitEntity = null; + if (position.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) { + hitEntity = ((MovingObjectPositionEntity) position).getEntity().getBukkitEntity(); + } + + ExpBottleEvent event = new ExpBottleEvent(bottle, hitEntity, hitBlock, hitFace, exp); Bukkit.getPluginManager().callEvent(event); return event; }