Search in sources :

Example 1 with PlayerPickupArrowEvent

use of org.bukkit.event.player.PlayerPickupArrowEvent in project Arclight by IzzelAliz.

the class AbstractArrowEntityMixin method onCollideWithPlayer.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void onCollideWithPlayer(final PlayerEntity entityhuman) {
    if (!this.world.isRemote && (this.inGround || this.getNoClip()) && this.arrowShake <= 0) {
        ItemStack itemstack = this.getArrowStack();
        if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) entityhuman.inventory).bridge$canHold(itemstack) > 0) {
            final ItemEntity item = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
            final PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) entityhuman).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (AbstractArrowEntity) (Object) this, item), (AbstractArrow) this.getBukkitEntity());
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                return;
            }
            itemstack = item.getItem();
        }
        boolean flag = this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED || (this.pickupStatus == AbstractArrowEntity.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.isCreativeMode) || (this.getNoClip() && this.getShooter().getUniqueID() == entityhuman.getUniqueID());
        if (this.pickupStatus == AbstractArrowEntity.PickupStatus.ALLOWED && !entityhuman.inventory.addItemStackToInventory(itemstack)) {
            flag = false;
        }
        if (flag) {
            entityhuman.onItemPickup((AbstractArrowEntity) (Object) this, 1);
            this.remove();
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) PlayerInventoryBridge(io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge) PlayerPickupArrowEvent(org.bukkit.event.player.PlayerPickupArrowEvent) ItemStack(net.minecraft.item.ItemStack) CraftItem(org.bukkit.craftbukkit.v.entity.CraftItem) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PlayerInventoryBridge (io.izzel.arclight.common.bridge.entity.player.PlayerInventoryBridge)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)1 ItemStack (net.minecraft.item.ItemStack)1 CraftItem (org.bukkit.craftbukkit.v.entity.CraftItem)1 PlayerPickupArrowEvent (org.bukkit.event.player.PlayerPickupArrowEvent)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1