Why Shouldn't you assign getConfig() to static field?

Discussion in 'Spigot Plugin Development' started by bobbutts, Jul 5, 2018.

  1. The Bukkit reference tells me not to assign the return from getConfig() to a static field. It has red exclamation points so I blindly follow.


    But why not? What is the advantage of using a constructor to get the configuration over accessing it as a static field?
  2. If you still want to know. The line below yours says

    If you use a static it will not be updated on a reload and other events that have todo with the config.
    • Agree Agree x 1
  3. MiniDigger


    there is really no need to save a reference to the config anywhere when you can just call getConfig(), it only introduces issues when the config object gets recreated and doesn't provide any benefits.
  4. Is there ever a situation where you just want to store the old configuration? Like in a static read only? I could see that being useful if the config get saved over and they need a backup from RAM? I feel like the warning is just to prevent the accidental use of a stale config?

    Anyway configs are hard to grasp :S