Solved The use of Multiple Config Files

Discussion in 'Plugin Development' started by ScottDurkin_, Nov 22, 2018.

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

    ScottDurkin_

    Hi all,

    So I am pretty new to Bukkit Development and I have been developing a plugin for our server and I want to keep things in separate config files.

    So I have the config.yml setup and it has some information inside of it that is used globally but I would like to dedicate another .yml file to our banking system so it can use it's own set of parameters and not have to look for them inside of the config.yml

    I have within my project a .yml file called "mcbank.yml" but I want to be able to create it with the information I have inside it within the plugins folder and be able to reference from it.

    Now I have tried googling this a lot, 8 hours to be exactly of solid googling and testing but it all seems to boil down to creating the mcbank.yml inside the plugins folder but non of the information is within like it would be inside eclipse.

    Since it has been 2 hours since I last searched, I have deleted the code since and if someone can help me that would be awesome :)

    BLANK MCBANK.YML
    upload_2018-11-22_14-57-5.png

    MCBANK.YML INSIDE ECLIPSE:
    upload_2018-11-22_14-57-45.png

    Hopefully one of you awesome experienced people could shine some light on my struggle!

    Thanks in advance,
    Scott
     

    Attached Files:

  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    ScottDurkin_

  4. Offline

    timtower Administrator Administrator Moderator

    That is what I linked.
    It copies over the file from the jar to the plugins folder.
     
  5. Offline

    ScottDurkin_

    Okay perfect I will give this a go and see how we get on, I will get back to you :) - Thanks!

    Hi there I just tried to save the resource and it is creating the config file but no information within, here is the code below.

    Code:
    package org.HumbleMC.Libraries;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.HumbleMC.HumbleMC.Main;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    
    public class SettingsManager {
    
        private Main plugin = org.HumbleMC.HumbleMC.Main.getPlugin(Main.class);
    
        // Files & File Configs Here
        public FileConfiguration config;
        public File configFile;
       
        //McBank
        public FileConfiguration McBank;
        public File mCBankFile;
        // --------------------------
    
        public void setup()
        {
            if (!plugin.getDataFolder().exists())
            {
                plugin.getDataFolder().mkdir();
            }
    
            configFile = new File(plugin.getDataFolder(), "config.yml");
    
            if (!configFile.exists())
            {
                try
                {
                    configFile.createNewFile();
                    Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "The players.yml file has been created");
                }
                catch (IOException e)
                {
                    Bukkit.getServer().getConsoleSender()
                            .sendMessage(ChatColor.RED + "Could not create the players.yml file");
                }
            }
    
            config = YamlConfiguration.loadConfiguration(configFile);
           
            McBank();
        }   
       
       
        void McBank()
        {
            if (!plugin.getDataFolder().exists())
            {
                plugin.getDataFolder().mkdir();
            }
    
            mCBankFile = new File(plugin.getDataFolder(), "mcbank.yml");
    
            if (!mCBankFile.exists())
            {
                try
                {
                    mCBankFile.createNewFile();
                    Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "The mcbank.yml file has been created");
                }
                catch (IOException e)
                {
                    Bukkit.getServer().getConsoleSender()
                            .sendMessage(ChatColor.RED + "Could not create the players.yml file");
                }
            }
    
            McBank = YamlConfiguration.loadConfiguration(mCBankFile);
            plugin.saveResource(McBank.getCurrentPath(), true);
        }
    
        public FileConfiguration getConfig() {
            return config;
        }
    
       
        public void saveConfig() {
            try {
                config.save(configFile);
                Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "The config.yml file has been saved");
    
            } catch (IOException e) {
                Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Could not save the config.yml file");
            }
        }
    
        public void reloadConfig() {
            config = YamlConfiguration.loadConfiguration(configFile);
            Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.BLUE + "The config.yml file has been reload");
    
        }
    }
    Here is the error from console:
    Code:
    java.lang.IllegalArgumentException: ResourcePath cannot be null or empty
            at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:179) ~[minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.HumbleMC.Libraries.SettingsManager.McBank(SettingsManager.java:78) ~[?:?]
            at org.HumbleMC.Libraries.SettingsManager.setup(SettingsManager.java:50) ~[?:?]
            at org.HumbleMC.HumbleMC.Main.loadConfigManager(Main.java:68) ~[?:?]
            at org.HumbleMC.HumbleMC.Main.onEnable(Main.java:63) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:254) ~[minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:339) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:434) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:348) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.reload(CraftServer.java:807) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.Bukkit.reload(Bukkit.java:570) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:139) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchCommand(CraftServer.java:702) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at org.bukkit.craftbukkit.v1_13_R2.CraftServer.dispatchServerCommand(CraftServer.java:687) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at net.minecraft.server.v1_13_R2.DedicatedServer.aU(DedicatedServer.java:459) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:418) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:835) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]
            at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:733) [minecraft_server.jar:git-Spigot-947a8e7-3a91182]


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 22, 2018
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    ScottDurkin_

    In the Main.java Here is the code:
    Code:
    package org.HumbleMC.HumbleMC;
    
    import java.io.File;
    
    import org.HumbleMC.HumbleMC.Commands.Donate;
    import org.HumbleMC.HumbleMC.Commands.GetVersion;
    import org.HumbleMC.HumbleMC.Commands.McBank;
    import org.HumbleMC.HumbleMC.Commands.McBuycraft;
    import org.HumbleMC.HumbleMC.Commands.McPrefix;
    import org.HumbleMC.HumbleMC.Commands.McRanks;
    import org.HumbleMC.HumbleMC.Commands.McRenew;
    import org.HumbleMC.HumbleMC.Commands.McVote;
    import org.HumbleMC.HumbleMC.Commands.PowerArmor;
    import org.HumbleMC.Libraries.SettingsManager;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.milkbowl.vault.economy.Economy;
    
    public class Main extends JavaPlugin
    {
        private SettingsManager cfgm;
        public static Economy economy;
        FileConfiguration config;
        File cfile;
       
        //Bank Config file
        public FileConfiguration BankConfig;
        File fBankConfig;
       
        public void onEnable()
        {
            if (!setupEconomy())
            {
                Bukkit.shutdown();
            }
           
            System.out.println("[HumbleMC] Has loaded Correctly.");
            this.getCommand("prefix").setExecutor((CommandExecutor)new McPrefix(this));
            this.getCommand("vote").setExecutor((CommandExecutor)new McVote());
            this.getCommand("mcupgrade").setExecutor((CommandExecutor)new McRanks(this));
            this.getCommand("bank").setExecutor((CommandExecutor)new McBank(this));
            this.getCommand("mcbroadcast").setExecutor((CommandExecutor)new McRanks(this));
            this.getCommand("mcremoverank").setExecutor((CommandExecutor)new McRanks(this));
            this.getCommand("mcbuy").setExecutor((CommandExecutor)new McBuycraft(this));
            this.getCommand("mcrenew").setExecutor((CommandExecutor)new McRenew(this));
            this.getCommand("newpa").setExecutor((CommandExecutor)new PowerArmor());
            this.getCommand("humblemc").setExecutor((CommandExecutor)new GetVersion(this));
            this.getCommand("donate").setExecutor((CommandExecutor)new Donate());
           
            //config = getConfig();
           //config.options().copyDefaults(true);
            //saveConfig();
            //cfile = new File(getDataFolder(), "config.yml");  
           
            loadConfigManager();
        }
       
        public void loadConfigManager(){
            cfgm = new SettingsManager();
            cfgm.setup();
    //        cfgm.saveConfig();
    //        cfgm.reloadConfig();
        }
     
  8. Offline

    timtower Administrator Administrator Moderator

    @ScottDurkin_ McBank.getCurrentPath() returns null probably.
     
  9. Offline

    ScottDurkin_

    I'm so confused of why :S

    upload_2018-11-22_15-36-53.png
     
    Last edited by a moderator: Nov 22, 2018
  10. Offline

    timtower Administrator Administrator Moderator

    @ScottDurkin_ And does that cause issues or not? And that + is from git right?
     
  11. Offline

    ScottDurkin_

    The function creates the file it's just not bringing the data from the mcbank.yml into the mcbank.yml inside the plugins folder. And the + is Team Foundations :)
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    ScottDurkin_

    The worked!! Thanks man!!
     
Thread Status:
Not open for further replies.

Share This Page