pick block event expansion

This commit is contained in:
Blast-MC
2025-03-06 12:27:39 -05:00
parent e2ef14b2d1
commit 68e097f2b2
2 changed files with 80 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
--- a/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
+++ b/src/main/java/io/papermc/paper/event/player/PlayerPickItemEvent.java
@@ -1,6 +_,8 @@
package io.papermc.paper.event.player;
import com.google.common.base.Preconditions;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -22,13 +_,18 @@
private int targetSlot;
private int sourceSlot;
+ private Location location;
+ private Entity entity;
+
private boolean cancelled;
@ApiStatus.Internal
- public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot) {
+ public PlayerPickItemEvent(final Player player, final int targetSlot, final int sourceSlot, final Location location, final Entity entity) {
super(player);
this.targetSlot = targetSlot;
this.sourceSlot = sourceSlot;
+ this.location = location;
+ this.entity = entity;
}
/**
@@ -72,6 +_,14 @@
public void setSourceSlot(final @Range(from = -1, to = 35) int sourceSlot) {
Preconditions.checkArgument(sourceSlot >= -1 && sourceSlot <= 35, "Source slot must be in range of the player's inventory slot, or -1");
this.sourceSlot = sourceSlot;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public Entity getEntity() {
+ return entity;
}
@Override

View File

@@ -16,6 +16,40 @@
}
// CraftBukkit end
// Paper start - Don't suggest if tab-complete is disabled
@@ -977,7 +_,8 @@
addBlockDataToItem(blockState, serverLevel, blockPos, cloneItemStack);
}
- this.tryPickItem(cloneItemStack);
+ Location location = new Location(this.player.getBukkitEntity().getWorld(), blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ this.tryPickItem(cloneItemStack, location, null);
}
}
}
@@ -1001,12 +_,12 @@
if (entity != null && this.player.canInteractWithEntity(entity, 3.0)) {
ItemStack pickResult = entity.getPickResult();
if (pickResult != null && !pickResult.isEmpty()) {
- this.tryPickItem(pickResult);
+ this.tryPickItem(pickResult, null, entity.getBukkitEntity());
}
}
}
- private void tryPickItem(ItemStack stack) {
+ private void tryPickItem(ItemStack stack, Location location, org.bukkit.entity.Entity entity) {
if (stack.isItemEnabled(this.player.level().enabledFeatures())) {
Inventory inventory = this.player.getInventory();
int i = inventory.findSlotMatchingItem(stack);
@@ -1014,7 +_,7 @@
final int sourceSlot = i;
final int targetSlot = Inventory.isHotbarSlot(sourceSlot) ? sourceSlot : inventory.getSuitableHotbarSlot();
final org.bukkit.entity.Player bukkitPlayer = this.player.getBukkitEntity();
- final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot);
+ final io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot, location, entity);
if (!event.callEvent()) {
return;
}
@@ -2497,6 +_,7 @@
// Spigot start - spam exclusions