Problem with my config list.

Discussion in 'Spigot Plugin Development' started by MLGSeller, Jun 25, 2018.

  1. Hi,so I'm making an block multiplier,I have 2 blocks in the list but it works only for one block and not others.
    Code (Text):

            sect = plugin.getConfig().getConfigurationSection("blockList").getKeys(false);
            for(String key : sect)
            {
                if(sect != null)
                {
                    if(e.getBlock().getType() == Material.matchMaterial(plugin.getConfig().getString("blockList." + key + ".name")))
                    {
                        System.out.print(plugin.getConfig().getString("blockList." + key + ".exp"));
                        plugin.getLogger().log(Level.INFO,"Modified multiplier");
                    }else {
                        plugin.getLogger().log(Level.INFO,"Default Multiplier");
                    }
                }else
                {
                    plugin.getLogger().log(Level.INFO,"Sect is null");
                }
            }
     
    To be exact it only works for the last block in the config file.
    Code (Text):

    blockList:
      DIAMOND_ORE:
        exp: 5
        name: DIAMOND_ORE
      OBSIDIAN:
        exp: 2
        name: OBSIDIAN
     
     
  2. well because it retrieves the number correctly but just adds it wrong, it means something is off with your conversion of that number into the player's experience. Could you show us the code involved with spitting out that debug message?
     
  3. Code (Text):

    plugin.getRDatabase().giveMultiplier(plr, (exp + plugin.getConfig().getInt("blockList." + e.getBlock().getType() + ".exp")), lvl);
     
     
  4. Okay, but we can't actually base anything off of this, can you give me the "giveMultiplier" method?
     
  5. It just sets the values in the database,just modifies/updates them.
    its something like
    db.setValues(player,multiplier,level)
    It just doesnt calculate anything in that method,I calculate the stuff when giving the multiplier.
     
  6. I'm pretty sure its wrong with block checking.
    Code (Text):

    if(e.getBlock().getType() == Material.matchMaterial(plugin.getConfig().getString("blockList." + key + ".name")))
                    {
                    }
     
    Because it says Default Multiplier and Modified Multiplier
    edit:
    yeah found the problem but not sure on how I should solve it.
    Whenever it loops through the blockList in the config,it says Default Multiplier and then modified multiplier after it gets to the last block when you destroy the block that is the last in the config it says modified multiplier,so I got no idea on how I should try to fix it,
    in short.
    It checks for all the blocks and only multiplies it if you break the last block in the config.
     
  7. So anyone has any ideas on what my problem could be? I kind of know it but dont know how to solve it.
    Whenever it loops through the Values in the stringlist of the config,It only multiplies if you break a block that is the last one in the config file.
     
  8. Well, for one why are you testing to see if sect isn't null since you are doing a for (String keys : sect) you should be really testing for keys as far as I know.