aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0757-Add-PrePlayerAttackEntityEvent.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0757-Add-PrePlayerAttackEntityEvent.patch')
-rw-r--r--patches/server/0757-Add-PrePlayerAttackEntityEvent.patch30
1 files changed, 30 insertions, 0 deletions
diff --git a/patches/server/0757-Add-PrePlayerAttackEntityEvent.patch b/patches/server/0757-Add-PrePlayerAttackEntityEvent.patch
new file mode 100644
index 0000000000..5a925374e5
--- /dev/null
+++ b/patches/server/0757-Add-PrePlayerAttackEntityEvent.patch
@@ -0,0 +1,30 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Owen1212055 <[email protected]>
+Date: Sun, 18 Sep 2022 13:10:18 -0400
+Subject: [PATCH] Add PrePlayerAttackEntityEvent
+
+
+diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
+index b8edbd23d547d7189ec64c5d3a8cd1d51859ce23..30e0a5fe3f9bd85d2b702c2c877c5682ed35d461 100644
+--- a/src/main/java/net/minecraft/world/entity/player/Player.java
++++ b/src/main/java/net/minecraft/world/entity/player/Player.java
+@@ -1222,8 +1222,17 @@ public abstract class Player extends LivingEntity {
+ }
+
+ public void attack(Entity target) {
+- if (target.isAttackable()) {
+- if (!target.skipAttackInteraction(this)) {
++ // Paper start - PlayerAttackEntityEvent
++ boolean willAttack = target.isAttackable() && !target.skipAttackInteraction(this); // Vanilla logic
++ io.papermc.paper.event.player.PrePlayerAttackEntityEvent playerAttackEntityEvent = new io.papermc.paper.event.player.PrePlayerAttackEntityEvent(
++ (org.bukkit.entity.Player) this.getBukkitEntity(),
++ target.getBukkitEntity(),
++ willAttack
++ );
++
++ if (playerAttackEntityEvent.callEvent() && willAttack) { // Logic moved to willAttack local variable.
++ {
++ // Paper end - PlayerAttackEntityEvent
+ float f = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : (float) this.getAttributeValue(Attributes.ATTACK_DAMAGE);
+ ItemStack itemstack = this.getWeaponItem();
+ DamageSource damagesource = (DamageSource) Optional.ofNullable(itemstack.getItem().getDamageSource(this)).orElse(this.damageSources().playerAttack(this));