mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 17:52:28 +01:00
#1281: Add hit entity/block to events extending ProjectileHitEvent
By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
parent
fa30894970
commit
511d6753cc
3 changed files with 72 additions and 13 deletions
|
@ -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<MobEffect> 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<MobEffect> list, @Nullable Entity entity) {
|
||||
+ private void applySplash(List<MobEffect> list, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition
|
||||
AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D);
|
||||
List<EntityLiving> list1 = this.level().getEntitiesOfClass(EntityLiving.class, axisalignedbb);
|
||||
+ Map<LivingEntity, Double> affected = new HashMap<LivingEntity, Double>(); // 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 {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -787,19 +787,45 @@ public class CraftEventFactory {
|
|||
/**
|
||||
* PotionSplashEvent
|
||||
*/
|
||||
public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, Map<LivingEntity, Double> affectedEntities) {
|
||||
public static PotionSplashEvent callPotionSplashEvent(EntityPotion potion, MovingObjectPosition position, Map<LivingEntity, Double> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue