From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cryptite Date: Tue, 21 Sep 2021 08:33:45 -0500 Subject: [PATCH] Add PlayerShieldDisableEvent diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java index bada11542390b7575466f0e7062470665b8266c4..3879bf37a508675fb4c918516b3f27d5d978c4d1 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java @@ -1583,6 +1583,7 @@ public abstract class Mob extends LivingEntity { float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F; if (this.random.nextFloat() < f) { + if (!new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) player.getBukkitEntity(), getBukkitEntity()).callEvent()) return; // Slice player.getCooldowns().addCooldown(Items.SHIELD, 100); this.level.broadcastEntityEvent(player, (byte) 30); } 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 d8780f06efc261a42389e466573a0bcf10c333f6..a5b7b798143b33c811928b9562f8cd11b484df60 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java +++ b/src/main/java/net/minecraft/world/entity/player/Player.java @@ -931,7 +931,7 @@ public abstract class Player extends LivingEntity { protected void blockUsingShield(LivingEntity attacker) { super.blockUsingShield(attacker); if (attacker.getMainHandItem().getItem() instanceof AxeItem) { - this.disableShield(true); + this.disableShield(true, attacker); // Slice } } @@ -1398,6 +1398,12 @@ public abstract class Player extends LivingEntity { } public void disableShield(boolean sprinting) { + // Slice start + disableShield(sprinting, null); + } + + public void disableShield(boolean sprinting, @Nullable LivingEntity attacker) { + // Slice end float f = 0.25F + (float) EnchantmentHelper.getBlockEfficiency(this) * 0.05F; if (sprinting) { @@ -1405,6 +1411,8 @@ public abstract class Player extends LivingEntity { } if (this.random.nextFloat() < f) { + org.bukkit.entity.Entity finalAttacker = attacker != null ? attacker.getBukkitEntity() : null; // Slice + if (!new io.papermc.paper.event.player.PlayerShieldDisableEvent((org.bukkit.entity.Player) getBukkitEntity(), finalAttacker).callEvent()) return; // Slice this.getCooldowns().addCooldown(Items.SHIELD, 100); this.stopUsingItem(); this.level.broadcastEntityEvent(this, (byte) 30);