Custom file generates on 1.12 but not 1.13

Discussion in 'Spigot Plugin Development' started by LegendOfzLink, Aug 3, 2018.

  1. Hey, basically I have a file to store player data, and I have updated the plugin and compiled with 1.13 spigot, and there are ZERO errors, interestingly enough, it works on 1.12 and not 1.13, even though the file codes don't change between those versions. The file doesent get created, and if i manually create it, it doesen't write to it.

    Here is some of the file related code. would appreciate any help.

    Code (Text):
      public static File playerdataFile = new File("plugins/LevelAchievements", ("playerdata.yml"));
      public static FileConfiguration playerdata = YamlConfiguration.loadConfiguration(playerdataFile);
    Code (Text):
        if (!playerdata.isConfigurationSection("players")) {
          playerdata.createSection("players");
        }
    and some of my methods.
    Code (Text):
      public void setPlayerConfigLevel(Player p, int level)
      {
        if (Main.playerdata.isConfigurationSection("players." + p.getUniqueId()))
        {
          Main.playerdata.set("players." + p.getUniqueId() + ".level", Integer.valueOf(level));
          Main.playerdata.set("players." + p.getUniqueId() + ".max", Boolean.valueOf(false));
          try
          {
            Main.playerdata.save(Main.playerdataFile);
          }
          catch (IOException e1)
          {
            e1.printStackTrace();
          }
        }
      }
    Code (Text):
      public void addPlayerToConfig(Player p)
      {
        Main.playerdata.createSection("players." + p.getUniqueId());
     
        Main.playerdata.set("players." + p.getUniqueId() + ".level", Integer.valueOf(1));
        try
        {
          Main.playerdata.save(Main.playerdataFile);
        }
        catch (IOException e1)
        {
          e1.printStackTrace();
        }
      }
     
      public int getPlayerConfigLevel(Player p)
      {
        if (Main.playerdata.isConfigurationSection("players." + p.getUniqueId())) {
          return Main.playerdata.getInt("players." + p.getUniqueId() + ".level");
        }
        return 0;
      }
     
      public Level getPlayerLevel(Player p)
      {
        return getLevelFromID(getPlayerConfigLevel(p));
      }
    NOTE* the config file generates fine. just the target file playerdata.yml not working at all
     
  2. Do you mean zero compile errors or zero runtime errors? Presumably both?

    To debug, try to print some console messages for each if() block to make sure the plugin is accessing those paths. Just to rule out a faulty logic somewhere along the lines. If it doesn't print something you're expecting, then you can see if it's the if statement that's causing something not to work. I know you said it works in 1.12.2, but I can't help but think there's some possibility that the logic flow may be different if something doesn't load quite properly or such. Just a way to narrow down where the problem is.

    This isn't liable to fix anything, but instead of specifying the folder that the file is in:
    If you instantiate the File in onEnable (obviously before trying to load anything), you can use getDataFolder()
    Code (Java):
    new File(getDataFolder(), "playerdata.yml");
    Bit more standard, and makes sure the data folder is the name of the plugin. Just a suggestion though, not necessary.
     
  3. Thanks for the help, after trying this I am still seeming to have no luck.
     
  4. I added a log to where it checks if the players section in the config is there and creates it. It logs to the console that the statement runs, but its not generating it.

    Code (Text):
        if (!playerdata.isConfigurationSection("players")) {
            Bukkit.getServer().getLogger().info("Players section created");
          playerdata.createSection("players");
        }
     
  5. I've never used createSection. Generally if you set a value that doesn't already exist, it'll create it and any keys it needs along the way. I'm not sure if it's the proper way, but never has let me down.
     
  6. its the way ive always done it :/