Integer returning 0

Discussion in 'Plugin Development' started by CONTREKEE, Jul 2, 2015.

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

    CONTREKEE

    So the int that I created keeps returning the integer 0. I am not getting any errors in console so I do not know what the problem is.

    Code:
    Code:
    public int test;
            getConfig().addDefault("GoldOre.Price", 5000);
            getConfig().options().copyDefaults(true);
            saveConfig();
           
            test = (int) (getConfig().getInt("GoldOre.Price"));
    The integer should be returning the integer 5000, but it seems to only be giving me the value 0.
    Can anyone help?
    Thank!
     
  2. Offline

    teej107

    @CONTREKEE How do you know it's returning 0? Where's your debug code? It's also not good to have a public field out in the open for anything to change the value.
     
  3. Offline

    CONTREKEE

    @teej107 It is setting the item lore to 0. Also I think I have to have a public integer to be able to use the int for this.


    Code:
            ItemStack GoldOre = new ItemStack(Material.GOLD_ORE, 1);{
                ItemMeta GoldOremeta = GoldOre.getItemMeta();
                ArrayList<String> cc = new ArrayList<String>();
                GoldOremeta.setDisplayName(ChatColor.DARK_RED + bold + "Gold Ore");
                cc.add(ChatColor.GRAY + "Purchase this to mine " + ChatColor.GREEN + "Gold Ore" + ChatColor.GRAY + "!");
                cc.add(ChatColor.GRAY + "Cost :" + ChatColor.WHITE + " $" + ChatColor.GREEN + test);
                GoldOremeta.setLore(cc);
                GoldOre.setItemMeta(GoldOremeta);
            }
     
  4. Offline

    Zombie_Striker

    @CONTREKEE
    • Why is it public?
    • Why are you casting it to an int?
    • Does the GoldOre path get saved in the config?
    • Are you sure the string is exactly the same?
     
  5. Offline

    CONTREKEE

    @Zombie_Striker It is public so I am able to use it in the Item Stack, GoldOre. Casting it as an int or not casting it as an it doesn't change anything. Yes, the GoldOre path does get saved. Please do not comment without read what I posted. I put the code up there and you can see the path of GoldOre, and that is it the same. You can also see that the GoldOre path does get saved.
     
  6. Offline

    Maxx_Qc

    test =(int)(getConfig().getInt("GoldOre.Price"));

    Wow, your saying that a Int is a Int.

    test = getConfig().getInt("GoldOre.Price");
     
    Zombie_Striker likes this.
  7. Offline

    Zombie_Striker

    @CONTREKEE
    And from what you posted, test does not need to be public because it is not being accessed by another class.

    Can you show the config and post the entire class?
     
Thread Status:
Not open for further replies.

Share This Page