Itemstack help!

Discussion in 'Plugin Development' started by DefaultSyntax, Jun 7, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    DefaultSyntax

    Hi, I'm trying this code out but it doesn't seem to work. Can someone please explain to me why it's not working and how I can fix this? Thanks

    Code:
    Code:java
    1. if(event.getBlock().getType() == Material.IRON_ORE && event.getPlayer().isOp() == false){
    2.  
    3. block.setType(Material.AIR);
    4. ItemStack iron = new ItemStack(event.getBlock().getDrops());
    5.  
    6. }


    The part that's not working is
    Code:java
    1. ItemStack iron = new ItemStack(event.getBlock().getDrops());
    because it always throws me an error.
     
  2. Offline

    HeadGam3z

    Maybe because air doesn't drop anything? Edit: Misread, I think? You're not really explaining what you're trying to do.
     
  3. DefaultSyntax
    i fixed your code
    Code:java
    1.  
    2. Block block = event.getBlock()
    3. if (block.getType().equals(Material.IRON_ORE) && !p.isOp() && !event.isCancelled()
    4. && !p.getGamemode().equals(Gamemode.CREATIVE)) {
    5.  
    6. Collection<ItemStack> items = block.getDrops();
    7.  
    8.  
    9. for (ItemStack item : items) {
    10. p.getInventory().addItem(new ItemStack(Material.IRON_INGOT));
    11. }
    12. e.setCancelled(true);
    13. block.setType(Material.AIR);
    14. }
     
  4. Offline

    DefaultSyntax

    Thank you so much FisheyLP.
    Just one question, can you please explain to me what a Collection is?
     
  5. it's almost the same as a list
     
  6. Offline

    DefaultSyntax

Thread Status:
Not open for further replies.

Share This Page