Development Assistance Plugin that creates config files.

Discussion in 'Plugin Help/Development/Requests' started by PlayerX2000, Jun 25, 2015.

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

    PlayerX2000

    I'm not sure if this is the right section to put this question, but here goes. I need help coding a custom plugin (Spigot 1.8). I've got the basic framework down for a few simple commands and a config file. However, I am creating a custom mini game plugin for a game I am going to put on my server. The plugin will let me create multiple arenas for this game. I would like the plugin to create a new config file for every arena that is created? How can I do this? I looked up creating multiple config files, and I found something that let me create multiple config files, but I had to create them in the plugin itself. The plugin couldn't keep creating more and more files based on commands.

    This is the code I used to create a custom config file

    Show Spoiler

    Code:
    private File arenaFile = null;
    private FileConfiguration arenaConfig = null;
    
    public void reloadArenaConfig() throws UnsupportedEncodingException
    {
        if(arenaFile == null)
        {
            arenaFile = new File(getDataFolder(), "arena.yml");
        }
    
        arenaConfig = YamlConfiguration.loadConfiguration(arenaFile);
        Reader arenaConfigStream = new InputStreamReader(this.getResource("arena.yml"), "UTF8");
    
        if(arenaConfigStream != null)
        {
            YamlConfiguration defConfigA = YamlConfiguration.loadConfiguration(arenaConfigStream);
    
            arenaConfig.setDefaults(defConfigA);
        }
    }
    
    
    public FileConfiguration getArenaConfig()
    {
    
        if(arenaConfig == null)
        {
            try {
                reloadArenaConfig();
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return arenaConfig;
    }
    
    
    publicvoid saveArenaConfig()
    {
    
        if(arenaConfig == null || arenaFile == null)
        {
             return;
        }
    
        try {
            getArenaConfig().save(arenaFile);
        } catch (IOException ex) {
            // TODO Auto-generated catch block
            getLogger().log(Level.SEVERE, "Could not save arena config to " + arenaFile, ex);
        }
    }
    
    
    
    
    publicvoid saveDefaultArenaConfig()
    {
    
        if(arenaFile == null)
        {
      
            arenaFile = new File(getDataFolder(), "arena.yml");
    
        }
    
        if(!arenaFile.exists())
        {
            plugin.saveResource("arenaConfig.yml", false);
        }
    }
    
    public FileConfiguration getArenaConfig;
    


    (This is not the full code for my entire plugin, just the part relevant to creating the custom config)


    I posted this question on the Minecraft Forums, and someone gave me this response.
    Show Spoiler


    What you need to do is white up a custom file handler that will make new files in your plugin's folder on demand. Look into JSON and how to create,edit,and read files. With tis you can create a method that will create a new file with whatever name you want and even put hem in a separate folder inside your plugin's folder to make everything nice and neat.


    For plugin support jump over to the Bukkit forums http://bukkit.org/forums/plugin-development.5/

    The developers are still very much active on the forums there.



    So, I'm posting this here, and I'm going to go look into JSON. If anyone has any links to good tutorials or ideas on how to do this, just reply here. Thanks![/code][/spoiler]
     
    Last edited: Jun 26, 2015
  2. Offline

    mine-care

    Can you please wrap up your code a bit, because it is hardly readable atm :3
     
  3. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives.
    @PlayerX2000 Use [code] <code here> [/code] instead of the spoilers
     
  4. Offline

    PlayerX2000

    What do you mean when you say wrap up my code a bit? Do you mean get rid of all the blank lines? If so, I will do that. That was some weird formatting thing that happened when I copy pasted it from my IDE. Also, I will use
    Code:
    
    
    Oh wow, I just edited the original post. It looks so much better now.
     
    Last edited by a moderator: Jun 25, 2015
Thread Status:
Not open for further replies.

Share This Page