Solved Itemstack setAmount returning null

Discussion in 'Spigot Plugin Development' started by Joshb_, Jan 13, 2020.

  1. Joshb_

    Supporter

    I literally don't see the issue here. I'm getting a null with i.setAmount

    Heres the code:

    Code (Java):
    Bukkit.broadcastMessage("+"+getConfig().getInt("Items.Boarder.Amount"));
    i.setAmount(getConfig().getInt("Items.Boarder.Amount"));
    Heres the error:
    [​IMG]

    Heres the config:
    [​IMG]

    Heres the debug message:
    [​IMG]

    I have a feeling I'm doing something wrong with setAmount with the itemstack. I have no idea. Im possibly spelling something wrong. Please look xD
     
    #1 Joshb_, Jan 13, 2020
    Last edited: Jan 13, 2020
  2. Either getConfig() or getInt() returns null.
    Is the broadcastMessage visible?
     
  3. Joshb_

    Supporter

    Yes, its the +1 message you see above the error
     
  4. Neither getConfig() nor getInt() can return null if the method is in the main-class. What is this i that you set the amount of?
     
  5. Joshb_

    Supporter

    It's not in the main class, it doesn't actually matter since its a custom config. I'm setting the amount of and itemstack (i)
     
  6. I mean... the definition of this ItemStack would be nice... how do you get it, are you simply instantiating it?
     
    • Like Like x 1
  7. Joshb_

    Supporter

    I figured it out, I have the material spelt wrong in the config for the Minecraft version I'm using.

    Heres the itemstack anyways.


    Code (Java):
    public static ItemStack boarder() {
            int amount = getConfig().getInt("Items.Boarder.Amount");
            ItemStack i = UMaterial.valueOf(getConfig().getString("Items.Boarder.Material"),
                    (byte) getConfig().getInt("Items.Boarder.Damage"));
            Bukkit.broadcastMessage("item= "+i.toString());
            Bukkit.broadcastMessage("amount= "+getConfig().getInt("Items.Boarder.Amount"));
            i.setAmount(amount);
            ItemMeta im = i.getItemMeta();
            im.setDisplayName(ChatColor.translateAlternateColorCodes('&',
                    getConfig().getString("Items.Boarder.Display-Name")));
            im.setLore(Assets.convert(getConfig().getStringList("Items.Boarder.Lore")));
            i.setItemMeta(im);
            return i;
        }
     
  8. Talking about spelling... if you aren't talking about some kind of boar (the animal), you write border without an 'a' :p
     
  9. Joshb_

    Supporter

    After the many updates iv put out with this plugin, I never noticed that/kept spelling it that way LOL thx
     
    • Friendly Friendly x 1
  10. I mean there are only 3 possibilities
    i == null
    getConfig() == null
    getInt() == null

    Check those 3
     
  11. getInt() can't return null, if nothing is set it will just return 0
     
    • Funny Funny x 1