Need a tester/fixer

Discussion in 'Plugin Development' started by theearlypc423, Jan 3, 2013.

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

    Jogy34

    Masterchat.getInstance()
     
  2. Offline

    theearlypc423

    cool
    ol

    Ok all of that worked now this line
    getCustomConfig
    ().save(
    file);

    or some random reason making it say getfileconfig() won't work. Any solution to this last small problem?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  3. Offline

    Jogy34

    just change getCustomConfig() to getConfig()
     
  4. Offline

    theearlypc423

    Oh my god I just completed my plugin! Sweet here i'll test it and tell you if it works!

    Ok it still won't generate the files for some reason. I have no clue why.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  5. Offline

    Jogy34

    In other words call getConfig() then saveConfig() in your load method.
     
  6. Offline

    theearlypc423

    Code:
    ackage info.bytecraft.sabersamus.MasterChat;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.logging.Level;
     
    import me.andrew.MasterChat.Masterchat;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
     
    public class ChannelConfig{
       
        private static File file = null;
        private static FileConfiguration fileConfig = null;
       
        public static void load(){
           
        }
       
        public static FileConfiguration getConfig(){
            if(fileConfig == null){
                reloadConfig();
            }
            return fileConfig;
        }
       
        public static void reloadConfig(){
            if(file == null){
                file = new File(Masterchat.getInstance().getDataFolder(), "Channels.yml");
            }
            fileConfig = YamlConfiguration.loadConfiguration(file);
           
            InputStream defConfigStream = Masterchat.getInstance().getResource("Channels.yml");
            if(defConfigStream != null){
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                fileConfig.setDefaults(defConfig);
            }
        }
        public static void saveCustomConfig() {
            if (fileConfig == null || file == null) {
            return;
            }
            try {
                getConfig().save(file);
            } catch (IOException ex) {
                Masterchat.getInstance().getLogger().log(Level.SEVERE, "Could not save config to " + file, ex);
            }
        }
    }
    Well heres the code but somthing just doesn't feel right about the way it is like with the public static void saveCustomConfig is that supposed to be changed to somthing as well?
     
  7. Offline

    Jogy34

    The static part just allows you to access it from any class without needing an instance of it so it's up to you if you want to leave it like that or if you want to take away the static part and make it so you either have to initialize it every time you want to get the config or have a local variable in each of your class that you use it in.
     
  8. Offline

    theearlypc423

    Hmm now exlain a little how I should do that.
     
  9. Offline

    Jogy34

    call getConfig() then saveConfig() in your load method.
     
  10. Offline

    theearlypc423

    Ok it works but for some reason only half of the yml file generated... I know exactly what your thinking :eek:

    Ok so this is what the saved file is like in eclipse
    Code:
    # this is the channels.yml file
    # channels are controlled by permission nodes
    # masterchat.<channelname>
    # you use the command to enter a channel
    # /ch <channelname>
    # the types are private and public
     
    Channels:
    # example:
    # prefix: 'example'
    # chatcolor: '&5'
     
        help:
            prefix: help
            chatcolor: '&5'
        admin:
            prefix: admin
            chatcolor: '&c'
        default:
            prefix:
            chatcolor: '&f'
     
    # If you create a new channel, add the name here please. Or stuff will break
    # //Sabersamus.
    Channel-list:
    - help
    - admin
    - default
    And this is what it looks like on the server when it generated...
    Code:
    # this is the channels.yml file
    # channels are controlled by permission nodes
    # masterchat.<channelname>
    # you use the command to enter a channel
    # /ch <channelname>
    # the types are private and public
    
    Do you know what may cause this kind of error?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  11. Offline

    Jogy34

    No clue. I don't use default config files
     
  12. Offline

    theearlypc423

    This is a custom config file dude remember?
     
  13. Offline

    Jogy34

    So. I use custom config files for a few of my plugins and I still don't use and have never used default config files.
     
  14. Offline

    theearlypc423

    Oh hmm this is still very odd.
     
Thread Status:
Not open for further replies.

Share This Page