SPIGOT-4938: Call EntityPickupItemEvent for dolphins

This commit is contained in:
Brokkonaut 2019-05-17 23:19:52 +02:00 committed by md_5
parent a278e4453a
commit 09d00e9f90
3 changed files with 31 additions and 14 deletions

View File

@ -9,7 +9,19 @@
} }
@Override @Override
@@ -422,7 +422,7 @@ @@ -178,6 +178,11 @@
ItemStack itemstack = entityitem.getItemStack();
if (this.g(itemstack)) {
+ // CraftBukkit start - call EntityPickupItemEvent
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, false).isCancelled()) {
+ return;
+ }
+ // CraftBukkit end
this.setSlot(EnumItemSlot.MAINHAND, itemstack);
this.dropChanceHand[EnumItemSlot.MAINHAND.b()] = 2.0F;
this.receive(entityitem, itemstack.getCount());
@@ -422,7 +427,7 @@
@Override @Override
public void c() { public void c() {
@ -18,7 +30,7 @@
} }
@Override @Override
@@ -441,7 +441,7 @@ @@ -441,7 +446,7 @@
} }
if (this.c.isSwimming() && this.c.world.random.nextInt(6) == 0) { if (this.c.isSwimming() && this.c.world.random.nextInt(6) == 0) {

View File

@ -112,18 +112,14 @@
@Override @Override
protected LootTableInfo.Builder a(boolean flag, DamageSource damagesource) { protected LootTableInfo.Builder a(boolean flag, DamageSource damagesource) {
@@ -462,11 +522,21 @@ @@ -462,11 +522,17 @@
ItemStack itemstack1 = this.getEquipment(enumitemslot); ItemStack itemstack1 = this.getEquipment(enumitemslot);
boolean flag = this.a(itemstack, itemstack1, enumitemslot); boolean flag = this.a(itemstack, itemstack1, enumitemslot);
- if (flag && this.g(itemstack)) { - if (flag && this.g(itemstack)) {
+ // CraftBukkit start + // CraftBukkit start
+ boolean canPickup = flag && this.g(itemstack); + boolean canPickup = flag && this.g(itemstack);
+ + canPickup = !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !canPickup).isCancelled();
+ 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) { + if (canPickup) {
+ // CraftBukkit end + // CraftBukkit end
double d0 = (double) this.d(enumitemslot); double d0 = (double) this.d(enumitemslot);
@ -135,7 +131,7 @@
} }
this.setSlot(enumitemslot, itemstack); this.setSlot(enumitemslot, itemstack);
@@ -544,11 +614,11 @@ @@ -544,11 +610,11 @@
if (entityhuman != null) { if (entityhuman != null) {
double d0 = entityhuman.h(this); double d0 = entityhuman.h(this);
@ -149,7 +145,7 @@
this.die(); this.die();
} else if (d0 < 1024.0D) { } else if (d0 < 1024.0D) {
this.ticksFarFromPlayer = 0; this.ticksFarFromPlayer = 0;
@@ -944,12 +1014,24 @@ @@ -944,12 +1010,24 @@
if (!this.isAlive()) { if (!this.isAlive()) {
return false; return false;
} else if (this.getLeashHolder() == entityhuman) { } else if (this.getLeashHolder() == entityhuman) {
@ -174,7 +170,7 @@
this.setLeashHolder(entityhuman, true); this.setLeashHolder(entityhuman, true);
itemstack.subtract(1); itemstack.subtract(1);
return true; return true;
@@ -995,6 +1077,7 @@ @@ -995,6 +1073,7 @@
if (this.leashHolder != null) { if (this.leashHolder != null) {
if (!this.isAlive() || !this.leashHolder.isAlive()) { if (!this.isAlive() || !this.leashHolder.isAlive()) {
@ -182,7 +178,7 @@
this.unleash(true, true); this.unleash(true, true);
} }
@@ -1010,7 +1093,9 @@ @@ -1010,7 +1089,9 @@
this.leashHolder = null; this.leashHolder = null;
if (!this.world.isClientSide && flag1) { if (!this.world.isClientSide && flag1) {
@ -192,7 +188,7 @@
} }
if (!this.world.isClientSide && flag && this.world instanceof WorldServer) { if (!this.world.isClientSide && flag && this.world instanceof WorldServer) {
@@ -1079,6 +1164,7 @@ @@ -1079,6 +1160,7 @@
this.setLeashHolder(EntityLeash.a(this.world, blockposition), true); this.setLeashHolder(EntityLeash.a(this.world, blockposition), true);
} else { } else {
@ -200,7 +196,7 @@
this.unleash(false, true); this.unleash(false, true);
} }
@@ -1186,7 +1272,14 @@ @@ -1186,7 +1268,14 @@
int i = EnchantmentManager.getFireAspectEnchantmentLevel(this); int i = EnchantmentManager.getFireAspectEnchantmentLevel(this);
if (i > 0) { if (i > 0) {

View File

@ -92,6 +92,7 @@ import org.bukkit.entity.Creeper;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pig; import org.bukkit.entity.Pig;
@ -137,6 +138,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier; import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityPlaceEvent; import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityShootBowEvent;
@ -1419,4 +1421,11 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
return !event.isCancelled(); return !event.isCancelled();
} }
public static EntityPickupItemEvent callEntityPickupItemEvent(Entity who, EntityItem item, int remaining, boolean cancelled) {
EntityPickupItemEvent event = new EntityPickupItemEvent((LivingEntity) who.getBukkitEntity(), (Item) item.getBukkitEntity(), remaining);
event.setCancelled(cancelled);
Bukkit.getPluginManager().callEvent(event);
return event;
}
} }