Class DataManager

java.lang.Object
rocks.gravili.notquests.spigot.managers.DataManager

public class DataManager extends Object
This is the Data Manager which handles loading and saving Player Data, Quest Data and Configurations. The Configuration files 'quests.yml' and 'general.yml' are created here. The MySQL Database is also created here.
  • Field Details

    • completions

      public final List<String> completions
      ArrayList for Command Tab Completions. They will be re-used where possible. This is sort of like a buffer for completions. It does not return the real completions, but it's for example used in ObjectivesAdminCommand handleCompletions() which is called by the real Tab Completer CommandNotQuestsAdmin to split it up a little.
    • standardPlayerCompletions

      public final List<String> standardPlayerCompletions
      ArrayList for Command Tab Completions for players. They will be re-used where possible.
    • standardEntityTypeCompletions

      public final List<String> standardEntityTypeCompletions
      ArrayList for Command Tab Completions for entity types. They will be initialized on startup be re-used where possible.
    • numberCompletions

      public final List<String> numberCompletions
      ArrayList for Command Tab Completions for numbers from -1 to 12. They will be initialized on startup be re-used where possible.
    • numberPositiveCompletions

      public final List<String> numberPositiveCompletions
      ArrayList for Command Tab Completions for numbers from 1 to 12. They will be initialized on startup be re-used where possible.
    • partialCompletions

      public final List<String> partialCompletions
      ArrayList for Command Tab Completions. They will be re-used where possible.
    • standardEliteMobNamesCompletions

      public final List<String> standardEliteMobNamesCompletions
      ArrayList for Command Tab Completions for elitemob entity types. They will be initialized on startup if the elitemobs integration is enabled and will be re-used where possible.
  • Constructor Details

    • DataManager

      public DataManager(NotQuests main)
      The Data Manager is initialized here. This mainly creates some Array List for generic Tab Completions for various commands.

      The actual loading of Data doesn't happen here yet.

      Parameters:
      main - an instance of NotQuests which will be passed over
  • Method Details

    • prepareDataFolder

      public void prepareDataFolder()
    • loadQuestsConfig

      public final void loadQuestsConfig()
    • loadGeneralConfig

      public final void loadGeneralConfig()
      The general.yml configuration file is initialized here. This will create the general.yml config file if it hasn't been created yet. It will also create all the necessary default config values if they are non-existent.

      This will also load the value from the general.yml config file, like the MySQL Database connection information. If that data is not found, the plugin will stop and throw a warning, since it cannot function without a MySQL database.

    • updateAndReadGeneralConfig

      public void updateAndReadGeneralConfig()
    • saveGeneralConfig

      public void saveGeneralConfig()
      This will try to save the general.yml configuration file with the data which is currently in the generalConfig FileConfiguration object.
    • saveQuestsConfig

      public void saveQuestsConfig()
    • disablePluginAndSaving

      public void disablePluginAndSaving(String reason)
      This will set saving to false, so the plugin will not try to save any kind of data anymore. After that, it disables the plugin.
      Parameters:
      reason - the reason for disabling saving and the plugin. Will be shown in the console error message
    • disablePluginAndSaving

      public void disablePluginAndSaving(String reason, Object... objects)
    • saveData

      public void saveData()
      If saving is enabled, this will try to save the following data: (1) Player Data into the MySQL Database (2) The quests.yml Quest Configuration file

      This will not save the general.yml Configuration file

    • refreshDatabaseConnection

      public void refreshDatabaseConnection(boolean newTask)
      If the plugin has been running for some time, the MySQL Database connection is sometimes interrupted which causes errors when it tries to save data once the plugin is disabled.

      This is especially bad, because if the plugin has been running for a while, that data will be lost.

      This method will try to re-open the database connection statement, so data can be saved to the database safely again.

      Parameters:
      newTask - sets if the plugin should force an asynchronous thread to re-open the database connection. If set to false, it will do it in whatever thread this method is run in.
    • reloadData

      public void reloadData()
      This will LOAD the following data: (1) general.yml General Configuration - in whatever Thread (2) CREATE all the necessary MySQL Database tables if they don't exist yet - in an asynchronous Thread (forced) (3) Load all the Quests Data from the quests.yml - in an asynchronous Thread (forced) (4) AFTER THAT load the Player Data from the MySQL Database - in an asynchronous Thread (forced) (5) Then it will try to load the Data from Citizens NPCs
    • isCurrentlyLoading

      public boolean isCurrentlyLoading()
    • getQuestsConfig

      public final org.bukkit.configuration.file.FileConfiguration getQuestsConfig()
      This will return the quests.yml Configuration FileConfiguration object. If it does not exist, it will try to load ALL the data again in reloadData() which should also create the quests.yml file
      Returns:
      the quests.yml Configuration FileConfiguration object
    • getGeneralConfig

      public final org.bukkit.configuration.file.FileConfiguration getGeneralConfig()
      This will return the general.yml Configuration FileConfiguration object. If it does not exist, it will try to load / create it.
      Returns:
      the general.yml Configuration FileConfiguration object
    • openConnection

      public void openConnection()
      This will open a MySQL connection statement which is needed to save and load to the MySQL Database.

      This is where it tries to log-in to the Database.

    • getDatabaseStatement

      public final Statement getDatabaseStatement()
      This returns the MySQL Database Statement, with which Database operations can be performed / executed.
      Returns:
      the MySQL Database Statement
    • isSavingEnabled

      public final boolean isSavingEnabled()
      Returns:
      if the plugin will try to save data once it's disabled. This should be true unless a severe error occurred during data loading
    • setSavingEnabled

      public void setSavingEnabled(boolean savingEnabled)
      Parameters:
      savingEnabled - sets if data saving should be enabled or disabled
    • isLoadingEnabled

      public final boolean isLoadingEnabled()
      Returns:
      if the plugin will try to load data. This should be true unless a severe error occurred during data loading
    • setLoadingEnabled

      public void setLoadingEnabled(boolean loadingEnabled)
      Parameters:
      loadingEnabled - sets if data loading should be enabled or disabled
    • loadNPCData

      public void loadNPCData()
      This will load the Data from Citizens NPCs asynchronously. It will also make sure that the quests.yml configuration object is valid first.

      The actual loading of Citizens NPC data will happen in the loadNPCData() function of the Quest Manager. In that function, most of that will run synchronously as that's required for some operations with the Citizens API.

    • isAlreadyLoadedNPCs

      public boolean isAlreadyLoadedNPCs()
      Returns:
      if Citizen NPCs have been already successfully loaded by the plugin
    • isAlreadyLoadedGeneral

      public boolean isAlreadyLoadedGeneral()
    • isAlreadyLoadedQuests

      public boolean isAlreadyLoadedQuests()
    • setAlreadyLoadedNPCs

      public void setAlreadyLoadedNPCs(boolean alreadyLoadedNPCs)
      Parameters:
      alreadyLoadedNPCs - sets if Citizen NPCs have been already successfully loaded by the plugin
    • setAlreadyLoadedGeneral

      public void setAlreadyLoadedGeneral(boolean alreadyLoadedGeneral)
    • setAlreadyLoadedQuests

      public void setAlreadyLoadedQuests(boolean alreadyLoadedQuests)
    • getConfiguration

      public final Configuration getConfiguration()
      Returns:
      the configuration object which contains values from the General.yml
    • loadYAMLConfiguration

      public final org.bukkit.configuration.file.YamlConfiguration loadYAMLConfiguration(File file) throws IOException, org.bukkit.configuration.InvalidConfigurationException
      (Taken from API, but this method also throws errors) Creates a new YamlConfiguration, loading from the given file.

      Any errors loading the Configuration will be logged and then ignored. If the specified input is not a valid config, a blank config will be returned.

      The encoding used may follow the system dependent default.

      Parameters:
      file - Input file
      Returns:
      Resulting configuration
      Throws:
      IllegalArgumentException - Thrown if file is null
      IOException
      org.bukkit.configuration.InvalidConfigurationException
    • getItemStackCache

      public HashMap<Integer,org.bukkit.inventory.ItemStack> getItemStackCache()
    • loadStandardCompletions

      public void loadStandardCompletions()
      Load values of the standard tab-completion lists. This is done in a separate method, because some lists are dependent on the integrations being loaded first.