InvocativeTargetException and config problems help

Discussion in 'Plugin Development' started by Jogy34, Aug 26, 2011.

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

    tyzoid

    What's the code for your configuration class?

    And how is your config file formatted?
     
  2. Offline

    Jogy34

    @tyzoid I dont have a configuration class. Do I need one?
     
  3. Offline

    tyzoid

  4. Offline

    Jogy34

    @tyzoid why would Properties be better
     
  5. Offline

    tyzoid

    @Jogy34
    Take a look at the Configuration documentation. (javax.security.auth.login.Configuration)

    Properties is generally used for config-files.
     
  6. Offline

    Jogy34

    @tyzoid ok and I have to make a separate class for Properties, right?
     
  7. Offline

    tyzoid

    @Jogy34
    You should hav a class that saves/loads properties from the file.
    It's also a good idea to have only one instance of the class as a member variable in your main plugin file.
     
  8. Offline

    nisovin

    Bukkit has its own Configuration class that is used to create and read yml files. Using Properties is ok, but Configuration is better.

    What? Do you even know what you're doing at all? You can declare the variable as a class member, then still access it from the constructor. Leave this:
    Code:
    public Configuration config;
    where it is. Then put this in your constructor:
    Code:
    config = instance.getConfiguration();
    config.load();
    Easy as that.

    Have you considered looking up some Java tutorials, and learning how this stuff works? It's obvious you're just kind of scrambling here.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  9. Offline

    Jogy34

    @nisovin I've tried that before (infact you told me to do that exact thing) and it didn't work. I'm just going to go with the properties file like what @tyzoid said

    @tyzoid I have figured out how to create property files but I have no idea what I would do for a property class. Can you help me here?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  10. Offline

    tyzoid

    @Jogy34
    If your plugin already reads it, its fine. It is useful if you want to keep code seperate.
     
  11. Offline

    Jogy34

    @tyzoid I still want to know how to do it for future plugins of mine. Can you point me in the direction of a tutorial at least.
     
  12. Offline

    tyzoid

    @Jogy34
    Do you mean user data? Or general configuration data?
     
  13. Offline

    Jogy34

    @tyzoid both but mainly general configuration data
     
  14. Offline

    AJCStriker

    The handle by Nijikokun had a good bit about configuration files.
     
  15. Offline

    Jogy34

  16. Offline

    AJCStriker

  17. Offline

    Jogy34

    can someone please tell me where i can find a written tutorial
     
  18. Offline

    Jogy34

    @Adamki11s how do I choose where the config is made
     
  19. You just specify the file.
     
  20. Offline

    Jogy34

    @Adamki11s how?

    EDIT:
    I made a plugin to test a few things with config files and I have this:
    Code:
    public static Configuration config = new Configuration(new File(plugin.getDataFolder(), "Config.yml"));
    
    but there is an error on plugin.getDataFolder() saying plugin cant be resolved and when I try doing
    Code:
    JavaPlugin plugin;
    
    like it suggests it gives me an error when I test it on the server
     
  21. public static Configuration c = new Configuration(new File("plugins" + File.separator + "MyPlugin" + File.seperator + "Config.yml"));
     
  22. Offline

    Jogy34

    @Adamki11s That got rid of all of the errors but it doesn't make a config file
     
  23. You have to then use it to make one, it just just 'appear' when you create the object.

    EG:
    Code:java
    1.  
    2. File root = new File("plugins" + File.separator + "MyPlugin");
    3. File configFile = new File(root + File.seperator + "Config.yml");
    4. public void createConfig() throws IOException{
    5. if(!root.exists()){
    6. root.mkdir();
    7. }
    8. if(!configFile.exists()){
    9. configFile.createNewFile();
    10. //set properties here
    11. }
    12.  
    13. Configuration c = new Configuration(configFile);
    14. c.load();
    15. //load properties here.
    16. }
    17.  


    Put it anywhere, just call it when you need your config created/loaded.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 19, 2016
  24. Offline

    Jogy34

    @Adamki11s sorry about that I was making idiotic mistakes
     
  25. It's fine, we're all here to help; well most are ;)
     
  26. Offline

    Jogy34

    @Adamki11s
    How do I get the value from the config file in a different class?
     
  27. Sorry, not to sound rude but if you don't know this you really need to go and get a better understand of java. I'd recommend the new boston's video tutorials on youtube.
     
  28. Offline

    Jogy34

    @Adamki11s I've tried setting the value in the main class and then getting it in my other class using private variables and get/set methods, I've tryed using public variables and then just <class name>.<variable>, Neither of those worked because I couldn't get the value out of the createconfig() method, I've also tried to get the configuration in my second class using basically the same method but without trying to create it but that didn't work either.
     
  29. When you load the config you need to either put your variables into a permanent variable or pass then along to another class.
     
Thread Status:
Not open for further replies.

Share This Page