From d7039347b06ecc8c65e3dbe0ca532d83960c75ef Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Fri, 10 Nov 2017 22:49:53 -0500 Subject: [PATCH] PlayerAttemptPickupItemEvent additions --- .../0055-PlayerAttemptPickupItemEvent.patch | 59 +++++++++++++++++-- .../0214-PlayerAttemptPickupItemEvent.patch | 28 ++++++--- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/Spigot-API-Patches/0055-PlayerAttemptPickupItemEvent.patch b/Spigot-API-Patches/0055-PlayerAttemptPickupItemEvent.patch index 1a8a209fd..ef0b6b18c 100644 --- a/Spigot-API-Patches/0055-PlayerAttemptPickupItemEvent.patch +++ b/Spigot-API-Patches/0055-PlayerAttemptPickupItemEvent.patch @@ -1,4 +1,4 @@ -From 22f105de2d79c874e1c620563073bbda1a78c97a Mon Sep 17 00:00:00 2001 +From a9bf0ad7d65a13fea2f4340fd6cea3c8c307c393 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sun, 11 Jun 2017 16:30:37 -0500 Subject: [PATCH] PlayerAttemptPickupItemEvent @@ -6,26 +6,36 @@ Subject: [PATCH] PlayerAttemptPickupItemEvent diff --git a/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java b/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java new file mode 100644 -index 00000000..2f5fdb13 +index 00000000..480293e9 --- /dev/null +++ b/src/main/java/org/bukkit/event/player/PlayerAttemptPickupItemEvent.java -@@ -0,0 +1,36 @@ +@@ -0,0 +1,85 @@ +package org.bukkit.event.player; + +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; ++import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +/** + * Thrown when a player attempts to pick an item up from the ground + */ -+public class PlayerAttemptPickupItemEvent extends PlayerEvent { ++public class PlayerAttemptPickupItemEvent extends PlayerEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private final Item item; ++ private final int remaining; ++ private boolean flyAtPlayer = true; ++ private boolean isCancelled = false; + ++ @Deprecated // Remove in 1.13 + public PlayerAttemptPickupItemEvent(final Player player, final Item item) { ++ this(player, item, 0); ++ } ++ ++ public PlayerAttemptPickupItemEvent(final Player player, final Item item, final int remaining) { + super(player); + this.item = item; ++ this.remaining = remaining; + } + + /** @@ -37,6 +47,45 @@ index 00000000..2f5fdb13 + return item; + } + ++ /** ++ * Gets the amount that will remain on the ground, if any ++ * ++ * @return amount that will remain on the ground ++ */ ++ public int getRemaining() { ++ return remaining; ++ } ++ ++ /** ++ * Set if the item will fly at the player ++ *

Cancelling the event will set this value to false.

++ * ++ * @param flyAtPlayer True for item to fly at player ++ */ ++ public void setFlyAtPlayer(boolean flyAtPlayer) { ++ this.flyAtPlayer = flyAtPlayer; ++ } ++ ++ /** ++ * Gets if the item will fly at the player ++ * ++ * @return True if the item will fly at the player ++ */ ++ public boolean getFlyAtPlayer() { ++ return this.flyAtPlayer; ++ } ++ ++ ++ @Override ++ public boolean isCancelled() { ++ return this.isCancelled; ++ } ++ ++ @Override ++ public void setCancelled(boolean cancel) { ++ this.isCancelled = cancel; ++ } ++ + @Override + public HandlerList getHandlers() { + return handlers; @@ -47,5 +96,5 @@ index 00000000..2f5fdb13 + } +} -- -2.13.1 +2.14.2 diff --git a/Spigot-Server-Patches/0214-PlayerAttemptPickupItemEvent.patch b/Spigot-Server-Patches/0214-PlayerAttemptPickupItemEvent.patch index dbdf21a37..58ee0ebc2 100644 --- a/Spigot-Server-Patches/0214-PlayerAttemptPickupItemEvent.patch +++ b/Spigot-Server-Patches/0214-PlayerAttemptPickupItemEvent.patch @@ -1,11 +1,11 @@ -From 5259d5af8c2d7a9357333588950b955ed4312eca Mon Sep 17 00:00:00 2001 +From 4a764d1d7cef5474fa407bb5c069e18b13d9f085 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sun, 11 Jun 2017 16:30:30 -0500 Subject: [PATCH] PlayerAttemptPickupItemEvent diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java -index ae4910b4b..b56d1a35e 100644 +index ae4910b4..0b7fc327 100644 --- a/src/main/java/net/minecraft/server/EntityItem.java +++ b/src/main/java/net/minecraft/server/EntityItem.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger; @@ -16,19 +16,29 @@ index ae4910b4b..b56d1a35e 100644 import com.destroystokyo.paper.HopperPusher; // Paper // Paper start - implement HopperPusher -@@ -329,6 +330,12 @@ public class EntityItem extends Entity implements HopperPusher { - Item item = itemstack.getItem(); - int i = itemstack.getCount(); +@@ -334,6 +335,22 @@ public class EntityItem extends Entity implements HopperPusher { + int remaining = i - canHold; + boolean flyAtPlayer = false; // Paper + // Paper start + if (this.pickupDelay <= 0) { -+ this.world.getServer().getPluginManager().callEvent(new PlayerAttemptPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity())); ++ PlayerAttemptPickupItemEvent attemptEvent = new PlayerAttemptPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); ++ this.world.getServer().getPluginManager().callEvent(attemptEvent); ++ ++ flyAtPlayer = attemptEvent.getFlyAtPlayer(); ++ if (attemptEvent.isCancelled()) { ++ if (flyAtPlayer) { ++ entityhuman.receive(this, i); ++ } ++ ++ return; ++ } + } + // Paper end + - // CraftBukkit start - fire PlayerPickupItemEvent - int canHold = entityhuman.inventory.canHold(itemstack); - int remaining = i - canHold; + if (this.pickupDelay <= 0 && canHold > 0) { + itemstack.setCount(canHold); + // Call legacy event -- 2.14.2