From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <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/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index 3e04510519ca5d03eb16aab8b1094e24101cebf4..12a3304c3b465f2a9d7cf279ea7b945bb3b8f6a1 100644
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -182,6 +182,7 @@ public abstract class Player extends LivingEntity {
     // Paper start
     public boolean affectsSpawning = true;
     // Paper end
+    public boolean isCritical = false; // Purpur
 
     // CraftBukkit start
     public boolean fauxSleeping;
@@ -1243,6 +1244,7 @@ public abstract class Player extends LivingEntity {
                     flag2 = flag2 && !level.paperConfig.disablePlayerCrits; // Paper
                     flag2 = flag2 && !this.isSprinting();
                     if (flag2) {
+                        this.isCritical = true; // Purpur
                         f *= 1.5F;
                     }
 
@@ -1279,6 +1281,7 @@ public abstract class Player extends LivingEntity {
 
                     Vec3 vec3d = target.getDeltaMovement();
                     boolean flag5 = target.hurt(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 89ad1c69456fb4aaf2ab8742c76343b30b74ecd0..c763fce31b074d396a9134c5412bce77a9625c9a 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -968,7 +968,7 @@ public class CraftEventFactory {
                 } else {
                     damageCause = DamageCause.ENTITY_EXPLOSION;
                 }
-                event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions);
+                event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), entity.getBukkitEntity(), damageCause, modifiers, modifierFunctions, damager instanceof HumanEntity && ((net.minecraft.world.entity.player.Player) damager).isCritical); // Purpur
                 damager.processClick(InteractionHand.MAIN_HAND); // Purpur
             }
             event.setCancelled(cancelled);
@@ -1049,7 +1049,7 @@ public class CraftEventFactory {
             } else {
                 throw new IllegalStateException(String.format("Unhandled damage of %s by %s from %s", entity, damager.getHandle(), source.msgId));
             }
-            EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions);
+            EntityDamageEvent event = new EntityDamageByEntityEvent(damager, entity.getBukkitEntity(), cause, modifiers, modifierFunctions, entityDamage instanceof HumanEntity && ((net.minecraft.world.entity.player.Player) entityDamage).isCritical); // Purpur
             event.setCancelled(cancelled);
             CraftEventFactory.callEvent(event);
             if (!event.isCancelled()) {
@@ -1106,7 +1106,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 && ((net.minecraft.world.entity.player.Player) damager).isCritical); // Purpur
             damager.processClick(InteractionHand.MAIN_HAND); // Purpur
         } else {
             event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
