3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0114-Add-ProjectileCollideEvent.patch
Jason Penilla 0fa2a949ae
Updated Upstream (Bukkit/CraftBukkit/Spigot)
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:
8503c3c9 #621: Add HumanEntity#getItemInUse and Material#getSlipperiness
248deb09 #622: Add methods to check if item is the breed item for an entity
2ce691d8 Clarify Player#breakBlock only works for blocks in the same world
5dcdd48e SPIGOT-6514: Small Dripleaf block data is missing half property
cc9610b7 #619: Add Player#breakBlock()
862bc475 Fix bad merge of SPIGOT-6502 fix
989bb0c1 Downgrade SnakeYAML due to issues with comments parsing
1dff62ae Fix inverted visual fire docs

CraftBukkit Changes:
40caacc8 SPIGOT-6526: World entities are not populated when plugin onEnable is called
c9a92ad0 SPIGOT-6536: Marker position not set on spawn
20d3e57c #855: Add HumanEntity#getItemInUse and Material#getSlipperiness
d9c69b44 SPIGOT-6529: Fix BundleMeta#setItems
8bd43be5 SPIGOT-6535: PlayerGameModeChangeEvent event incorrectly reports old gamemode
4ece3ff3 #856: Add methods to check if item is the breed item for an entity
dd4bec5f Add additional validation to Player#breakBlock
bc835ae6 SPIGOT-6532: Fix Entity#setGlowing
384e116e Restore 1.16.5 behaviour of InventoryDragEvent being called even when a single item is 'dragged' to its own slot
b42e708c Fix new map colors rendering as transparent
cfe7fecf SPIGOT-6524: Inventory desync when InventoryClickEvent is cancelled
eeae1b19 SPIGOT-6522: ItemStack on cursor is always AIR
7490724d Fix missing PlayerEditBookEvent
06875f76 SPIGOT-6513: Placing ItemStack in Inventory causes InventoryAction.NOTHING
27835bde SPIGOT-6519: Fix end gateway teleports
4ac634ad SPIGOT-6515: "Un-waterlogging" throws UnsupportedOperationException in some cases
da425fa2 SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server
50530da9 SPIGOT-6514: Small Dripleaf block data is missing half property
6fdecf20 #853: Implement Player#breakBlock()
4db9c49f SPIGOT-6510: Bukkit#createMap throws NullPointerException
89e2b127 SPIGOT-6517: Spider jockey crash on dripstone
cbf2f678 SPIGOT-6508: Rename conflicted getServer
74575d48 SPIGOT-6506: Fix crash with custom inventories
a3df386f Fix NPE with Entity.getNearbyEntities
d747f8ed Fix NPE with World.getNearbyEntities
4d2c7800 Fix second usage of worldGenSettings just in case
5182f923 SPIGOT-6504: Fix generating fresh worlds

Spigot Changes:
66f9d3c1 Rebuild patches
191e4971 Rebuild patches
a09c0bb6 Restore Spigot experience merging
2021-06-12 22:13:07 -07:00

110 Zeilen
6.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Techcable <Techcable@outlook.com>
Date: Fri, 16 Dec 2016 21:25:39 -0600
Subject: [PATCH] Add ProjectileCollideEvent
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
index 676e5ad3a23bfdccd8f5f7bb9e79c3fa004dc95f..71f0de893fe0243cc226fd36685f2a3fba02575f 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
@@ -225,6 +225,17 @@ public abstract class AbstractArrow extends Projectile {
}
}
+ // Paper start - Call ProjectileCollideEvent
+ // TODO: flag - noclip - call cancelled?
+ if (object instanceof EntityHitResult) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)object);
+ if (event.isCancelled()) {
+ object = null;
+ movingobjectpositionentity = null;
+ }
+ }
+ // Paper end
+
if (object != null && !flag) {
this.preOnHit((HitResult) object); // CraftBukkit - projectile hit event
this.hasImpulse = true;
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
index a8b51bece92676f1964a795112a1d490b437ed0f..dd5209ab2e5b59312349e709392689f25da162c0 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractHurtingProjectile.java
@@ -11,6 +11,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
+import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
@@ -82,7 +83,16 @@ public abstract class AbstractHurtingProjectile extends Projectile {
HitResult movingobjectposition = ProjectileUtil.getHitResult((Entity) this, this::canHitEntity);
- if (movingobjectposition.getType() != HitResult.Type.MISS) {
+ // Paper start - Call ProjectileCollideEvent
+ if (movingobjectposition instanceof EntityHitResult) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)movingobjectposition);
+ if (event.isCancelled()) {
+ movingobjectposition = null;
+ }
+ }
+ // Paper end
+
+ if (movingobjectposition != null && movingobjectposition.getType() != HitResult.Type.MISS) { // Paper - add null check in case cancelled
this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
// CraftBukkit start - Fire ProjectileHitEvent
diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java b/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
index f81be1c6a5efc5090fbb8832f44dbb2ae6aa2f4a..8e81b19706a14c21b5ffdc4f12818fe74adc9ddb 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrowableProjectile.java
@@ -11,6 +11,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
+import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
@@ -67,7 +68,17 @@ public abstract class ThrowableProjectile extends Projectile {
}
if (movingobjectposition.getType() != HitResult.Type.MISS && !flag) {
+ // Paper start - Call ProjectileCollideEvent
+ if (movingobjectposition instanceof EntityHitResult) {
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileCollideEvent(this, (EntityHitResult)movingobjectposition);
+ if (event.isCancelled()) {
+ movingobjectposition = null;
+ }
+ }
+ if (movingobjectposition != null) {
+ // Paper end
this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event
+ } // Paper
}
this.checkInsideBlocks();
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index f32a2a96da71c1cbcf0d153d882ff60ca66ffd2a..1fce91a05a6b04a8d93d2707637c5b96c318a641 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1201,6 +1201,16 @@ public class CraftEventFactory {
return CraftItemStack.asNMSCopy(bitem);
}
+ // Paper start
+ public static com.destroystokyo.paper.event.entity.ProjectileCollideEvent callProjectileCollideEvent(Entity entity, EntityHitResult position) {
+ Projectile projectile = (Projectile) entity.getBukkitEntity();
+ org.bukkit.entity.Entity collided = position.getEntity().getBukkitEntity();
+ com.destroystokyo.paper.event.entity.ProjectileCollideEvent event = new com.destroystokyo.paper.event.entity.ProjectileCollideEvent(projectile, collided);
+ Bukkit.getPluginManager().callEvent(event);
+ return event;
+ }
+ // Paper end
+
public static ProjectileLaunchEvent callProjectileLaunchEvent(Entity entity) {
Projectile bukkitEntity = (Projectile) entity.getBukkitEntity();
ProjectileLaunchEvent event = new ProjectileLaunchEvent(bukkitEntity);