Config Files

Discussion in 'Spigot Plugin Development' started by Yoreni, May 28, 2017.

  1. Do any one know how to use config files problay
    I tryied Bukkit's config file methods but they dont work in static methods
  2. What do you want to do with it?
  3. like make a API sort thing the formats numbers and people can change the suffix of the abbateion in the config
  4. Small tip: Dont use static if its not necessarily
  5. In this case it is nessary cos people or i might be useing the methods in thier plugins
  6. It really isn't.
    Static should only be used for utilities in a private constructor class, for (very few) nested classes and mostly just instances for normal classes.

    E.g. if you store a config object statically, please stop and go back to learning basic Java, as that is not something you should ever do.
  7. How else are people going to use the methods if i dont use static? what can replace static?
  8. Using instances. As stoneminer said, it's definitely a good idea to learn the basics of Java before diving into plugin development.

    As for the original post, what Bukkit methods were you trying to use? What do you need to know / are trying to do?
  9. You don't always want to create new instance all the time to access something though, that could lead to memory leaks. Use getters and setters.
  10. electronicboy

    IRC Staff

    if you're creating a new instance all the time to access something, that's called bad practice, but isn't going to create a memory leak unless you make it cause one. Storing stuff using static just because you're too lazy to create an instance, now that's wasteful because you have stuff that can't be GC'd until the class itself is unloaded.

    in general, they'd get an instance of your plugin from the plugin manager, e.g. Bukkit.getPluginManager().getPlugin("MyAPI");
    they'd then be able to check if the plugin manager returned null, in which case, your plugin isn't on the server, or it would return your plugins instance, in which they can then cast to whatever your main class is (Which, /should/ be reflective of your main class and not called something arbitrary like "Main", e.g. NicknamePlugin) they would then be able to use the public methods on your classes instance, which can be exposed without static as they actually have a reference to your plugin.
    • Agree Agree x 1
  11. If you are developing an API on top of spigot, make all functionality available in the main class. Now, users of your library can do Bukkit.getPluginManager().getPlugin("yourAPI") to get access to your API.

    [Edit] Oups, haven't read electronicboys reply...