mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-18 15:20:37 +01:00
#1272: Only allow one entity in CraftItem instead of two
This pr reverts a change made in 2012 which allowed CraftItem to be a also other entities such as an arrow. I don't see any practical reason why the original change was done, other than to allow plugin developers to do some stuff in a cursed way. With the introduction of the PlayerPickupArrowEvent in 2016 there is also a way to access the arrow involved in a better way. Generally I think the current behavior is a bit strange and should be reverted. By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
39de862c02
commit
c4c6bf8a92
2 changed files with 19 additions and 21 deletions
|
@ -46,7 +46,7 @@
|
|||
+ ItemStack itemstack = this.getPickupItem();
|
||||
+ if (this.pickup == PickupStatus.ALLOWED && !itemstack.isEmpty() && entityhuman.getInventory().canHold(itemstack) > 0) {
|
||||
+ EntityItem item = new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), itemstack);
|
||||
+ PlayerPickupArrowEvent event = new PlayerPickupArrowEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.level().getCraftServer(), this, item), (org.bukkit.entity.AbstractArrow) this.getBukkitEntity());
|
||||
+ PlayerPickupArrowEvent event = new PlayerPickupArrowEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.level().getCraftServer(), item), (org.bukkit.entity.AbstractArrow) this.getBukkitEntity());
|
||||
+ // event.setCancelled(!entityhuman.canPickUpLoot); TODO
|
||||
+ this.level().getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.EntityItem;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
|
@ -9,50 +8,49 @@ import org.bukkit.entity.Item;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CraftItem extends CraftEntity implements Item {
|
||||
private final EntityItem item;
|
||||
|
||||
public CraftItem(CraftServer server, Entity entity, EntityItem item) {
|
||||
super(server, entity);
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public CraftItem(CraftServer server, EntityItem entity) {
|
||||
this(server, entity, entity);
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityItem getHandle() {
|
||||
return (EntityItem) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return CraftItemStack.asCraftMirror(item.getItem());
|
||||
return CraftItemStack.asCraftMirror(getHandle().getItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemStack(ItemStack stack) {
|
||||
item.setItem(CraftItemStack.asNMSCopy(stack));
|
||||
getHandle().setItem(CraftItemStack.asNMSCopy(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPickupDelay() {
|
||||
return item.pickupDelay;
|
||||
return getHandle().pickupDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupDelay(int delay) {
|
||||
item.pickupDelay = Math.min(delay, Short.MAX_VALUE);
|
||||
getHandle().pickupDelay = Math.min(delay, Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnlimitedLifetime(boolean unlimited) {
|
||||
if (unlimited) {
|
||||
// See EntityItem#INFINITE_LIFETIME
|
||||
item.age = Short.MIN_VALUE;
|
||||
getHandle().age = Short.MIN_VALUE;
|
||||
} else {
|
||||
item.age = getTicksLived();
|
||||
getHandle().age = getTicksLived();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnlimitedLifetime() {
|
||||
return item.age == Short.MIN_VALUE;
|
||||
return getHandle().age == Short.MIN_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,28 +59,28 @@ public class CraftItem extends CraftEntity implements Item {
|
|||
|
||||
// Second field for EntityItem (don't set if lifetime is unlimited)
|
||||
if (!isUnlimitedLifetime()) {
|
||||
item.age = value;
|
||||
getHandle().age = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOwner(UUID uuid) {
|
||||
item.setTarget(uuid);
|
||||
getHandle().setTarget(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getOwner() {
|
||||
return item.target;
|
||||
return getHandle().target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThrower(UUID uuid) {
|
||||
item.setThrower(uuid);
|
||||
getHandle().setThrower(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getThrower() {
|
||||
return item.thrower;
|
||||
return getHandle().thrower;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue