Search in sources :

Example 91 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project EverNifeCore by EverNife.

the class NMSUtils_v1_7_R4 method setHandle.

private void setHandle(org.bukkit.inventory.ItemStack mcStack, ItemStack handle) {
    Validate.notNull(mcStack, "mcStack can not be null!");
    Validate.notNull(handle, "handle can not be null!");
    try {
        CraftItemStack craftItemStack = (CraftItemStack) mcStack;
        handle_field.set(craftItemStack, handle);
    } catch (Exception e) {
        Class c = mcStack.getClass();
        EverNifeCore.warning("ItemStack Class:\n\n Package: " + c.getPackage() + "\nClass: " + c.getSimpleName() + "\nFull Identifier: " + c.getName());
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Example 92 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project EverNifeCore by EverNife.

the class NMSUtils_v1_7_R4 method getHandle.

private ItemStack getHandle(org.bukkit.inventory.ItemStack itemStack) {
    Validate.notNull(itemStack, "itemStack can not be null!");
    try {
        CraftItemStack craftItemStack = (CraftItemStack) itemStack;
        ItemStack mcStack = handle_field.get(craftItemStack);
        return mcStack;
    } catch (Exception e) {
        Class c = itemStack.getClass();
        EverNifeCore.warning("Failed to get ItemStack Handle for:" + "\n" + "\nPackage: " + c.getPackage() + "" + "\nClass: " + c.getSimpleName() + "" + "\nFull Identifier: " + c.getName());
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Example 93 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project Magma by magmafoundation.

the class CraftEventFactory method callEntityShootBowEvent.

/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(EntityLivingBase who, ItemStack itemstack, EntityArrow entityArrow, float force) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Arrow arrow = (Arrow) entityArrow.getBukkitEntity();
    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }
    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) EntityArrow(net.minecraft.entity.projectile.EntityArrow) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)

Example 94 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project Magma by magmafoundation.

the class CraftEventFactory method callBlockDamageEvent.

/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(EntityPlayer 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_12_R1.inventory.CraftItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 95 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project Magma by magmafoundation.

the class FactoryItemMaterialTest method itemStack.

@Test
public void itemStack() {
    ItemStack bukkitStack = new ItemStack(material);
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(bukkitStack);
    ItemMeta meta = factory.getItemMeta(material);
    if (meta == null) {
        assertThat(material, is(Material.AIR));
    } else {
        assertTrue(factory.isApplicable(meta, bukkitStack));
        assertTrue(factory.isApplicable(meta, craftStack));
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Test(org.junit.Test)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)34 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)25 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)20 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)17 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)11 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)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 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)7 CraftItemStack (org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack)6