Hello! Im newer to java / spigotapi and the course i took did not include new files and stuff, So i read the Bukkit Wiki, It does not make total sense, Can someone Help me further? Bukkit TUT: Code (Text): If for whatever reason you need another configuration file, you can use YamlConfiguration to make a new one. FileConfiguration data = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "data.yml")); This reads the file data.yml from your data folder, and returns a FileConfiguration. If the file does not exist, the FileConfiguration is empty. If you need a pre-made FileConfiguration to be used, you can instead use an InputStream. FileConfiguration data = YamlConfiguration.loadConfiguration(getResource("data.yml")) This takes the InputStream from getResource, which gets a file embedded in the jar, and retreives a FileConfiguration from that.
You literally call File::createNewFile(), any hit on Google would've told you that (by searching something like "java create file")
*sigh* Nothing to do with the spigot API (besides the YamlConfiguration class included in it), and everything to do with Java itself. http://lmgtfy.com/?iie=1&q=How+to+create+a+file+in+a+directory+in+java?
You basically use Java itself to create a new file, then turn it into a yaml configuration file. Code (Text): // To load it: File newFile = new File(this.dataFolder(),"locations.yml"); FileConfiguration secondConfig = Yaml configuration.loadConfigurationFile(newFile); // Now you can do whatever with it like a normal config // And to save: secondConfig.save(newFile);
Auto correct messed me up. Im writing this from my phone so plz don't sue me (It's meant to be "YamlConfiguration")
Code (Text): public static FileConfiguration data; public File datafile; public void setup() { if (!plugin.getDataFolder().exists()) { plugin.getDataFolder().mkdir(); } datafile = new File(plugin.getDataFolder(), "data.yml"); if (!datafile.exists()) { try { datafile.createNewFile(); Core.plugin.saveResource("data.yml", false); }catch (IOException e) { Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml"); } } data = YamlConfiguration.loadConfiguration(datafile); } public void reloadData() { data = YamlConfiguration.loadConfiguration(datafile); }
Thank you all! and @jetp250 i looked over the code and i do under stand it Thank makes alot of sense! Thanks for the help