Removing an item with a damagevalue wont work

Discussion in 'Plugin Development' started by MinecraftMart, May 4, 2014.

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

    MinecraftMart

    So i need to remove ItemStack s (the itemstack is called s)with a damage value.

    This is my code but i cant find any way to do it. Can somebody help me?

    Code:java
    1. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Iron Pickaxe Of Speed")) {
    2. final Player p = (Player) e.getWhoClicked();
    3. int Lvl = p.getLevel();
    4. if(Lvl >= 8){
    5. e.setCancelled(true);
    6. e.getWhoClicked().setItemInHand(s);
    7. p.giveExpLevels(-8);
    8. e.getWhoClicked().closeInventory();
    9. p.sendMessage("You used Magic Forging to create you perfect tool! This tool will last for 30 seconds!");
    10. new BukkitRunnable(){
    11. public void run(){
    12. p.getInventory( ).removeItem(s);
    13. }
    14. }.runTaskLater(plugin, 30 * 20);
    15. }
    16. else{
    17. e.setCancelled(true);
    18. p.sendMessage("Your level is too low! You need 8 levels!");
    19. }
     
  2. Offline

    hugokk

    You can iterate trough the items in the inventory, and check if the name and material are the same as your ItemStack s.
     
  3. Offline

    MinecraftMart

    hugokk
    Okay and how do i do that?
    Sorry i am kinda new to this. Altough i can do much myself i dont exactly know how to do this.
     
  4. Offline

    hugokk

    Code:java
    1. for(ItemStack item : p.getInventory().getContents())
    2. {
    3. if(item.getType() == s.getType())
    4. {
    5. if(item.getItemMeta().getDisplayName() != null)
    6. {
    7. if(item.getItemMeta().getDisplayName().equalsIgnoreCase(s.getItemMeta().getDisplayName()))
    8. {
    9. p.getInventory().remove(item);
    10. }
    11. }
    12. }
    13. }
     
Thread Status:
Not open for further replies.

Share This Page