How can i register my config in my main class?

Discussion in 'Plugin Development' started by Lenis3, Aug 10, 2017.

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

    Lenis3

    (PLEASE do not hate on my and tell me to learn Java beacuse im a beginner and i want to be as good or better than you so please help instead of posting a RUDE answear or something like that)

    Well, it i think you already saw the title so just start to get in to it i got my main class and a few other classes but i dont know how the hell i can register the config to my main class!
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Lenis3 Did you try getConfig() ?
     
  3. Offline

    Zombie_Striker

    @Lenis3
    We only tell users to learn Java when it is clear they have not learned Java before bukkit. Bukkit is built with Java, so you need to have a good understanding of how Java works before you can work on bukkit. We say this because people who do not know java either do not understand fundamental concepts of Java, which means users post the same thread about simple practices over and over again, or the user doesn't know the jargon and requires us to write the code for them in order to understand (neither of the two results do we want).

    You do not need to register the default config. Just use getConfig() to get the config.yml. If you wanted to create a custom yml, you will need to get the file's instance and use the YamlConfiguration.loadConfiguration() to load the file.
     
  4. Offline

    Lenis3

    Okay, thak you i just asked one of my friends and he told me that where the easisets way but he leaved the discord server after like 1h so i whre like fucked up. But again thanks for the help!

    Like this?

    Code:
    private Core plugin;
    
    p.sendMessage(plugin.getConfig().getString("ResetMessage"));
    and this?

    Code:
                getConfig().options().copyDefaults(true);
                saveConfig();
     
    Last edited: Aug 10, 2017
  5. Offline

    Zombie_Striker

    @Lenis3
    Assuming that you set 'plugin' in the constructor, yes.
     
  6. Offline

    Lenis3

    Well, i have it and when i have
    Code:
    p.sendMessage(plugin.getConfig().getString("ResetMessage"));
    an error pop up from the console, when i dont use it it wont happend... :(
     
  7. Offline

    timtower Administrator Administrator Moderator

    @Lenis3 Please post your entire class
     
  8. Offline

    Lenis3

  9. Offline

    timtower Administrator Administrator Moderator

    @Lenis3 Pass the main instance to the listeners using a constructor.
     
  10. Offline

    AdamDev

    @Lenis3
    I know this is not to solve the whole problem but I do suggest making a registerCommands() constructor and registerListeners() constructor. It will help later on if you have tons of commands and listeners.

    Edit: As @timtower had said, you need to make a constructor that returns your plugin.
     
  11. Offline

    Lenis3

    Thank you very much guys!
     
  12. Offline

    Zombie_Striker

    @Lenis3
    If your problem has been solved, mark this thread as solved.
     
  13. Offline

    Lenis3

  14. Offline

    timtower Administrator Administrator Moderator

    @Lenis3 Please post the new code for WearEvents
     
  15. Offline

    AdamDev

    @Lenis3 The lines between 70-80, can you paste them please.
     
Thread Status:
Not open for further replies.

Share This Page