Solved ItemStack Amount from config.

Discussion in 'Plugin Development' started by CrystallFTW, May 28, 2015.

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

    CrystallFTW

    So I created a plugin that will give a player an item from config with amount and damage.
    this is my code:
    Code:
                   
    for(String keys : this.getConfig().getConfigurationSection("Reward.Items.Materials").getKeys(false)){
                      
                        int amountint = instance.getConfig().getInt(keys +".Amount");
                        p.getInventory().addItem(new ItemStack(Material.valueOf(keys), amountint, (short) this.getConfig().getInt(keys +".Short")));
                      
                        String amount = this.getConfig().getInt(keys +".Amount") + "";
                        p.sendMessage(UtilChatColor.colorizeString(Language.getString("Language.ItemReward").replaceAll("%amount", amount).replaceAll("%material", keys)));
                      
                      
                    }
    
    For some reason the amount is always 0 .

    My config looks like this:
    Code:
       Reward:
         Enabled: true
         Materials:
          Items:
           'DIAMOND':
             Amount: 1
             Short: 0
           'DIAMOND_SWORD':
             Amount: 1
             Short: 0
    
     
    Last edited: May 28, 2015
  2. Offline

    Ziron5

    Actually I'm surprised that you get an Item at all becuase the path to your Items isn't "Reward.Items.Materials".
    It's just "Reward.Materials".

    Try to change that in your for loop
     
  3. Offline

    CrystallFTW

    @Ziron5 oh yea, i changed my config path only here because i don't want to post the whole config. This will be easier for an example for the develpoers that have the same problem. The path is right.
     
  4. Offline

    Ziron5

    @CrystallFTW Okay what does the message say that you send to the player?

    edit: Or more exactly: Is the content of the amount String "0" ?
     
  5. Offline

    CrystallFTW

  6. Offline

    Ziron5

    Is it possible that you wrote that config by hand? Maybe you have a spacing error
     
  7. Offline

    CrystallFTW

    @Ziron5 It is written by hand but there aren't any spacing errors.
    I think I should change my config file.
     
Thread Status:
Not open for further replies.

Share This Page