3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

SPIGOT-3403: Add an EntityPickupItemEvent

Dieser Commit ist enthalten in:
md_5 2017-07-28 17:47:59 +10:00
Ursprung 5c4864398d
Commit d00c0574cd
2 geänderte Dateien mit 57 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,14 @@
--- a/net/minecraft/server/EntityInsentient.java --- a/net/minecraft/server/EntityInsentient.java
+++ b/net/minecraft/server/EntityInsentient.java +++ b/net/minecraft/server/EntityInsentient.java
@@ -9,6 +9,15 @@ @@ -9,6 +9,17 @@
import java.util.UUID; import java.util.UUID;
import javax.annotation.Nullable; import javax.annotation.Nullable;
+// CraftBukkit start +// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.entity.EntityPickupItemEvent;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityUnleashEvent; +import org.bukkit.event.entity.EntityUnleashEvent;
@ -16,7 +18,7 @@
public abstract class EntityInsentient extends EntityLiving { public abstract class EntityInsentient extends EntityLiving {
private static final DataWatcherObject<Byte> a = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.a); private static final DataWatcherObject<Byte> a = DataWatcher.a(EntityInsentient.class, DataWatcherRegistry.a);
@@ -27,7 +36,7 @@ @@ -27,7 +38,7 @@
public float[] dropChanceHand; public float[] dropChanceHand;
private final NonNullList<ItemStack> by; private final NonNullList<ItemStack> by;
public float[] dropChanceArmor; public float[] dropChanceArmor;
@ -25,7 +27,7 @@
public boolean persistent; public boolean persistent;
private final Map<PathType, Float> bB; private final Map<PathType, Float> bB;
private MinecraftKey bC; private MinecraftKey bC;
@@ -57,6 +66,9 @@ @@ -57,6 +68,9 @@
this.r(); this.r();
} }
@ -35,7 +37,7 @@
} }
protected void r() {} protected void r() {}
@@ -110,7 +122,38 @@ @@ -110,7 +124,38 @@
} }
public void setGoalTarget(@Nullable EntityLiving entityliving) { public void setGoalTarget(@Nullable EntityLiving entityliving) {
@ -74,7 +76,7 @@
} }
public boolean d(Class<? extends EntityLiving> oclass) { public boolean d(Class<? extends EntityLiving> oclass) {
@@ -340,11 +383,20 @@ @@ -340,11 +385,20 @@
public void a(NBTTagCompound nbttagcompound) { public void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound); super.a(nbttagcompound);
@ -97,7 +99,24 @@
NBTTagList nbttaglist; NBTTagList nbttaglist;
int i; int i;
@@ -525,7 +577,9 @@ @@ -508,7 +562,15 @@
}
}
- if (flag && this.c(itemstack)) {
+ // CraftBukkit start
+ boolean canPickup = flag && this.c(itemstack);
+
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((LivingEntity) getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity(), 0);
+ entityEvent.setCancelled(!canPickup);
+ this.world.getServer().getPluginManager().callEvent(entityEvent);
+ canPickup = !entityEvent.isCancelled();
+ if (canPickup) {
+ // CraftBukkit end
double d0;
switch (enumitemslot.a()) {
@@ -525,7 +587,9 @@
} }
if (!itemstack1.isEmpty() && (double) (this.random.nextFloat() - 0.1F) < d0) { if (!itemstack1.isEmpty() && (double) (this.random.nextFloat() - 0.1F) < d0) {
@ -107,7 +126,7 @@
} }
this.setSlot(enumitemslot, itemstack); this.setSlot(enumitemslot, itemstack);
@@ -565,11 +619,11 @@ @@ -565,11 +629,11 @@
double d2 = entityhuman.locZ - this.locZ; double d2 = entityhuman.locZ - this.locZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2; double d3 = d0 * d0 + d1 * d1 + d2 * d2;
@ -121,7 +140,7 @@
this.die(); this.die();
} else if (d3 < 1024.0D) { } else if (d3 < 1024.0D) {
this.ticksFarFromPlayer = 0; this.ticksFarFromPlayer = 0;
@@ -938,12 +992,24 @@ @@ -938,12 +1002,24 @@
public final boolean b(EntityHuman entityhuman, EnumHand enumhand) { public final boolean b(EntityHuman entityhuman, EnumHand enumhand) {
if (this.isLeashed() && this.getLeashHolder() == entityhuman) { if (this.isLeashed() && this.getLeashHolder() == entityhuman) {
@ -146,7 +165,7 @@
this.setLeashHolder(entityhuman, true); this.setLeashHolder(entityhuman, true);
itemstack.subtract(1); itemstack.subtract(1);
return true; return true;
@@ -964,10 +1030,12 @@ @@ -964,10 +1040,12 @@
if (this.bE) { if (this.bE) {
if (!this.isAlive()) { if (!this.isAlive()) {
@ -159,7 +178,7 @@
this.unleash(true, true); this.unleash(true, true);
} }
} }
@@ -978,7 +1046,9 @@ @@ -978,7 +1056,9 @@
this.bE = false; this.bE = false;
this.leashHolder = null; this.leashHolder = null;
if (!this.world.isClientSide && flag1) { if (!this.world.isClientSide && flag1) {
@ -169,7 +188,7 @@
} }
if (!this.world.isClientSide && flag && this.world instanceof WorldServer) { if (!this.world.isClientSide && flag && this.world instanceof WorldServer) {
@@ -1048,6 +1118,7 @@ @@ -1048,6 +1128,7 @@
this.setLeashHolder(entityleash, true); this.setLeashHolder(entityleash, true);
} else { } else {

Datei anzeigen

@ -1,14 +1,17 @@
--- a/net/minecraft/server/EntityItem.java --- a/net/minecraft/server/EntityItem.java
+++ b/net/minecraft/server/EntityItem.java +++ b/net/minecraft/server/EntityItem.java
@@ -4,6 +4,7 @@ @@ -4,6 +4,10 @@
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
+import org.bukkit.event.player.PlayerPickupItemEvent; // CraftBukkit +// CraftBukkit start
+import org.bukkit.event.entity.EntityPickupItemEvent;
+import org.bukkit.event.player.PlayerPickupItemEvent;
+// CraftBukkit end
public class EntityItem extends Entity { public class EntityItem extends Entity {
@@ -15,6 +16,7 @@ @@ -15,6 +19,7 @@
private String g; private String g;
private String h; private String h;
public float a; public float a;
@ -16,7 +19,7 @@
public EntityItem(World world, double d0, double d1, double d2) { public EntityItem(World world, double d0, double d1, double d2) {
super(world); super(world);
@@ -54,9 +56,12 @@ @@ -54,9 +59,12 @@
this.die(); this.die();
} else { } else {
super.B_(); super.B_();
@ -32,7 +35,7 @@
this.lastX = this.locX; this.lastX = this.locX;
this.lastY = this.locY; this.lastY = this.locY;
@@ -104,9 +109,11 @@ @@ -104,9 +112,11 @@
this.motY *= -0.5D; this.motY *= -0.5D;
} }
@ -44,7 +47,7 @@
this.aq(); this.aq();
if (!this.world.isClientSide) { if (!this.world.isClientSide) {
@@ -121,6 +128,12 @@ @@ -121,6 +131,12 @@
} }
if (!this.world.isClientSide && this.age >= 6000) { if (!this.world.isClientSide && this.age >= 6000) {
@ -57,7 +60,7 @@
this.die(); this.die();
} }
@@ -162,6 +175,7 @@ @@ -162,6 +178,7 @@
} else if (itemstack1.getCount() + itemstack.getCount() > itemstack1.getMaxStackSize()) { } else if (itemstack1.getCount() + itemstack.getCount() > itemstack1.getMaxStackSize()) {
return false; return false;
} else { } else {
@ -65,7 +68,7 @@
itemstack1.add(itemstack.getCount()); itemstack1.add(itemstack.getCount());
entityitem.pickupDelay = Math.max(entityitem.pickupDelay, this.pickupDelay); entityitem.pickupDelay = Math.max(entityitem.pickupDelay, this.pickupDelay);
entityitem.age = Math.min(entityitem.age, this.age); entityitem.age = Math.min(entityitem.age, this.age);
@@ -208,6 +222,11 @@ @@ -208,6 +225,11 @@
} else if (!this.getItemStack().isEmpty() && this.getItemStack().getItem() == Items.NETHER_STAR && damagesource.isExplosion()) { } else if (!this.getItemStack().isEmpty() && this.getItemStack().getItem() == Items.NETHER_STAR && damagesource.isExplosion()) {
return false; return false;
} else { } else {
@ -77,7 +80,7 @@
this.ax(); this.ax();
this.f = (int) ((float) this.f - f); this.f = (int) ((float) this.f - f);
if (this.f <= 0) { if (this.f <= 0) {
@@ -270,6 +289,26 @@ @@ -270,6 +292,35 @@
Item item = itemstack.getItem(); Item item = itemstack.getItem();
int i = itemstack.getCount(); int i = itemstack.getCount();
@ -87,15 +90,24 @@
+ +
+ if (this.pickupDelay <= 0 && canHold > 0) { + if (this.pickupDelay <= 0 && canHold > 0) {
+ itemstack.setCount(canHold); + itemstack.setCount(canHold);
+ PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining); + // Call legacy event
+ event.setCancelled(!entityhuman.canPickUpLoot); + PlayerPickupItemEvent playerEvent = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
+ this.world.getServer().getPluginManager().callEvent(event); + playerEvent.setCancelled(!entityhuman.canPickUpLoot);
+ itemstack.setCount(canHold + remaining); + this.world.getServer().getPluginManager().callEvent(playerEvent);
+ + if (playerEvent.isCancelled()) {
+ if (event.isCancelled()) {
+ return; + return;
+ } + }
+ +
+ // Call newer event afterwards
+ EntityPickupItemEvent entityEvent = new EntityPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity(), remaining);
+ entityEvent.setCancelled(!entityhuman.canPickUpLoot);
+ this.world.getServer().getPluginManager().callEvent(entityEvent);
+ if (entityEvent.isCancelled()) {
+ return;
+ }
+
+ itemstack.setCount(canHold + remaining);
+
+ // Possibly < 0; fix here so we do not have to modify code below + // Possibly < 0; fix here so we do not have to modify code below
+ this.pickupDelay = 0; + this.pickupDelay = 0;
+ } + }