RemoveItem(ItemStack) not working

Discussion in 'Plugin Development' started by facemywrath, Dec 24, 2015.

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

    facemywrath

    So, first of all, merry christmas and happy holidays.
    Second of all...
    I've been working on an mmorpg profession plugin lately. I made a method to make inventory clicks work so that you input all the information and it runs it accordingly. The problem I'm having is that when a play goes to use my inventory GUIs to smelt/craft items, it doesn't remove the item that is needed to craft. For example, it takes iron ore to make iron ingots and when you do that it doesn't take the iron ore. I had it working but it wasn't working (with blacksmithing) with my custom-made iron ingots (special lore) so I added a different way of RemoveItem so that it searches for the first of that material and removes some of that itemstack.
    It does add the item and say what it needs to and all that stuff, so it gets there and everything, but it isn't removing the item...

    Let me know what is wrong here please.

    The method:

    Code:
        public static void checkClicked(String newItemName, String craftItemName, String professionName, Player p, HashMap<Player, Integer> profession, int skillLevel, Material craftMaterial, Material newMaterial, int itemCostMat, int itemCostGold, int maxProfLevel, int returnAmount, List<String> lore){
            if(profession.get(p) >= skillLevel){
                if(Main.gold.get(p) >= itemCostGold){
                    if(p.getInventory().contains(craftMaterial)){
                        int itemamount = 0;
                        for(ItemStack stack : p.getInventory().getContents()){
                            if(stack != null){
                                if(stack.getType() == craftMaterial){
                                    itemamount = (itemamount + stack.getAmount());
                                }
                            }
                        }
                        if(itemamount >= itemCostMat){
                            p.getInventory().removeItem(new ItemStack(p.getInventory().getItem(p.getInventory().first(craftMaterial)).getType(), itemCostMat));
                            Main.gold.put(p, Main.gold.get(p)-itemCostGold);
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &3Crafted a(n) &6" + newItemName + "."));
                            p.getInventory().addItem(Main.invItem(newItemName, newMaterial, 1, lore));
                            p.updateInventory();
                            if(profession.get(p) < maxProfLevel){
                                    profession.put(p, profession.get(p) + 1);
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&',"&3New " + professionName + " level: &5" + profession.get(p)));
                                if(profession.get(p) == 50){
                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &2&lYou've unlocked Novice " + professionName + "!"));  
                                }else{
                                    if(profession.get(p) == 100){
                                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &2&lYou've unlocked Advanced " + professionName + "!"));         
                                    }else{
                                        if(profession.get(p) == 150){
                                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &2&lYou've unlocked Expert " + professionName + "!"));     
                                        }else{
                                            if(profession.get(p) == 200){
                                                p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &2&lYou've unlocked Professional " + professionName + "!"));             
                                            }else{
                                                if(profession.get(p) == Main.maxProfLevel){
                                                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&b[FS] &2&lYou've unlocked Artisan " + professionName + "!"));     
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }else{
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4[FS] &cYou need more &6" + craftItemName + " &cto do that."));
                        }
                    }else{
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4[FS] &cYou need more &6" + craftItemName + " &cto do that."));
                    }
                }
            }else{
                p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4[FS] &cMust have a &6" + professionName + " level of &6" + skillLevel + " &cto do that"));
            }
        }
    
    }
    Then the part where it uses said method:

    Code:
                        Main.checkClicked("Stone", "cobblestone", "Mining", p, Main.mining, 10, Material.COBBLESTONE, Material.STONE, 4, 30, 250, 1, Main.formatLore("&6Crafting Item :: Sell: 5 gold"));
    
     
  2. Offline

    Javlin

    Add some code to print out the material of:
    Make sure this is the correct material, and print out itemCostMat as well, to make sure this is the correct amount.
     
  3. Offline

    Zombie_Striker

    Why not just revome that instance, instead of creating a new instance.

    Did you debug? Does it read everything?
     
  4. Offline

    facemywrath

    Is there a way to remove a certain amount of said item? I believe the problem is because of its lore.
     
  5. Offline

    Zombie_Striker

    @facemywrath
    Yes.
    Code:
    If amount >= amountNeeded{
    Item.setamount(amount - amountNeeded){
    else{
    amountneeded -= the amount
    Inv.remov(amount)
    
     
  6. Offline

    facemywrath

    I figured it out, thanks guys.
     
  7. Offline

    Zombie_Striker

    Mark this thread as solved if solved.
     
Thread Status:
Not open for further replies.

Share This Page