[NEED HELP] Questions About Configs

Discussion in 'Plugin Development' started by BungeeTheCookie, Oct 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    BungeeTheCookie

    Hello people of Bukkit! I am trying to save the default config for something that is not the actual config, which I got from the Configuration API on BukkitWiki. Unfortunately, I am running into this error. Please help in any way possible! ANY AND ALL HELP IS APPRECIATED!!! Thanks!

    The Error:
    PHP:
    2013-10-21 17:26:49 [SEVEREError occurred while enabling PVPEssentials Commands vCookie Release 1.0 (Is it up to date?)
    java.lang.NullPointerException
        at com
    .PVPEssentials.main.config.ConfigManager.saveDefaultSpawnsConfig(ConfigManager.java:33)
        
    at com.PVPEssentials.main.config.ConfigManager.SetUpConfigs(ConfigManager.java:29)
        
    at com.PVPEssentials.main.PVPEssentialsCommands.onEnable(PVPEssentialsCommands.java:31)
        
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:282)
        
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:264)
        
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.reload(CraftServer.java:609)
        
    at org.bukkit.Bukkit.reload(Bukkit.java:277)
        
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
        
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchServerCommand(CraftServer.java:512)
        
    at net.minecraft.server.v1_6_R3.DedicatedServer.as(DedicatedServer.java:263)
        
    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:228)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    The Code: (Config Manager Class)
    Code:java
    1. package com.PVPEssentials.main.config;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.io.InputStream;
    6. import java.util.logging.Level;
    7.  
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10.  
    11. import com.PVPEssentials.main.PVPEssentialsCommands;
    12.  
    13. public class ConfigManager {
    14.  
    15. public PVPEssentialsCommands plugin;
    16.  
    17. public ConfigManager(PVPEssentialsCommands plugin) {this.plugin = plugin;}
    18. public ConfigManager() { }
    19.  
    20. static ConfigManager instance = new ConfigManager();
    21.  
    22. public static ConfigManager getInstance() {
    23. return instance;
    24. }
    25. private File spawnsFile = null;
    26. private FileConfiguration spawns = null;
    27.  
    28. public void SetUpConfigs(){
    29. saveDefaultSpawnsConfig();
    30. }
    31. public void saveDefaultSpawnsConfig() {
    32. if (spawnsFile == null) {
    33. spawnsFile = new File(plugin.getDataFolder(), "spawns.yml");
    34. }
    35. if (!spawnsFile.exists()) {
    36. plugin.saveResource("spawns.yml", false);
    37. }
    38. }
    39. public FileConfiguration getSpawnsConfig() {
    40. if (spawns == null) {
    41. reloadSpawnsConfig();
    42. }
    43. return spawns;
    44. }
    45. public void reloadSpawnsConfig() {
    46. if (spawnsFile == null) {
    47. spawnsFile = new File(plugin.getDataFolder(), "spawns.yml");
    48. }
    49. spawns = YamlConfiguration.loadConfiguration(spawnsFile);
    50.  
    51. // Look for defaults in the jar
    52. InputStream defConfigStream = plugin.getResource("spawns.yml");
    53. if (defConfigStream != null) {
    54. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    55. spawns.setDefaults(defConfig);
    56. }
    57. }
    58. public void saveSpawnsConfig() {
    59. if (spawns == null || spawnsFile == null) {
    60. return;
    61. }
    62. try {
    63. getSpawnsConfig().save(spawnsFile);
    64. } catch (IOException ex) {
    65. plugin.getLogger().log(Level.SEVERE, "ERROR: Could not save config to " + spawnsFile, ex);
    66. }
    67. }
    68. }


    Main Class:
    Code:java
    1. public static PVPEssentialsCommands plugin;
    2. public ConfigManager leconfig = ConfigManager.getInstance();
    3.  
    4. public void onEnable(){
    5.  
    6. if (getServer().getPluginManager().getPlugin("PVPEssentials") == null) {
    7. Bukkit.getServer().getLogger().severe("[PVPEssentials Commands] PVPEssentials was not found!!! Please install it from the bundle you downloaded!!!");
    8. setEnabled(false);
    9. return;
    10. }
    11. Bukkit.getServer().getLogger().info("[PVPEssentials Commands] PVPEssentials Commands has been enabled!");
    12. Bukkit.getServer().getLogger().info("[PVPEssentials Commands] Thank you for using this feature of PVPEssentials!");
    13. Bukkit.getServer().getLogger().info("[PVPEssentials Commands] This plugin adds over 30 commands!");
    14. Bukkit.getServer().getLogger().info("[PVPEssentials Commands] Have fun and enjoy!");
    15. new CommandListener(this).onCommandReciever();
    16. new PermissionListener(this).onNoPermissionUse();
    17. new EventListeners(this).RegisterListeners();
    18. this.saveDefaultConfig();
    19. leconfig.SetUpConfigs();
    20. }
    21.  


    If you know the answer to this, please help out. THANKS!!!
     
  2. Offline

    calebbfmv

    Change
    Code:
    spawnsFile = new File(getDataFolder(), "spawns.yml");
    
    to:
    Code:
    File spawnsFile = new File(getDataFolder(), "spawns.yml");
    
    and remove
    Code:
    File spawnsFile = null;
    
     
  3. Offline

    SkillSam

    BungeeTheCookie You might have forgotten to make sure the folder inside your plugins folder exists as well.

    Code:java
    1. if (!p.getDataFolder().exists()) p.getDataFolder().mkdir();
     
  4. Offline

    BungeeTheCookie

    SkillSam calebbfmv
    I tried both of your methods, and neither work.

    It is also giving me the same error btw

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    5pHiNxX

    @BungeeTheCookie:

    your problem is that the variable plugin in ConfigManager is never initialized, because only the default constructor (with no parameters) is called...
     
  6. Offline

    beastman3226

    Why would you set up your config manager part object and part singleton?
     
Thread Status:
Not open for further replies.

Share This Page