Yatopia/patches/server/0051-PlayerAttackEntityEvent.patch
Ivan Pekov 56cfcf9e99
Properly handle PlayerAttackEntityEvent
smaller diff and also fixes an issue the entity has been put on fire but no other damage dealt
2020-09-22 15:21:04 +03:00

60 lines
2.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Tue, 22 Sep 2020 12:52:34 +0300
Subject: [PATCH] PlayerAttackEntityEvent
Added per request
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index a64683d1d21c282b249e2dd07cbb497721f1052d..a7758c07270aedabe19dc6b1aa96e58ebe87648b 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -1058,11 +1058,47 @@ public abstract class EntityHuman extends EntityLiving {
flag2 = flag2 && !world.paperConfig.disablePlayerCrits; // Paper
flag2 = flag2 && !this.isSprinting();
+ /* // Yatopia start - PlayerAttackEntityEvent
if (flag2) {
f *= 1.5F;
}
f += f1;
+ */
+ net.yatopia.api.event.PlayerAttackEntityEvent playerAttackEntityEvent =
+ new net.yatopia.api.event.PlayerAttackEntityEvent(
+ getBukkitEntity(),
+ entity.getBukkitEntity(),
+ org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(getItemInMainHand()),
+ flag2, f + f1
+ );
+ float totalDamage = f + f1;
+ org.bukkit.Bukkit.getPluginManager().callEvent(playerAttackEntityEvent);
+ if (playerAttackEntityEvent.isCancelled()) {
+ return;
+ }
+ flag2 = playerAttackEntityEvent.isCritical() && !world.paperConfig.disablePlayerCrits;
+ if (playerAttackEntityEvent.getDamage() == totalDamage) {
+ if (flag2) {
+ f *= 1.5F;
+ }
+ f += f1;
+ } else {
+ if (playerAttackEntityEvent.getDamage() < 0) {
+ return;
+ }
+ float damage = playerAttackEntityEvent.getDamage() - f1;
+ if (damage < 0) {
+ return;
+ }
+ if (flag2) {
+ damage *= 1.5F;
+ }
+ damage += f1;
+ f = damage;
+ }
+ // Yatopia end
+
boolean flag3 = false;
double d0 = (double) (this.A - this.z);