Search code examples
javalistenerminecraftbukkit

Check if PickupItemEvent ItemStack is cobblestone?


@EventHandler
public void pickup(InventoryPickupItemEvent e) {
    if (e.getItem().getItemStack().isSimilar(new ItemStack(Material.COBBLESTONE))) {
        Bukkit.broadcastMessage("doesn't work yet");
    }
}

This doesn't seem to work. I've also tried .equals similarly.

Thanks for the help!


Solution

  • You can check a material against another, as it's a fixed enum value.

    Material m = myItemstack.getType();
    if (m.equals(Material.COBBLESTONE)) //IS COBBLE
    

    And also, if the data is also important

    MaterialData data = myItemstack.getData();
    if (data.equals(/*ANOTHER MATERIAL DATA*/)) //Also the same data