diff --git a/paper-server/nms-patches/Block.patch b/paper-server/nms-patches/Block.patch index b7478480fc..9c455095dc 100644 --- a/paper-server/nms-patches/Block.patch +++ b/paper-server/nms-patches/Block.patch @@ -15,6 +15,15 @@ } } +@@ -240,7 +246,7 @@ + + public void a(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, @Nullable TileEntity tileentity, ItemStack itemstack) { + entityhuman.b(StatisticList.BLOCK_MINED.b(this)); +- entityhuman.applyExhaustion(0.005F); ++ entityhuman.applyExhaustion(0.005F, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.BLOCK_MINED); // CraftBukkit - EntityExhaustionEvent + dropItems(iblockdata, world, blockposition, tileentity, entityhuman, itemstack); + } + @@ -336,6 +342,12 @@ return this; } diff --git a/paper-server/nms-patches/EntityHuman.patch b/paper-server/nms-patches/EntityHuman.patch index 12a786ef0f..0e63dad0c6 100644 --- a/paper-server/nms-patches/EntityHuman.patch +++ b/paper-server/nms-patches/EntityHuman.patch @@ -1,16 +1,18 @@ --- a/net/minecraft/server/EntityHuman.java +++ b/net/minecraft/server/EntityHuman.java -@@ -16,10 +16,22 @@ +@@ -16,10 +16,24 @@ import java.util.function.Predicate; import javax.annotation.Nullable; +// CraftBukkit start +import org.bukkit.craftbukkit.entity.CraftHumanEntity; ++import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.util.CraftVector; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityCombustByEntityEvent; ++import org.bukkit.event.entity.EntityExhaustionEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +// CraftBukkit end @@ -24,7 +26,7 @@ private static final DataWatcherObject c = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.c); private static final DataWatcherObject d = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.b); protected static final DataWatcherObject bi = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.a); -@@ -28,10 +40,10 @@ +@@ -28,10 +42,10 @@ protected static final DataWatcherObject bl = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.p); private long e; public final PlayerInventory inventory = new PlayerInventory(this); @@ -37,7 +39,7 @@ protected int br; public float bs; public float bt; -@@ -57,6 +69,16 @@ +@@ -57,6 +71,16 @@ @Nullable public EntityFishingHook hookedFish; @@ -54,7 +56,7 @@ public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) { super(EntityTypes.PLAYER, world); this.bL = ItemStack.b; -@@ -194,7 +216,7 @@ +@@ -194,7 +218,7 @@ ItemStack itemstack = this.getEquipment(EnumItemSlot.HEAD); if (itemstack.getItem() == Items.TURTLE_HELMET && !this.a((Tag) TagsFluid.WATER)) { @@ -63,7 +65,7 @@ } } -@@ -359,7 +381,8 @@ +@@ -359,7 +383,8 @@ if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL && this.world.getGameRules().getBoolean(GameRules.NATURAL_REGENERATION)) { if (this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 == 0) { @@ -73,7 +75,7 @@ } if (this.foodData.c() && this.ticksLived % 10 == 0) { -@@ -544,6 +567,30 @@ +@@ -544,6 +569,30 @@ entityitem.setMot((double) (-f3 * f2 * 0.3F) + Math.cos((double) f5) * (double) f6, (double) (-f1 * 0.3F + 0.1F + (this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (f4 * f2 * 0.3F) + Math.sin((double) f5) * (double) f6); } @@ -104,7 +106,7 @@ return entityitem; } } -@@ -670,16 +717,17 @@ +@@ -670,16 +719,17 @@ if (this.isInvulnerable(damagesource)) { return false; } else if (this.abilities.isInvulnerable && !damagesource.ignoresInvulnerability()) { @@ -124,7 +126,7 @@ } if (this.world.getDifficulty() == EnumDifficulty.EASY) { -@@ -691,7 +739,13 @@ +@@ -691,7 +741,13 @@ } } @@ -139,7 +141,7 @@ } } } -@@ -706,10 +760,29 @@ +@@ -706,10 +762,29 @@ } public boolean a(EntityHuman entityhuman) { @@ -172,7 +174,7 @@ } @Override -@@ -746,8 +819,13 @@ +@@ -746,8 +821,13 @@ } } @@ -187,7 +189,16 @@ if (!this.isInvulnerable(damagesource)) { f = this.applyArmorModifier(damagesource, f); f = this.applyMagicModifier(damagesource, f); -@@ -773,6 +851,7 @@ +@@ -762,7 +842,7 @@ + } + + if (f != 0.0F) { +- this.applyExhaustion(damagesource.getExhaustionCost()); ++ this.applyExhaustion(damagesource.getExhaustionCost(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent + float f3 = this.getHealth(); + + this.setHealth(this.getHealth() - f); +@@ -773,6 +853,7 @@ } } @@ -195,7 +206,7 @@ } @Override -@@ -932,7 +1011,7 @@ +@@ -932,7 +1013,7 @@ f *= 0.2F + f2 * f2 * 0.8F; f1 *= f2; @@ -204,7 +215,7 @@ if (f > 0.0F || f1 > 0.0F) { boolean flag = f2 > 0.9F; boolean flag1 = false; -@@ -971,8 +1050,15 @@ +@@ -971,8 +1052,15 @@ if (entity instanceof EntityLiving) { f3 = ((EntityLiving) entity).getHealth(); if (j > 0 && !entity.isBurning()) { @@ -222,7 +233,7 @@ } } -@@ -1000,8 +1086,11 @@ +@@ -1000,8 +1088,11 @@ EntityLiving entityliving = (EntityLiving) iterator.next(); if (entityliving != this && entityliving != entity && !this.r(entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) entityliving).isMarker()) && this.h((Entity) entityliving) < 9.0D) { @@ -235,7 +246,7 @@ } } -@@ -1010,9 +1099,26 @@ +@@ -1010,9 +1101,26 @@ } if (entity instanceof EntityPlayer && entity.velocityChanged) { @@ -262,7 +273,7 @@ } if (flag2) { -@@ -1057,7 +1163,14 @@ +@@ -1057,7 +1165,14 @@ this.a(StatisticList.DAMAGE_DEALT, Math.round(f5 * 10.0F)); if (j > 0) { @@ -278,7 +289,14 @@ } if (this.world instanceof WorldServer && f5 > 2.0F) { -@@ -1073,6 +1186,11 @@ +@@ -1067,12 +1182,17 @@ + } + } + +- this.applyExhaustion(0.1F); ++ this.applyExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent + } else { + this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F); if (flag4) { entity.extinguish(); } @@ -290,7 +308,7 @@ } } -@@ -1133,6 +1251,12 @@ +@@ -1133,6 +1253,12 @@ } public Either sleep(BlockPosition blockposition) { @@ -303,7 +321,19 @@ this.entitySleep(blockposition); this.sleepTicks = 0; return Either.right(Unit.INSTANCE); -@@ -1253,7 +1377,11 @@ +@@ -1217,9 +1343,9 @@ + super.jump(); + this.a(StatisticList.JUMP); + if (this.isSprinting()) { +- this.applyExhaustion(0.2F); ++ this.applyExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent + } else { +- this.applyExhaustion(0.05F); ++ this.applyExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent + } + + } +@@ -1253,7 +1379,11 @@ this.setMot(vec3d2.x, d3 * 0.6D, vec3d2.z); this.aE = f; this.fallDistance = 0.0F; @@ -316,7 +346,47 @@ } else { super.g(vec3d); } -@@ -1383,12 +1511,24 @@ +@@ -1288,19 +1418,19 @@ + i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); + if (i > 0) { + this.a(StatisticList.SWIM_ONE_CM, i); +- this.applyExhaustion(0.01F * (float) i * 0.01F); ++ this.applyExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SWIM); // CraftBukkit - EntityExhaustionEvent + } + } else if (this.a((Tag) TagsFluid.WATER)) { + i = Math.round(MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); + if (i > 0) { + this.a(StatisticList.WALK_UNDER_WATER_ONE_CM, i); +- this.applyExhaustion(0.01F * (float) i * 0.01F); ++ this.applyExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_UNDERWATER); // CraftBukkit - EntityExhaustionEvent + } + } else if (this.isInWater()) { + i = Math.round(MathHelper.sqrt(d0 * d0 + d2 * d2) * 100.0F); + if (i > 0) { + this.a(StatisticList.WALK_ON_WATER_ONE_CM, i); +- this.applyExhaustion(0.01F * (float) i * 0.01F); ++ this.applyExhaustion(0.01F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK_ON_WATER); // CraftBukkit - EntityExhaustionEvent + } + } else if (this.isClimbing()) { + if (d1 > 0.0D) { +@@ -1311,13 +1441,13 @@ + if (i > 0) { + if (this.isSprinting()) { + this.a(StatisticList.SPRINT_ONE_CM, i); +- this.applyExhaustion(0.1F * (float) i * 0.01F); ++ this.applyExhaustion(0.1F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.SPRINT); // CraftBukkit - EntityExhaustionEvent + } else if (this.bz()) { + this.a(StatisticList.CROUCH_ONE_CM, i); +- this.applyExhaustion(0.0F * (float) i * 0.01F); ++ this.applyExhaustion(0.0F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.CROUCH); // CraftBukkit - EntityExhaustionEvent + } else { + this.a(StatisticList.WALK_ONE_CM, i); +- this.applyExhaustion(0.0F * (float) i * 0.01F); ++ this.applyExhaustion(0.0F * (float) i * 0.01F, EntityExhaustionEvent.ExhaustionReason.WALK); // CraftBukkit - EntityExhaustionEvent + } + } + } else if (this.isGliding()) { +@@ -1383,12 +1513,24 @@ } public void startGliding() { @@ -342,7 +412,30 @@ } @Override -@@ -1555,14 +1695,21 @@ +@@ -1478,10 +1620,21 @@ + return this.expLevel >= 30 ? 112 + (this.expLevel - 30) * 9 : (this.expLevel >= 15 ? 37 + (this.expLevel - 15) * 5 : 7 + this.expLevel * 2); + } + ++ // CraftBukkit start + public void applyExhaustion(float f) { ++ this.applyExhaustion(f, EntityExhaustionEvent.ExhaustionReason.UNKNOWN); ++ } ++ ++ public void applyExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) { ++ // CraftBukkit end + if (!this.abilities.isInvulnerable) { + if (!this.world.isClientSide) { +- this.foodData.a(f); ++ // CraftBukkit start ++ EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent(this, reason, f); ++ if (!event.isCancelled()) { ++ this.foodData.a(event.getExhaustion()); // PAIL rename addExhaustion ++ } ++ // CraftBukkit end + } + + } +@@ -1555,14 +1708,21 @@ @Override public void setSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { @@ -367,7 +460,7 @@ this.inventory.armor.set(enumitemslot.b(), itemstack); } -@@ -1603,26 +1750,31 @@ +@@ -1603,26 +1763,31 @@ protected void releaseShoulderEntities() { if (this.e + 20L < this.world.getTime()) { diff --git a/paper-server/nms-patches/EntityLiving.patch b/paper-server/nms-patches/EntityLiving.patch index 34ce357f42..a8f6aad8a8 100644 --- a/paper-server/nms-patches/EntityLiving.patch +++ b/paper-server/nms-patches/EntityLiving.patch @@ -729,7 +729,7 @@ + if (f > 0 || !human) { + if (human) { + // PAIL: Be sure to drag all this code from the EntityHuman subclass each update. -+ ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost()); ++ ((EntityHuman) this).applyExhaustion(damagesource.getExhaustionCost(), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent + if (f < 3.4028235E37F) { + ((EntityHuman) this).a(StatisticList.DAMAGE_TAKEN, Math.round(f * 10.0F)); + } diff --git a/paper-server/nms-patches/FoodMetaData.patch b/paper-server/nms-patches/FoodMetaData.patch index 2f0e4bdf78..054cc9be7a 100644 --- a/paper-server/nms-patches/FoodMetaData.patch +++ b/paper-server/nms-patches/FoodMetaData.patch @@ -55,20 +55,25 @@ } } -@@ -44,14 +69,14 @@ +@@ -44,15 +69,17 @@ if (this.foodTickTimer >= 10) { float f = Math.min(this.saturationLevel, 6.0F); - entityhuman.heal(f / 6.0F); +- this.a(f); + entityhuman.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason - this.a(f); ++ // this.a(f); CraftBukkit - EntityExhaustionEvent ++ entityhuman.applyExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.foodTickTimer = 0; } } else if (flag && this.foodLevel >= 18 && entityhuman.eJ()) { ++this.foodTickTimer; if (this.foodTickTimer >= 80) { - entityhuman.heal(1.0F); +- this.a(6.0F); + entityhuman.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason - this.a(6.0F); ++ // this.a(6.0F); CraftBukkit - EntityExhaustionEvent ++ entityhuman.applyExhaustion(6.0f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.foodTickTimer = 0; } + } else if (this.foodLevel <= 0) { diff --git a/paper-server/nms-patches/MobEffectList.patch b/paper-server/nms-patches/MobEffectList.patch index b3e7e1ce07..463f698344 100644 --- a/paper-server/nms-patches/MobEffectList.patch +++ b/paper-server/nms-patches/MobEffectList.patch @@ -21,7 +21,7 @@ } protected MobEffectList(MobEffectInfo mobeffectinfo, int i) { -@@ -32,11 +37,11 @@ +@@ -32,26 +37,37 @@ public void tick(EntityLiving entityliving, int i) { if (this == MobEffects.REGENERATION) { if (entityliving.getHealth() < entityliving.getMaxHealth()) { @@ -35,8 +35,9 @@ } } else if (this == MobEffects.WITHER) { entityliving.damageEntity(DamageSource.WITHER, 1.0F); -@@ -44,14 +49,25 @@ - ((EntityHuman) entityliving).applyExhaustion(0.005F * (float) (i + 1)); + } else if (this == MobEffects.HUNGER && entityliving instanceof EntityHuman) { +- ((EntityHuman) entityliving).applyExhaustion(0.005F * (float) (i + 1)); ++ ((EntityHuman) entityliving).applyExhaustion(0.005F * (float) (i + 1), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.HUNGER_EFFECT); // CraftBukkit - EntityExhaustionEvent } else if (this == MobEffects.SATURATION && entityliving instanceof EntityHuman) { if (!entityliving.world.isClientSide) { - ((EntityHuman) entityliving).getFoodData().eat(i + 1, 1.0F); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index c1f361d79f..61d406b2c1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -154,6 +154,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityEnterLoveModeEvent; +import org.bukkit.event.entity.EntityExhaustionEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityPlaceEvent; import org.bukkit.event.entity.EntityPotionEffectEvent; @@ -1566,4 +1567,11 @@ public class CraftEventFactory { return event; } + + public static EntityExhaustionEvent callPlayerExhaustionEvent(EntityHuman humanEntity, EntityExhaustionEvent.ExhaustionReason exhaustionReason, float exhaustion) { + EntityExhaustionEvent event = new EntityExhaustionEvent(humanEntity.getBukkitEntity(), exhaustionReason, exhaustion); + Bukkit.getPluginManager().callEvent(event); + + return event; + } }