Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4509

[Refactor] Plugin interface & JavaPlugin implementation should be not hardcoded

XMLWordPrintable

    • Not applicable for Improvement/Refactor request that is version independent
    • Yes

      https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/Plugin.html

      https://hub.spigotmc.org/javadocs/spigot/org/bukkit/plugin/java/JavaPlugin.html

      JavaPlugin.getConfig() calls reloadConfig() which harcodes "config.yml".

      These methods (getConfig, reloadConfig, saveConfig) should be overloaded to accept a parameter name for the name of a different configuration.  Kind of like how getResource() & saveResource() accept a parameter for the name of any resource.

      The current implementation creates duplication of code in all projects.

      The new implementation will make for an easier to use API.

      So for example, I am proposing that the implementation for these methods merely forwards its call with getConfig("config.yml"), reloadConfig("config.yml"), saveConfig("config.yml") and that the API provide three new methods:

       

      public abstract FileConfiguration getConfig(String name);
      public abstract void reloadConfig(String name);
      public abstract void saveConfig(String name);
      

       

      Possible problems:

      The first & most obvious is that reloadConfig() & saveConfig() require File objects to do their work.  There are a plethora of different ways to handle this... from mapping the file name to its file object... To simply creating the object on the fly:

      public void saveConfig(String name)
        {
          try
          {
            getConfig().save(new File(this.dataFolder, name); // **CHANGED**
          }
          catch (IOException ex)
          {
            this.logger.log(Level.SEVERE, "Could not save config to " + this.configFile, ex);
          }
        }
      

      And this object creation might cause significant slow down ? (If it's called too much during a tick).  Or it might be negligible ?

      Are there any other possible problems ?

      Conclusion:

      I believe this is a worthwhile change (altho admittedly minor).

      If not, that's fine, but just out of pure curiosity, I would like to know why.  Thanks !

            Unassigned Unassigned
            Europia79 Europia79
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: