From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <blake.galbreath@gmail.com>
Date: Tue, 24 Nov 2020 04:30:46 -0600
Subject: [PATCH] Add critical hit check to EntityDamagedByEntityEvent


diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 3a7dc584bd2b88415a238f9c0cb7f85968fb8dfb..7ce46b53ad9fbaf7baf198557565b2467ab43c09 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -73,6 +73,7 @@ public abstract class EntityHuman extends EntityLiving {
     // Paper start
     public boolean affectsSpawning = true;
     // Paper end
+    public boolean isCritical = false; // Purpur
 
     // CraftBukkit start
     public boolean fauxSleeping;
@@ -1066,6 +1067,7 @@ public abstract class EntityHuman extends EntityLiving {
                     flag2 = flag2 && !world.paperConfig.disablePlayerCrits; // Paper
                     flag2 = flag2 && !this.isSprinting();
                     if (flag2) {
+                        this.isCritical = true; // Purpur
                         f *= 1.5F;
                     }
 
@@ -1102,6 +1104,7 @@ public abstract class EntityHuman extends EntityLiving {
 
                     Vec3D vec3d = entity.getMot();
                     boolean flag5 = entity.damageEntity(DamageSource.playerAttack(this), f);
+                    this.isCritical = false; // Purpur
 
                     if (flag5) {
                         if (i > 0) {
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index c4d0082bb0d310ad16de36df03dd99225c5cadb0..22aaa4efd0f5e89f66abf6a9054b595f52e7129b 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1074,7 +1074,7 @@ public class CraftEventFactory {
     private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions, boolean cancelled) {
         EntityDamageEvent event;
         if (damager != null) {
-            event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
+            event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions, damager instanceof HumanEntity && ((EntityHuman)damager).isCritical); // Purpur
             damager.processClick(EnumHand.MAIN_HAND); // Purpur
         } else {
             event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
