[SOLVED] Setting an item's material to air doesn't work?

Discussion in 'Spigot Plugin Development' started by JordanOsterberg, Jun 18, 2015.

  1. EDIT: Solved.
    I am attempting to set an itemstack's material to air upon usage of a sell command, and it doesn't seem to do anything.
    Code:
    PHP:
    int itemprice = Core.getInstance().sv.getPrice(im);
                System.out.print(itemprice);
                // money to give:
                int value = itemamount * itemprice;
                System.out.print(value);
                p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou sold &6" + im.getType().name() + "x(" + itemamount + ") &afor &6" + value + "&a!"));
                if (itemamount == 64){
                    p.getItemInHand().setType(Material.AIR);
                } else if (itemamount == 1 || itemamount == 0){
                    p.getItemInHand().setType(Material.AIR);
                } else {
                    p.getItemInHand().setType(Material.AIR);
                }
                p.updateInventory();
                Core.economy.depositPlayer(p.getName(), value); // giving the money
    There are no errors in console.
     
    #1 JordanOsterberg, Jun 18, 2015
    Last edited: Jun 18, 2015
  2. Try
    Code (Text):
    p.setItemInHand(new ItemStack(Material.AIR));
     
  3. [​IMG]

    There's your problem, you're code is in PHP. Silly, it should be in Java.

    PS: Update your post with the solution incase someone else sees this in the future.

    As well:
    Code (Java):
               if (itemamount == 64) {
                    p.getItemInHand().setType(Material.AIR);
               } else if (itemamount == 1 || itemamount == 0) {
                    p.getItemInHand().setType(Material.AIR);
               } else {
                    p.getItemInHand().setType(Material.AIR);
               }
    Assuming you didn't simplify your example to get help, the above code will always set the item to air so there's no point in checking the itemamount.

    PS2: For the love of all that is decent, spaces.
     
    #3 CraftedFury, Jun 18, 2015
    Last edited: Jun 18, 2015
    • Funny Funny x 1
    • Creative Creative x 1