Search in sources :

Example 61 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project LoliServer by Loli-Server.

the class CraftEventFactory method callEntityDeathEvent.

public static EntityDeathEvent callEntityDeathEvent(LivingEntity victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.expToDrop);
    CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);
    victim.expToDrop = event.getDroppedExp();
    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0)
            continue;
        // Paper - note: dropItem already clones due to this being bukkit -> NMS
        world.dropItem(entity.getLocation(), stack);
        if (stack instanceof CraftItemStack)
            // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe, but don't nuke bukkit stacks of manually added items
            stack.setAmount(0);
    }
    victim.dropExperience();
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 62 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callPlayerItemBreakEvent.

public static void callPlayerItemBreakEvent(PlayerEntity human, ItemStack brokenItem) {
    CraftItemStack item = CraftItemStack.asCraftMirror(brokenItem);
    PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item);
    Bukkit.getPluginManager().callEvent(event);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) PlayerItemBreakEvent(org.bukkit.event.player.PlayerItemBreakEvent)

Example 63 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callPlayerHarvestBlockEvent.

/**
 * Player Harvest Block Event
 */
public static PlayerHarvestBlockEvent callPlayerHarvestBlockEvent(World world, BlockPos blockposition, PlayerEntity who, List<ItemStack> itemsToHarvest) {
    List<org.bukkit.inventory.ItemStack> bukkitItemsToHarvest = new ArrayList<>(itemsToHarvest.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList()));
    Player player = (Player) who.getBukkitEntity();
    PlayerHarvestBlockEvent playerHarvestBlockEvent = new PlayerHarvestBlockEvent(player, CraftBlock.at(world, blockposition), bukkitItemsToHarvest);
    Bukkit.getPluginManager().callEvent(playerHarvestBlockEvent);
    return playerHarvestBlockEvent;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) ArrayList(java.util.ArrayList) PlayerHarvestBlockEvent(org.bukkit.event.player.PlayerHarvestBlockEvent) ItemStack(net.minecraft.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 64 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callLootGenerateEvent.

public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
    CraftWorld world = lootInfo.getLevel().getWorldCB();
    Entity entity = lootInfo.getParamOrNull(LootParameters.THIS_ENTITY);
    NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootTables().lootTableToKey.get(lootTable));
    CraftLootTable craftLootTable = new CraftLootTable(key, lootTable);
    List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
    LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), InventoryHelper.getHolderOwner(inventory), craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) CraftLootTable(org.bukkit.craftbukkit.v1_16_R3.CraftLootTable) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) ItemStack(net.minecraft.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 65 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callBlockDamageEvent.

/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(PlayerEntity who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();
    Block blockClicked = craftWorld.getBlockAt(x, y, z);
    BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) BlockDamageEvent(org.bukkit.event.block.BlockDamageEvent) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)22 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)18 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)12 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)9 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)9 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)8 ArrayList (java.util.ArrayList)7 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)7 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7