13
0
geforkt von Mirrors/Paper

#776: Add ability to cancel ProjectileHitEvent

By: Martoph <sager1018@gmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2021-05-09 16:51:44 +10:00
Ursprung 9d5bc88891
Commit 3df6aee27f
9 geänderte Dateien mit 101 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -13,6 +13,15 @@
public abstract class EntityArrow extends IProjectile {
private static final DataWatcherObject<Byte> f = DataWatcher.a(EntityArrow.class, DataWatcherRegistry.a);
@@ -181,7 +187,7 @@
}
if (object != null && !flag) {
- this.a((MovingObjectPosition) object);
+ this.preOnHit((MovingObjectPosition) object); // CraftBukkit - projectile hit event
this.impulse = true;
}
@@ -328,7 +334,13 @@
int k = entity.getFireTicks();

Datei anzeigen

@ -29,10 +29,12 @@
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
if (d6 != 0.0D) {
@@ -64,6 +74,12 @@
@@ -63,7 +73,13 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
this.a(movingobjectposition);
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
+
+ // CraftBukkit start - Fire ProjectileHitEvent
+ if (this.dead) {

Datei anzeigen

@ -9,6 +9,15 @@
public class EntityFireworks extends IProjectile {
public static final DataWatcherObject<ItemStack> FIREWORK_ITEM = DataWatcher.a(EntityFireworks.class, DataWatcherRegistry.g);
@@ -130,7 +132,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
if (!this.noclip) {
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
this.impulse = true;
}
@@ -145,7 +147,11 @@
}

Datei anzeigen

@ -26,6 +26,15 @@
private EntityFishingHook(World world, EntityHuman entityhuman, int i, int j) {
super(EntityTypes.FISHING_BOBBER, world);
this.b = new Random();
@@ -244,7 +256,7 @@
private void m() {
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
@Override
@@ -291,6 +303,10 @@
this.waitTime = 0;
this.ai = 0;

Datei anzeigen

@ -0,0 +1,11 @@
--- a/net/minecraft/world/entity/projectile/EntityLlamaSpit.java
+++ b/net/minecraft/world/entity/projectile/EntityLlamaSpit.java
@@ -34,7 +34,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
if (movingobjectposition != null) {
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
double d0 = this.locX() + vec3d.x;

Datei anzeigen

@ -0,0 +1,11 @@
--- a/net/minecraft/world/entity/projectile/EntityProjectile.java
+++ b/net/minecraft/world/entity/projectile/EntityProjectile.java
@@ -57,7 +57,7 @@
}
if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS && !flag) {
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
this.checkBlockCollisions();

Datei anzeigen

@ -22,6 +22,15 @@
@Override
public SoundCategory getSoundCategory() {
return SoundCategory.HOSTILE;
@@ -218,7 +231,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.a((Entity) this, this::a);
if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) {
- this.a(movingobjectposition);
+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
}
}
@@ -280,7 +293,7 @@
if (flag) {
this.a(entityliving, entity);

Datei anzeigen

@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/projectile/IProjectile.java
+++ b/net/minecraft/world/entity/projectile/IProjectile.java
@@ -15,6 +15,10 @@
@@ -15,12 +15,20 @@
import net.minecraft.world.phys.MovingObjectPositionEntity;
import net.minecraft.world.phys.Vec3D;
@ -11,7 +11,17 @@
public abstract class IProjectile extends Entity {
private UUID shooter;
@@ -30,6 +34,7 @@
private int c;
private boolean d;
+ // CraftBukkit start
+ private boolean hitCancelled = false;
+ // CraftBukkit end
+
IProjectile(EntityTypes<? extends IProjectile> entitytypes, World world) {
super(entitytypes, world);
}
@@ -30,6 +38,7 @@
this.shooter = entity.getUniqueID();
this.c = entity.getId();
}
@ -19,11 +29,32 @@
}
@@ -112,6 +117,7 @@
@@ -111,6 +120,16 @@
this.setMot(this.getMot().add(vec3d.x, entity.isOnGround() ? 0.0D : vec3d.y, vec3d.z));
}
+ // CraftBukkit start - call projectile hit event
+ protected void preOnHit(MovingObjectPosition movingobjectposition) {
+ org.bukkit.event.entity.ProjectileHitEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
+ this.hitCancelled = event != null && event.isCancelled();
+ if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK || !this.hitCancelled) {
+ this.a(movingobjectposition); // PAIL rename onHit
+ }
+ }
+ // CraftBukkit end
+
protected void a(MovingObjectPosition movingobjectposition) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // CraftBukkit - Call event
MovingObjectPosition.EnumMovingObjectType movingobjectposition_enummovingobjecttype = movingobjectposition.getType();
if (movingobjectposition_enummovingobjecttype == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
@@ -125,6 +144,11 @@
protected void a(MovingObjectPositionEntity movingobjectpositionentity) {}
protected void a(MovingObjectPositionBlock movingobjectpositionblock) {
+ // CraftBukkit start - cancellable hit event
+ if (hitCancelled) {
+ return;
+ }
+ // CraftBukkit end
IBlockData iblockdata = this.world.getType(movingobjectpositionblock.getBlockPosition());
iblockdata.a(this.world, iblockdata, movingobjectpositionblock, this);

Datei anzeigen

@ -1167,9 +1167,9 @@ public class CraftEventFactory {
return event;
}
public static void callProjectileHitEvent(Entity entity, MovingObjectPosition position) {
public static ProjectileHitEvent callProjectileHitEvent(Entity entity, MovingObjectPosition position) {
if (position.getType() == MovingObjectPosition.EnumMovingObjectType.MISS) {
return;
return null;
}
Block hitBlock = null;
@ -1187,6 +1187,7 @@ public class CraftEventFactory {
ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), hitEntity, hitBlock, hitFace);
entity.world.getServer().getPluginManager().callEvent(event);
return event;
}
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {