Solved Config Load error

Discussion in 'Plugin Development' started by FuZioN720, Mar 16, 2014.

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

    FuZioN720

    Hello, I'm having a null error when loading my config. I can't put my tongue on why there is an error. Please help.

    Error:
    Code:
    [19:02:19 INFO]: xXFuZioN360Xx issued server command: /tw g medic
    [19:02:19 WARN]: java.lang.NullPointerException
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.ConfigManager.load(ConfigM
    anager.java:33)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.classes.Medic.giveHelmet(M
    edic.java:59)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.classes.Medic.giveMedic(Me
    dic.java:39)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.cmds.Give.onCommand(Give.j
    ava:34)
    [19:02:19 WARN]:        at me.xxfuzion360xx.parthenon.CommandManager.onCommand(C
    ommandManager.java:54)
    [19:02:19 WARN]:        at org.bukkit.command.PluginCommand.execute(PluginComman
    d.java:44)
    [19:02:19 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:196)
    [19:02:19 WARN]:        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCo
    mmand(CraftServer.java:542)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.handleC
    ommand(PlayerConnection.java:932)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PlayerConnection.a(Playe
    rConnection.java:814)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(Packe
    tPlayInChat.java:28)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(
    PacketPlayInChat.java:47)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.NetworkManager.a(Network
    Manager.java:146)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.ServerConnection.c(Sourc
    eFile:134)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(Minecr
    aftServer.java:655)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(Dedica
    tedServer.java:250)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(Minecr
    aftServer.java:545)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(Mine
    craftServer.java:457)
    [19:02:19 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.
    run(SourceFile:617)
    >
    ConfigManager Class:
    Code:java
    1. package me.xxfuzion360xx.parthenon;
    2.  
    3. import java.io.File;
    4. import java.util.HashMap;
    5. import java.util.Map;
    6. import org.bukkit.configuration.file.FileConfiguration;
    7. import org.bukkit.configuration.file.YamlConfiguration;
    8. import org.bukkit.plugin.Plugin;
    9.  
    10. public class ConfigManager {
    11.  
    12. @SuppressWarnings({ "unchecked", "rawtypes" })
    13. public static Map<String, FileConfiguration> configs = new HashMap();
    14.  
    15. /**
    16.   * Checks to see if the ConfigManager knows about fileName
    17.   *
    18.   * @param fileName file to check
    19.   * @return true if file is loaded, false if not
    20.   */
    21. public static boolean isFileLoaded(String fileName) {
    22. return configs.containsKey(fileName);
    23. }
    24.  
    25. /**
    26.   * Loads a files configuration into Memory
    27.   *
    28.   * @param plugin Plugin to load file from if fileName does not exist in
    29.   * Plugins folder
    30.   * @param fileName File to load
    31.   */
    32. public static void load(Plugin plugin, String fileName) {
    33. File file = new File(plugin.getDataFolder(), fileName);//Line 33
    34. if (!file.exists()) {
    35. try {
    36. plugin.saveResource(fileName, false);
    37. } catch (Exception e) {
    38. e.printStackTrace();
    39. }
    40. }
    41. if (!isFileLoaded(fileName)) {
    42. configs.put(fileName, YamlConfiguration.loadConfiguration(file));
    43. }
    44. }
    45.  
    46. /**
    47.   * Gets the FileConfiguration for a specified file
    48.   *
    49.   * @param fileName File to load data from
    50.   * @return File Configuration
    51.   */
    52. public static FileConfiguration get(String fileName) {
    53. if (isFileLoaded(fileName)) {
    54. return configs.get(fileName);
    55. }
    56. return null;
    57. }
    58.  
    59. /**
    60.   * Updates the FileConfiguration at the given path. If path already exists
    61.   * this will return false.
    62.   *
    63.   * @param fileName File to update
    64.   * @param path Path to update
    65.   * @param value Data to set at path
    66.   * @return True if successful, otherwise false
    67.   */
    68. public static boolean update(String fileName, String path, Object value) {
    69. if (isFileLoaded(fileName)) {
    70. if (!configs.get(fileName).contains(path)) {
    71. configs.get(fileName).set(path, value);
    72. return true;
    73. }
    74. }
    75. return false;
    76. }
    77.  
    78. /**
    79.   * Sets data at any given path. If path already exists it will be over
    80.   * written.
    81.   *
    82.   * @param fileName File to update
    83.   * @param path Path to set
    84.   * @param value Data to set at path
    85.   */
    86. public static void set(String fileName, String path, Object value) {
    87. if (isFileLoaded(fileName)) {
    88. configs.get(fileName).set(path, value);
    89. }
    90. }
    91.  
    92. /**
    93.   * Create YAML Comments at the given path
    94.   *
    95.   * @param fileName File to add comments to
    96.   * @param path Path to add comments too
    97.   * @param comments Comments to add
    98.   *
    99.   * @deprecated Not Tested/Experimental
    100.   */
    101. public void addComment(String fileName, String path, String... comments) {
    102. if (isFileLoaded(fileName)) {
    103. for (String comment : comments) {
    104. if (!configs.get(fileName).contains(path)) {
    105. configs.get(fileName).set("_COMMENT_" + comments.length, " " + comment);
    106. }
    107. }
    108. }
    109. }
    110.  
    111. /**
    112.   * Removes a path from the FileConfiguration.
    113.   *
    114.   * @param fileName File to update
    115.   * @param path Path to remove
    116.   */
    117. public static void remove(String fileName, String path) {
    118. if (isFileLoaded(fileName)) {
    119. configs.get(fileName).set(path, null);
    120. }
    121. }
    122.  
    123. /**
    124.   * Checks if a file has a path.
    125.   *
    126.   * @param fileName File to check
    127.   * @param path Path to check
    128.   * @return True if path exists, otherwise false.
    129.   */
    130. public static boolean contains(String fileName, String path) {
    131. if (isFileLoaded(fileName)) {
    132. return configs.get(fileName).contains(path);
    133. }
    134. return false;
    135. }
    136.  
    137. /**
    138.   * Reload the config from the given Plugin.
    139.   *
    140.   * @param plugin Plugin to get the File from
    141.   * @param fileName File to reload
    142.   */
    143. public static void reload(Plugin plugin, String fileName) {
    144. File file = new File(plugin.getDataFolder(), fileName);
    145. if (isFileLoaded(fileName)) {
    146. try {
    147. configs.get(fileName).load(file);
    148. } catch (Exception e) {
    149. e.printStackTrace();
    150. }
    151. }
    152. }
    153.  
    154. /**
    155.   * Save the config for the given plugin
    156.   *
    157.   * @param plugin Plugin dir to save to the file to
    158.   * @param fileName File to save
    159.   */
    160. public static void save(Plugin plugin, String fileName) {
    161. File file = new File(plugin.getDataFolder(), fileName);
    162. if (isFileLoaded(fileName)) {
    163. try {
    164. configs.get(fileName).save(file);
    165. } catch (Exception e) {
    166. e.printStackTrace();
    167. }
    168. }
    169. }
    170.  
    171. /**
    172.   * Get a path from the FileConfiguration.
    173.   *
    174.   * @param fileName File to update
    175.   * @param path Path to get from
    176.   * @return
    177.   */
    178. public static Object getObject(String fileName, String path) {
    179. if (isFileLoaded(fileName)) {
    180. return configs.get(fileName).get(path);
    181. }
    182. return null;
    183. }
    184. }
     
Thread Status:
Not open for further replies.

Share This Page