mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 20:46:59 +01:00
de04cbced5
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: f29cb801 Separate checkstyle-suppressions file is not required 86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack 9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode() 994a6163 Attempt upgrade of resolver libraries CraftBukkit Changes: b3b43a6ad Add Checkstyle check for unused imports 13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names 3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API 2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor 1dbdbbed4 PR-1238: Remove unnecessary sign ticking 659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper e37e29ce0 Increase outdated build delay c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack 492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode() e11fbb9d7 Upgrade MySQL driver 9f3a0bd2a Attempt upgrade of resolver libraries 60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion Spigot Changes: 06d602e7 Rebuild patches
66 lines
3.7 KiB
Diff
66 lines
3.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Tue, 22 Dec 2020 13:52:48 -0800
|
|
Subject: [PATCH] Added EntityDamageItemEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
index 0dfa1ca78f747b2ea7e6b9f59d4561daad8bfcc8..368837172f87ac45e1d58e9905b4693cc0804328 100644
|
|
--- a/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
|
@@ -622,7 +622,7 @@ public final class ItemStack {
|
|
return this.getItem().getMaxDamage();
|
|
}
|
|
|
|
- public boolean hurt(int amount, RandomSource random, @Nullable ServerPlayer player) {
|
|
+ public boolean hurt(int amount, RandomSource random, @Nullable LivingEntity player) { // Paper - allow any living entity instead of only ServerPlayers
|
|
if (!this.isDamageableItem()) {
|
|
return false;
|
|
} else {
|
|
@@ -640,8 +640,8 @@ public final class ItemStack {
|
|
|
|
amount -= k;
|
|
// CraftBukkit start
|
|
- if (player != null) {
|
|
- PlayerItemDamageEvent event = new PlayerItemDamageEvent(player.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount);
|
|
+ if (player instanceof ServerPlayer serverPlayer) { // Paper
|
|
+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(serverPlayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), amount); // Paper
|
|
event.getPlayer().getServer().getPluginManager().callEvent(event);
|
|
|
|
if (amount != event.getDamage() || event.isCancelled()) {
|
|
@@ -652,6 +652,14 @@ public final class ItemStack {
|
|
}
|
|
|
|
amount = event.getDamage();
|
|
+ // Paper start - EntityDamageItemEvent
|
|
+ } else if (player != null) {
|
|
+ io.papermc.paper.event.entity.EntityDamageItemEvent event = new io.papermc.paper.event.entity.EntityDamageItemEvent(player.getBukkitLivingEntity(), CraftItemStack.asCraftMirror(this), amount);
|
|
+ if (!event.callEvent()) {
|
|
+ return false;
|
|
+ }
|
|
+ amount = event.getDamage();
|
|
+ // Paper end
|
|
}
|
|
// CraftBukkit end
|
|
if (amount <= 0) {
|
|
@@ -659,8 +667,8 @@ public final class ItemStack {
|
|
}
|
|
}
|
|
|
|
- if (player != null && amount != 0) {
|
|
- CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(player, this, this.getDamageValue() + amount);
|
|
+ if (player instanceof ServerPlayer serverPlayer && amount != 0) { // Paper
|
|
+ CriteriaTriggers.ITEM_DURABILITY_CHANGED.trigger(serverPlayer, this, this.getDamageValue() + amount); // Paper
|
|
}
|
|
|
|
j = this.getDamageValue() + amount;
|
|
@@ -672,7 +680,7 @@ public final class ItemStack {
|
|
public <T extends LivingEntity> void hurtAndBreak(int amount, T entity, Consumer<T> breakCallback) {
|
|
if (!entity.level().isClientSide && (!(entity instanceof net.minecraft.world.entity.player.Player) || !((net.minecraft.world.entity.player.Player) entity).getAbilities().instabuild)) {
|
|
if (this.isDamageableItem()) {
|
|
- if (this.hurt(amount, entity.getRandom(), entity instanceof ServerPlayer ? (ServerPlayer) entity : null)) {
|
|
+ if (this.hurt(amount, entity.getRandom(), entity /*instanceof ServerPlayer ? (ServerPlayer) entity : null*/)) { // Paper - pass LivingEntity for EntityItemDamageEvent
|
|
breakCallback.accept(entity);
|
|
Item item = this.getItem();
|
|
// CraftBukkit start - Check for item breaking
|