PaperMC/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityArrow.patch
CraftBukkit/Spigot 3df6aee27f #776: Add ability to cancel ProjectileHitEvent
By: Martoph <sager1018@gmail.com>
2021-05-09 16:51:44 +10:00

64 lines
3.2 KiB
Diff

--- a/net/minecraft/world/entity/projectile/EntityArrow.java
+++ b/net/minecraft/world/entity/projectile/EntityArrow.java
@@ -45,6 +45,12 @@
import net.minecraft.world.phys.Vec3D;
import net.minecraft.world.phys.shapes.VoxelShape;
+// CraftBukkit start
+import net.minecraft.world.entity.item.EntityItem;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.player.PlayerPickupArrowEvent;
+// CraftBukkit end
+
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();
if (this.isBurning() && !flag) {
- entity.setOnFire(5);
+ // CraftBukkit start
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 5);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+ if (!combustEvent.isCancelled()) {
+ entity.setOnFire(combustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
}
if (entity.damageEntity(damagesource, (float) i)) {
@@ -495,9 +507,23 @@
@Override
public void pickup(EntityHuman entityhuman) {
if (!this.world.isClientSide && (this.inGround || this.t()) && this.shake <= 0) {
+ // CraftBukkit start
+ ItemStack itemstack = this.getItemStack();
+ if (this.fromPlayer == PickupStatus.ALLOWED && !itemstack.isEmpty() && entityhuman.inventory.canHold(itemstack) > 0) {
+ EntityItem item = new EntityItem(this.world, this.locX(), this.locY(), this.locZ(), itemstack);
+ PlayerPickupArrowEvent event = new PlayerPickupArrowEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), this, item), (org.bukkit.entity.AbstractArrow) this.getBukkitEntity());
+ // event.setCancelled(!entityhuman.canPickUpLoot); TODO
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return;
+ }
+ itemstack = item.getItemStack();
+ }
boolean flag = this.fromPlayer == EntityArrow.PickupStatus.ALLOWED || this.fromPlayer == EntityArrow.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.canInstantlyBuild || this.t() && this.getShooter().getUniqueID() == entityhuman.getUniqueID();
- if (this.fromPlayer == EntityArrow.PickupStatus.ALLOWED && !entityhuman.inventory.pickup(this.getItemStack())) {
+ if (this.fromPlayer == EntityArrow.PickupStatus.ALLOWED && !entityhuman.inventory.pickup(itemstack)) {
+ // CraftBukkit end
flag = false;
}