Bukkit ConfigurationYAML Cannot save Integer list?

Discussion in 'Bukkit Discussion' started by AngryCupcake274, Dec 31, 2015.

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

    AngryCupcake274

    Hello,
    I am making a plugin that keeps a list of players and a list of Integers. The list of players is a String list of their names, and the Integer list is, well, just an Integer list. When I try to save to the config.yml file, though, it doesn't save...I have no clue why this happens...

    Code:
    Code:
    gc.setList("playerList", plugin.playerKillList);
    gc.setList("playerKills", plugin.killsList);
    gc.setList():
    Code:
        public void setList(String path, List<?> value) {
          
            FileConfiguration config = null;
            File file = new File(plugin.getDataFolder() + File.separator + "config.yml");
          
            config = YamlConfiguration.loadConfiguration(file);
          
            config.set(path, value);
          
            try {
              
                config.save(file);
              
                this.loadConfiguration();
              
            } catch (IOException e) {
              
                plugin.console.sendMessage(ChatColor.RED + "Error saving config file!");
              
            }
        }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 And what if you use the regular config? The one from getConfig
     
  3. Offline

    AngryCupcake274

    I am not using that because I need to use multiple config files.

    @timtower I have used this ConfigurationYAML on other plugins, but I have always used String lists.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    @timtower did you edit that :)
     
    Last edited: Dec 31, 2015
  4. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 Can you try it for the default config? Doesn't have to be definitive.
    And I didn't, that is a bot, thread about it in offtopic called "Auto merged"
     
  5. Offline

    AngryCupcake274

    @timtower The problem lies with the saving! I don't know why the actual crap Bukkit would not support Integer lists, and every time I try to make it a string list, and after changing all my code, I get "cannot cast String to Integer" EVEN IF I USE Integer.parseInt(string)! WHY DOES THAT METHOD NOT WORK!?!?!?!

    Oracle pls fix
     
  6. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 Bukkit even supports lists of custom classes.
    Could you post the load for saving and loading?
    Can try it tomorrow myself but I doubt that it will fail.
     
  7. Offline

    AngryCupcake274

    @timtower
    Code:
    Code:
        @SuppressWarnings("unchecked")
        public void loadConfiguration() {
           
            plugin.lobbyLoc = getLocation(this.getList("lobby"));
            plugin.spawn1 = getLocation(this.getList("spawn1"));
            plugin.spawn2 = getLocation(this.getList("spawn2"));
            plugin.spawn3 = getLocation(this.getList("spawn3"));
            plugin.spawn4 = getLocation(this.getList("spawn4"));
            plugin.spawn5 = getLocation(this.getList("spawn5"));
            plugin.spawn6 = getLocation(this.getList("spawn6"));
            plugin.spawn7 = getLocation(this.getList("spawn7"));
            plugin.spawn8 = getLocation(this.getList("spawn8"));
           
            plugin.kills1 = getLocation(this.getList("kills1"));
            plugin.kills2 = getLocation(this.getList("kills2"));
            plugin.kills3 = getLocation(this.getList("kills3"));
           
            plugin.playerKillList = (List<String>) this.getList("playerList");
            plugin.killsList = (List<Integer>) this.getList("playerKills");
           
        }
       
        public void saveConfiguration() {
           
            this.setList("lobby", getList(plugin.lobbyLoc));
            this.setList("spawn1", getList(plugin.spawn1));
            this.setList("spawn2", getList(plugin.spawn2));
            this.setList("spawn3", getList(plugin.spawn3));
            this.setList("spawn4", getList(plugin.spawn4));
            this.setList("spawn5", getList(plugin.spawn5));
            this.setList("spawn6", getList(plugin.spawn6));
            this.setList("spawn7", getList(plugin.spawn7));
            this.setList("spawn8", getList(plugin.spawn8));
           
            this.setList("kills1", getList(plugin.kills1));
            this.setList("kills2", getList(plugin.kills2));
            this.setList("kills3", getList(plugin.kills3));
           
            this.setList("playerList", plugin.playerKillList);
            this.setList("playerKills", getStringListFromIntegerList(plugin.killsList));
           
        }
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. Offline

    AngryCupcake274

    @timtower The problem is when I am saving, not loading. (At least from my testing.)
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    mcdorli

    I don't see a saveConfig() in your code
     
  12. Offline

    timtower Administrator Administrator Moderator

    First post, second block, line 12
     
  13. Offline

    AngryCupcake274

    @timtower I am not getting errors, only if I try to turn my Integer list to a String list I get a "String cannot be cast to Integer error". (Even though I'm using Integer.toString() or String.valueOf() on an Integer)

    EDIT: For my problem I would not have these problems as I would like to save the Integer list directly.
     
  14. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 Then why are you trying to save an integer list as string list?
     
  15. Offline

    AngryCupcake274

    @timtower No, I was using a loop and making a new list:
    Code:
    private ArrayList<String> getStringListFromIntegerList(List<Integer> list) {
        ArrayList<String> newList = new ArrayList<String>();
        for (Integer num : list) {
            newList.add(Integer.toString(num)); // or String.valueOf(num); (both didn't work)
        }
        return newList;
    }
    I was calling that method then saving the new list. That was my second idea. So far I have tried saving the Integer list, the Integer.toString(num); list, and the String.valueOf(num); list. None have worked so far.
     
  16. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 And why are you converting then? That doesn't make sense to me.
    And tried num+"" ?
     
  17. Offline

    AngryCupcake274

    @timtower I'm trying this because since it wouldn't let me use an Integer list, I was trying converting the Integer list to a String list. Those were my (failed) attempts.
     
  18. Offline

    AngryCupcake274

    @timtower bump. (I tagged you in case other notifications didn't show you this one.)

    EDIT: I'm not at my PC at the moment (on a bad laptop), when I get home I will try your methods.
     
  19. Offline

    timtower Administrator Administrator Moderator

    @AngryCupcake274 It did notify me, try a regular integer list in a regular bukkit config using getConfig.
     
  20. Offline

    AngryCupcake274

    @timtower List for tomorrow:
    • Try num + 1
    • Go back to *shudder* default Bukkit config.
     
Thread Status:
Not open for further replies.

Share This Page