Solved WHY my Item buy feature don't work.

Discussion in 'Plugin Development' started by ImAFlo, May 13, 2015.

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

    ImAFlo

    I get no errors if I use the function. I only get the sound for "You havent enough Items of this typ", but I have enough of this items in my inventory :(

    Code: http://pastebin.com/FPnK5qj2
    (A little bit is on german, but the code is java[english] )
    If you understand anything not, please write me, I will translate it.
     
  2. Offline

    Zombie_Striker

    Don't have huge gaps in code. No more then three lines
    Ondisabled does nothing, so remove it
    use != null instaed of !(== null)

    Did you debug? What is the cause? Is there unreached code? What line is at fault?

    These questions and this problem would have been fixed if you debugged.
     
  3. Offline

    ImAFlo

    Debug?

    Neither Eclipse nor the Console Report Errors. I know that the code up to the last if statement in Buy void works.
    Code:
    if (p.getInventory().contains(new ItemStack(mat, price))) {
                            p.getPlayer().getWorld().playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
                            p.getInventory().removeItem(new ItemStack(mat, price));
                            p.getInventory().addItem(new ItemStack(get, getwv));
                   } else {
                            p.getPlayer().getWorld().playSound(p.getLocation(), Sound.FIZZ, 1, 1);
                   }
    
    This IF statement is always recognized as wrong, although it should be right actually, when I the respective Item (brick, iron_ingot, gold_ingot) in inventory have.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  4. Offline

    T0X1C0801

    Code:
    if (p.getInventory().contains(new ItemStack(mat, price))) {
                            p.getPlayer().getWorld().playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
                            p.getInventory().removeItem(new ItemStack(mat, price));
                            p.getInventory().addItem(new ItemStack(get, getwv));
                   } else {
                            p.getPlayer().getWorld().playSound(p.getLocation(), Sound.FIZZ, 1, 1);
                   }
    ok so i have learned this from one of my friends and he did
    Code:
    } else {
         p.sendMessage("TEST");
    and then he fixed it by checking if its not null but idk if it will fix it...
    but if it says TEST then u made a mistake in the code but idk where xD
     
  5. Offline

    ImAFlo

    Yeah, the say TEST. :(
    I post this here bcs i can't find the mistake :(
     
  6. Offline

    Zombie_Striker

    Okay, So, do this:
    • Check if P is null
    • Check if new ItemStack is null
    • Check if the Inventory Contains the new ItemStack
    • Look at ALL Items in the inventory, and print out the Material/Display name/ Durability ect. to understand what is actually in the inventory.

    [EDIT]Also, Try looking to see if the inventory has the MATERIAL, instead of a new itemstack. How can an inventory have that New ItemStack if you never added that exact itemstack
     
  7. Offline

    ImAFlo

    I found the bug...
    if (p.getInventory().contains(mat, price)) <-- Right
    if (p.getInventory().contains(new ItemStack(mat, price))) <-- False
     
Thread Status:
Not open for further replies.

Share This Page