diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch index d7cbd98e94..cd96164aaf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityExperienceOrb.java +++ b/net/minecraft/world/entity/EntityExperienceOrb.java -@@ -21,6 +21,12 @@ +@@ -21,6 +21,13 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -8,12 +8,13 @@ +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent; ++import org.bukkit.event.player.PlayerExpCooldownChangeEvent; +// CraftBukkit end + public class EntityExperienceOrb extends Entity { private static final int LIFETIME = 6000; -@@ -59,6 +65,7 @@ +@@ -59,6 +66,7 @@ @Override public void tick() { super.tick(); @@ -21,7 +22,7 @@ this.xo = this.getX(); this.yo = this.getY(); this.zo = this.getZ(); -@@ -84,7 +91,22 @@ +@@ -84,7 +92,22 @@ this.followingPlayer = null; } @@ -45,7 +46,13 @@ Vec3D vec3d = new Vec3D(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ()); double d0 = vec3d.lengthSqr(); -@@ -227,7 +249,7 @@ +@@ -222,12 +245,12 @@ + public void playerTouch(EntityHuman entityhuman) { + if (!this.level.isClientSide) { + if (entityhuman.takeXpDelay == 0) { +- entityhuman.takeXpDelay = 2; ++ entityhuman.takeXpDelay = CraftEventFactory.callPlayerXpCooldownEvent(entityhuman, 2, PlayerExpCooldownChangeEvent.ChangeReason.PICKUP_ORB).getNewCooldown(); // CraftBukkit - entityhuman.takeXpDelay = 2; + entityhuman.take(this, 1); int i = this.repairPlayerItems(entityhuman, this.value); if (i > 0) { @@ -54,7 +61,7 @@ } --this.count; -@@ -245,9 +267,17 @@ +@@ -245,9 +268,17 @@ if (entry != null) { ItemStack itemstack = (ItemStack) entry.getValue(); int j = Math.min(this.xpToDurability(this.value), itemstack.getDamageValue()); @@ -72,7 +79,7 @@ return k > 0 ? this.repairPlayerItems(entityhuman, k) : 0; } else { -@@ -272,6 +302,24 @@ +@@ -272,6 +303,24 @@ } public static int getExperienceValue(int i) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index abff9b89b2..b28932ad17 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -131,6 +131,7 @@ import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.craftbukkit.block.CraftSign; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.conversations.ConversationTracker; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.craftbukkit.map.RenderData; @@ -143,6 +144,7 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; import org.bukkit.event.player.PlayerHideEntityEvent; import org.bukkit.event.player.PlayerRegisterChannelEvent; import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason; @@ -1186,6 +1188,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return getHandle().getPlayerWeather(); } + @Override + public int getExpCooldown() { + return getHandle().takeXpDelay; + } + + @Override + public void setExpCooldown(int ticks) { + getHandle().takeXpDelay = CraftEventFactory.callPlayerXpCooldownEvent(this.getHandle(), ticks, PlayerExpCooldownChangeEvent.ChangeReason.PLUGIN).getNewCooldown(); + } + @Override public void resetPlayerWeather() { getHandle().resetPlayerWeather(); 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 bba9521f44..93bd7c6ac8 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 @@ -212,6 +212,7 @@ import org.bukkit.event.player.PlayerBucketFishEvent; import org.bukkit.event.player.PlayerEditBookEvent; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerExpChangeEvent; +import org.bukkit.event.player.PlayerExpCooldownChangeEvent; import org.bukkit.event.player.PlayerHarvestBlockEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemBreakEvent; @@ -1125,6 +1126,13 @@ public class CraftEventFactory { return event; } + public static PlayerExpCooldownChangeEvent callPlayerXpCooldownEvent(EntityHuman entity, int newCooldown, PlayerExpCooldownChangeEvent.ChangeReason changeReason) { + Player player = (Player) entity.getBukkitEntity(); + PlayerExpCooldownChangeEvent event = new PlayerExpCooldownChangeEvent(player, newCooldown, changeReason); + Bukkit.getPluginManager().callEvent(event); + return event; + } + public static PlayerItemMendEvent callPlayerItemMendEvent(EntityHuman entity, EntityExperienceOrb orb, net.minecraft.world.item.ItemStack nmsMendedItem, EnumItemSlot slot, int repairAmount) { Player player = (Player) entity.getBukkitEntity(); org.bukkit.inventory.ItemStack bukkitStack = CraftItemStack.asCraftMirror(nmsMendedItem);