getDefaultSection null after reload

Discussion in 'Spigot Plugin Development' started by TheCreeperCow, Oct 10, 2018 at 2:41 PM.

  1. Hi. So i have a problem my getDefaultSection() returns null after doing the reloadConfig() method is there a way to fix this?
     
  2. Can you post your code....
     
  3. Reload method
    Code (Java):
        public void reload() {
            String langMode = getConfig().getString("System.Language Mode");
            this.locale = Locale.getLocale(getConfig().getString("System.Language Mode", langMode));
            this.locale.reloadMessages();
            this.spawnerFile.createNewFile("Loading Spawners File", "EpicSpawners Spawners File");
            this.hooksFile.createNewFile("Loading hookHandler File", "EpicSpawners Spawners File");
            this.references = new References();
            this.blacklistHandler.reload();
            this.loadSpawnersFromFile();
            this.reloadConfig();
        }
    OpenSettings method
    Code (Java):
        public void openSettingsManager(Player player) {
            Inventory inventory = Bukkit.createInventory(null, 27, pluginName + " Settings Manager");
            ItemStack glass = Methods.getGlass();
            for (int i = 0; i < inventory.getSize(); i++) {
                inventory.setItem(i, glass);
            }

            int slot = 10;
            for (String key : instance.getConfig().getDefaultSection().getKeys(false)) {
                ItemStack item = new ItemStack(Material.WHITE_WOOL, 1, (byte) (slot - 9)); //ToDo: Make this function as it was meant to.
                ItemMeta meta = item.getItemMeta();
                meta.setLore(Collections.singletonList(TextComponent.formatText("&6Click To Edit This Category.")));
                meta.setDisplayName(TextComponent.formatText("&f&l" + key));
                item.setItemMeta(meta);
                inventory.setItem(slot, item);
                slot++;
            }

            player.openInventory(inventory);
        }
     
    This one is the one that gives the null error after the reload method has been invoked
     
  4. Have to cheaked to see if instance is null ?
    In your for loop
     
  5. The console throw a bug?

    You can use this code:
    Code (Java):
    for (String key : instance.getConfig().getConfigurationSection().getKeys(false)) {
      //code
    }
     

Share This Page