Solved Custom configs not working???

Discussion in 'Plugin Development' started by Bammerbom, Jul 16, 2013.

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

    Bammerbom

    Error:
    - NullPointerException
    - FileConfig.java:112
    FileConfig.java:112 =
    Code:java
    1. if (!plugin.getDataFolder().exists()) {

    Full code:
    Note: It handle the command by other classes but i don't post this because you don't need it.
    loader.class: (Main class)
    Code:java
    1. package me.bammerbom.core;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. import org.fusesource.jansi.Ansi;
    9.  
    10. public class Loader extends JavaPlugin {
    11.  
    12. // MAIN DINGEN
    13. public static Loader plugin;
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15.  
    16. // PLUGIN ENABLE
    17. public void onEnable() {
    18. FileConfig.Enable();
    19. FileConfig.loadConfig();
    20. boolean succes = true;
    21. plugin = this;
    22. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    23. + "> "
    24. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    25. + "Loading core..." + Ansi.ansi().reset());
    26. if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
    27. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    28. .toString()
    29. + "> "
    30. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    31. .toString()
    32. + "ProtocolLib found!"
    33. + Ansi.ansi().reset());
    34. } else {
    35. succes = true;
    36. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    37. .toString()
    38. + "> "
    39. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    40. + "ProtocolLib not found"
    41. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    42. + " > "
    43. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    44. .toString()
    45. + "Loading without support"
    46. + Ansi.ansi().reset());
    47. }
    48. // OBSTRUCTING PLUGINS
    49. if (getServer().getPluginManager().getPlugin("") != null) {
    50. succes = false;
    51. }
    52.  
    53. // Folder
    54.  
    55. // END
    56. if (succes == true) {
    57. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    58. .toString()
    59. + "> "
    60. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold()
    61. .toString()
    62. + "Loaded succesfull!"
    63. + Ansi.ansi().reset());
    64. } else {
    65. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    66. .toString()
    67. + "> "
    68. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    69. + "Loading failed!" + Ansi.ansi().reset());
    70. }
    71. }
    72.  
    73. // PLUGIN DISABLE
    74. public void onDisable() {
    75. //FileConfig.saveConfig();
    76. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    77. + "> "
    78. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    79. + "Unloaded core!" + Ansi.ansi().reset());
    80. }
    81.  
    82. // COMMAND HANDLER
    83. @Override
    84. public boolean onCommand(CommandSender sender, Command cmd, String label,
    85. String[] args) {
    86. if (cmd.getName().equalsIgnoreCase("a")
    87. || cmd.getName().equalsIgnoreCase("admin")) {
    88. me.bammerbom.core.CommandHandler.handle(sender, cmd, label, args);
    89. }
    90. return true;
    91. }
    92.  
    93. }

    FileConfig.java: (Class with error)
    Code:Java
    1. package me.bammerbom.core;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.configuration.file.YamlConfiguration;
    9. import org.bukkit.entity.Player;
    10. import org.fusesource.jansi.Ansi;
    11.  
    12. public class FileConfig {
    13.  
    14. static Loader plugin;
    15. public FileConfig(Loader instance){
    16. plugin = instance;
    17. }
    18.  
    19. static FileConfiguration config;
    20. static File cfile;
    21.  
    22. static FileConfiguration data;
    23. static File dfile;
    24.  
    25. static FileConfiguration CUSTOM;
    26. static File C_file;
    27.  
    28. static FileConfiguration NL;
    29. static File NL_file;
    30.  
    31. static FileConfiguration EN;
    32. static File EN_file;
    33.  
    34. public static void Message(Player pl, String Name, String type) {
    35. cfile = new File(me.bammerbom.core.Loader.plugin.getDataFolder(), "config.yml");
    36. C_file = new File(me.bammerbom.core.Loader.plugin.getDataFolder() + File.separator + "Messages", "CUSTOM.yml");
    37. NL_file = new File(me.bammerbom.core.Loader.plugin.getDataFolder() + File.separator + "Messages", "NL.yml");
    38. EN_file = new File(me.bammerbom.core.Loader.plugin.getDataFolder() + File.separator + "Messages", "EN.yml");
    39.  
    40. Player p = (Player) pl;
    41. String message = null;
    42. String typeh = null;
    43. if(config.getString("Language").equalsIgnoreCase("NL")){
    44. message = NL.getString(Name);
    45. }
    46. else if(config.getString("Language").equalsIgnoreCase("EN")){
    47. message = NL.getString(Name);
    48. }
    49. else if(config.getString("Language").equalsIgnoreCase("CUSTOM")){
    50. message = NL.getString(Name);
    51. }
    52. else{
    53. p.sendMessage(ChatColor.RED + "> " + ChatColor.GOLD + "Config error: Language is not: " + ChatColor.YELLOW + "\"NL, EN, CUSTOM\"");
    54. }
    55. if(type.equalsIgnoreCase("Error")){
    56. typeh = ChatColor.RED + "> ";
    57. }else if(type.equalsIgnoreCase("Private")){
    58. typeh = ChatColor.GOLD + "> ";
    59. }else if(type.equalsIgnoreCase("Public")){
    60. typeh = ChatColor.DARK_PURPLE + "> ";
    61. }else if(type.equalsIgnoreCase("Chat")){
    62. typeh = ChatColor.DARK_BLUE + "> ";
    63. }else{
    64. p.sendMessage("Error in plugin. Please contact the owner!");
    65. }
    66. p.sendMessage(typeh + message);
    67. }
    68.  
    69. public static void saveConfig(){
    70. try {
    71. config.save(cfile);
    72. data.save(dfile);
    73. CUSTOM.save(C_file);
    74. NL.save(NL_file);
    75. EN.save(EN_file);
    76. } catch (IOException e) {
    77. e.printStackTrace();
    78. }
    79. }
    80. public static void loadConfig(){
    81. try {
    82. config.load(cfile);
    83. data.load(dfile);
    84. CUSTOM.load(C_file);
    85. NL.load(NL_file);
    86. EN.load(EN_file);
    87. } catch (Exception e) {
    88. e.printStackTrace();
    89. }
    90. }
    91.  
    92.  
    93.  
    94.  
    95.  
    96.  
    97.  
    98.  
    99.  
    100.  
    101.  
    102.  
    103. public static void Enable(){
    104. //Config
    105. config = new YamlConfiguration();
    106. data = new YamlConfiguration();
    107. CUSTOM = new YamlConfiguration();
    108. NL = new YamlConfiguration();
    109. EN = new YamlConfiguration();
    110.  
    111. //File creation
    112. if (!plugin.getDataFolder().exists()) {
    113. plugin.getDataFolder().mkdir();
    114. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    115. .toString()
    116. + "> "
    117. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold().toString()
    118. + "Created"
    119. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    120. + " > "
    121. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold().toString()
    122. + "Folder"
    123. + Ansi.ansi().reset());
    124. } else {
    125. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    126. .toString()
    127. + "> "
    128. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    129. .toString()
    130. + "Loaded"
    131. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    132. + " > "
    133. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    134. .toString() + "Folder" + Ansi.ansi().reset());
    135. }
    136. if (!cfile.exists()) {
    137. plugin.saveResource("config.yml", true);
    138. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    139. .toString()
    140. + "> "
    141. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    142. .toString()
    143. + "Created"
    144. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    145. + " > "
    146. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    147. .toString() + "config.yml" + Ansi.ansi().reset());
    148. } else {
    149. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    150. .toString()
    151. + "> "
    152. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    153. .toString()
    154. + "Loaded"
    155. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    156. + " > "
    157. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    158. .toString() + "config.yml" + Ansi.ansi().reset());
    159. }
    160. if (!dfile.exists()) {
    161. plugin.saveResource("data.yml", true);
    162. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    163. .toString()
    164. + "> "
    165. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    166. .toString()
    167. + "Created"
    168. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    169. + " > "
    170. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    171. .toString() + "data.yml" + Ansi.ansi().reset());
    172. } else {
    173. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    174. .toString()
    175. + "> "
    176. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    177. .toString()
    178. + "Loaded"
    179. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    180. + " > "
    181. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    182. .toString() + "data.yml" + Ansi.ansi().reset());
    183. }
    184. if (!NL_file.exists()) {
    185. plugin.saveResource("Messages" + File.separator + "NL.yml", true);
    186. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    187. .toString()
    188. + "> "
    189. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    190. .toString()
    191. + "Created"
    192. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    193. + " > "
    194. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    195. .toString()
    196. + "Messages/NL.yml"
    197. + Ansi.ansi().reset());
    198. } else {
    199. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    200. .toString()
    201. + "> "
    202. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    203. .toString()
    204. + "Loaded"
    205. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    206. + " > "
    207. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    208. .toString()
    209. + "Messages/NL.yml"
    210. + Ansi.ansi().reset());
    211. }
    212. if (!EN_file.exists()) {
    213. plugin.saveResource("Messages" + File.separator + "EN.yml", true);
    214. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    215. .toString()
    216. + "> "
    217. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    218. .toString()
    219. + "Created"
    220. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    221. + " > "
    222. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    223. .toString()
    224. + "Messages/EN.yml"
    225. + Ansi.ansi().reset());
    226. } else {
    227. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    228. .toString()
    229. + "> "
    230. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    231. .toString()
    232. + "Loaded"
    233. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    234. + " > "
    235. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    236. .toString()
    237. + "Messages/EN.yml"
    238. + Ansi.ansi().reset());
    239. }
    240. if (!C_file.exists()) {
    241. plugin.saveResource("Messages" + File.separator + "CUSTOM.yml", true);
    242. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    243. .toString()
    244. + "> "
    245. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    246. .toString()
    247. + "Created"
    248. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    249. + " > "
    250. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    251. .toString()
    252. + "Messages/CUSTOM.yml"
    253. + Ansi.ansi().reset());
    254. } else {
    255. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    256. .toString()
    257. + "> "
    258. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    259. .toString()
    260. + "Loaded"
    261. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    262. + " > "
    263. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    264. .toString()
    265. + "Messages/CUSTOM.yml"
    266. + Ansi.ansi().reset());
    267. }
    268. }
    269.  
    270. }

    Need more things???
    Post a command.
    Thanks for help me.

    Ps. If you want to remake this part for me:
    It need to do:
    - Get messages file: plugins/<pluginname>/messages/NL.yml
    - Get messages file: plugins/<pluginname>/messages/EN.yml
    - Get messages file: plugins/<pluginname>/messages/CUSTOM.yml
    - If one of this files not exist make: Data Folder. Config.yml Messages.yml Messages/NL.yml Messages/EN.yml Messages/CUSTOM.yml
    - Save / Reload this files
     
  2. Offline

    adam753

    I notice FileConfig's plugin variable is static, as well as the method where the error is happening. That means it's possible you're calling Enable() before setting the plugin variable, which would cause the error. Is that the problem?
     
  3. Offline

    Bammerbom

    adam753 Nope.

    bump

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

    seemethere


    Jhtzb That's exactly what's happening. Your FileConfig class never has the plugin variable set.

    It's pretty clear why it's not working when you look at the first 2 lines of your onEnable()
    Code:java
    1. // PLUGIN ENABLE
    2. public void onEnable() {
    3. FileConfig.Enable();
    4. FileConfig.loadConfig();


    My suggestion is to not use static methods for this kind of class. It's not really necessary to do it like that in the first place.

    Here's how it should look:

    Code:java
    1. public FileConfig fileConfig;
    2. public void onEnable() {
    3. fileConfig = new FileConfig(this);
    4. fileConfig.Enable();
    5. fileConfig.loadConfig();
     
  5. Offline

    PatoTheBest

    Config class (or whatever name)
    Code:java
    1. //from mrmag518 LogStream (used it because I needed to make my config static)
    2.  
    3. package yourpackage;
    4.  
    5. import java.io.File;
    6. import java.io.IOException;
    7. import java.util.logging.Level;
    8. import java.util.logging.Logger;
    9.  
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.configuration.file.YamlConfiguration;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14.  
    15. publicclass Config {
    16. private FileConfiguration config = null;
    17. private File configFile = null;
    18.  
    19.  
    20. public void load() {
    21. config = getConfig();
    22.  
    23. config.options().header("Header");
    24.  
    25. config.addDefault("String", true);
    26. getConfig().options().copyDefaults(true);
    27. save();
    28. }
    29.  
    30. public void reload() {
    31. if (configFile == null) {
    32. configFile = new File("plugins/(yourplugin)/custom.yml");
    33. }
    34. config = YamlConfiguration.loadConfiguration(configFile);
    35. }
    36.  
    37. public FileConfiguration getConfig() {
    38. if (config == null) {
    39. reload();
    40. }
    41. return config;
    42. }
    43.  
    44. public void save() {
    45. if (config == null || configFile == null) {
    46. return;
    47. }
    48. try {
    49. config.save(configFile);
    50. } catch (IOException ex) {
    51. Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save configFile to " + configFile, ex);
    52. }
    53. }
    54.  


    on Main Class:

    Code:java
    1.  
    2. public void onEnable(){
    3. loadConfig();
    4. }
    5. protected void loadConfig() {
    6. if(!getDataFolder().exists()) {
    7. getDataFolder().mkdir();
    8. }
    9.  
    10. Config.reload();
    11. Config.load();
    12. Config.reload();
    13. }
    14.  
     
  6. Offline

    Bammerbom

  7. Offline

    seemethere

    Jhtzb Does it give you the same error?
     
  8. Offline

    Bammerbom

  9. Offline

    seemethere

    Jhtzb Post your updated main class?
     
  10. Offline

    Bammerbom

    PatoTheBest Testing...
    seemethere Yes

    seemethere
    Code:java
    1. package me.bammerbom.core;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. import org.fusesource.jansi.Ansi;
    9.  
    10. public class Loader extends JavaPlugin {
    11.  
    12. // MAIN DINGEN
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. // PLUGIN ENABLE
    16. public FileConfig fileConfig;
    17. public void onEnable() {
    18. FileConfig.Enable();
    19. boolean succes = true;
    20.  
    21. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    22. + "> "
    23. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    24. + "Loading core..." + Ansi.ansi().reset());
    25. if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
    26. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    27. .toString()
    28. + "> "
    29. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    30. .toString()
    31. + "ProtocolLib found!"
    32. + Ansi.ansi().reset());
    33. } else {
    34. succes = true;
    35. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    36. .toString()
    37. + "> "
    38. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    39. + "ProtocolLib not found"
    40. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    41. + " > "
    42. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    43. .toString()
    44. + "Loading without support"
    45. + Ansi.ansi().reset());
    46. }
    47. // OBSTRUCTING PLUGINS
    48. if (getServer().getPluginManager().getPlugin("") != null) {
    49. succes = false;
    50. }
    51.  
    52. // Folder
    53.  
    54. // END
    55. if (succes == true) {
    56. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    57. .toString()
    58. + "> "
    59. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold()
    60. .toString()
    61. + "Loaded succesfull!"
    62. + Ansi.ansi().reset());
    63. } else {
    64. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    65. .toString()
    66. + "> "
    67. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    68. + "Loading failed!" + Ansi.ansi().reset());
    69. }
    70. }
    71.  
    72. // PLUGIN DISABLE
    73. public void onDisable() {
    74. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    75. + "> "
    76. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    77. + "Unloaded core!" + Ansi.ansi().reset());
    78. }
    79.  
    80. // COMMAND HANDLER
    81. @Override
    82. public boolean onCommand(CommandSender sender, Command cmd, String label,
    83. String[] args) {
    84. if (cmd.getName().equalsIgnoreCase("a")
    85. || cmd.getName().equalsIgnoreCase("admin")) {
    86. me.bammerbom.core.CommandHandler.handle(sender, cmd, label, args);
    87. }
    88. return true;
    89. }
    90.  
    91.  
    92. }


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

    seemethere

    Jhtzb You didn't actually do what I recommended:

    Code:java
    1. public FileConfig fileConfig;
    2. public void onEnable() {
    3. /////////////////////////////////////////////////////////////
    4. fileConfig = new FileConfig(this); //MOST IMPORTANT LINE
    5. ////////////////////////////////////////////////////////////
    6. fileConfig.Enable();
    7. fileConfig.loadConfig();
     
  12. Offline

    Bammerbom

    seemethere I have now another error.
    -NullPointerException
    -FileConfig.java:122 = if (!cfile.exists()) {
    -The File (cfile) is not created.

    Codes:
    Loader.java (main class):
    Code:java
    1. package me.bammerbom.core;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8. import org.fusesource.jansi.Ansi;
    9.  
    10. public class Loader extends JavaPlugin {
    11.  
    12. // MAIN DINGEN
    13. public final Logger logger = Logger.getLogger("Minecraft");
    14.  
    15. // PLUGIN ENABLE
    16. public FileConfig fileConfig;
    17. public void onEnable() {
    18.  
    19. fileConfig = new FileConfig(this); //THESE
    20. FileConfig.Enable(); //ARE
    21. FileConfig.loadConfig();
    22.  
    23. boolean succes = true;
    24.  
    25. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    26. + "> "
    27. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    28. + "Loading core..." + Ansi.ansi().reset());
    29. if (getServer().getPluginManager().getPlugin("ProtocolLib") != null) {
    30. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    31. .toString()
    32. + "> "
    33. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    34. .toString()
    35. + "ProtocolLib found!"
    36. + Ansi.ansi().reset());
    37. } else {
    38. succes = true;
    39. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    40. .toString()
    41. + "> "
    42. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    43. + "ProtocolLib not found"
    44. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    45. + " > "
    46. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    47. .toString()
    48. + "Loading without support"
    49. + Ansi.ansi().reset());
    50. }
    51. // OBSTRUCTING PLUGINS
    52. if (getServer().getPluginManager().getPlugin("") != null) {
    53. succes = false;
    54. }
    55.  
    56. // Folder
    57.  
    58. // END
    59. if (succes == true) {
    60. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    61. .toString()
    62. + "> "
    63. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold()
    64. .toString()
    65. + "Loaded succesfull!"
    66. + Ansi.ansi().reset());
    67. } else {
    68. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    69. .toString()
    70. + "> "
    71. + Ansi.ansi().reset().fg(Ansi.Color.RED).bold().toString()
    72. + "Loading failed!" + Ansi.ansi().reset());
    73. }
    74. }
    75.  
    76. // PLUGIN DISABLE
    77. public void onDisable() {
    78. logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    79. + "> "
    80. + Ansi.ansi().reset().fg(Ansi.Color.GREEN).bold().toString()
    81. + "Unloaded core!" + Ansi.ansi().reset());
    82. }
    83.  
    84. // COMMAND HANDLER
    85. @Override
    86. public boolean onCommand(CommandSender sender, Command cmd, String label,
    87. String[] args) {
    88. if (cmd.getName().equalsIgnoreCase("a")
    89. || cmd.getName().equalsIgnoreCase("admin")) {
    90. me.bammerbom.core.CommandHandler.handle(sender, cmd, label, args);
    91. }
    92. return true;
    93. }
    94.  
    95.  
    96. }

    FileConfig.java (class with error):
    Code:java
    1. package me.bammerbom.core;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.configuration.file.YamlConfiguration;
    9. import org.bukkit.entity.Player;
    10. import org.fusesource.jansi.Ansi;
    11.  
    12. public class FileConfig {
    13.  
    14. static Loader plugin;
    15. public FileConfig(Loader instance){
    16. plugin = instance;
    17. }
    18.  
    19. static FileConfiguration config;
    20. static FileConfiguration data;
    21. static FileConfiguration CUSTOM;
    22. static FileConfiguration NL;
    23. static FileConfiguration EN;
    24.  
    25. static File cfile;
    26. static File dfile;
    27. static File C_file;
    28. static File NL_file;
    29. static File EN_file;
    30.  
    31. public static void Message(Player pl, String Name, String type) {
    32. cfile = new File(plugin.getDataFolder(), "config.yml");
    33. C_file = new File(plugin.getDataFolder() + File.separator + "Messages", "CUSTOM.yml");
    34. NL_file = new File(plugin.getDataFolder() + File.separator + "Messages", "NL.yml");
    35. EN_file = new File(plugin.getDataFolder() + File.separator + "Messages", "EN.yml");
    36.  
    37. Player p = (Player) pl;
    38. String message = null;
    39. String typeh = null;
    40. if(config.getString("Language").equalsIgnoreCase("NL")){
    41. message = NL.getString(Name);
    42. }
    43. else if(config.getString("Language").equalsIgnoreCase("EN")){
    44. message = NL.getString(Name);
    45. }
    46. else if(config.getString("Language").equalsIgnoreCase("CUSTOM")){
    47. message = NL.getString(Name);
    48. }
    49. else{
    50. p.sendMessage(ChatColor.RED + "> " + ChatColor.GOLD + "Config error: Language is not: " + ChatColor.YELLOW + "\"NL, EN, CUSTOM\"");
    51. }
    52. if(type.equalsIgnoreCase("Error")){
    53. typeh = ChatColor.RED + "> ";
    54. }else if(type.equalsIgnoreCase("Private")){
    55. typeh = ChatColor.GOLD + "> ";
    56. }else if(type.equalsIgnoreCase("Public")){
    57. typeh = ChatColor.DARK_PURPLE + "> ";
    58. }else if(type.equalsIgnoreCase("Chat")){
    59. typeh = ChatColor.DARK_BLUE + "> ";
    60. }else{
    61. p.sendMessage("Error in plugin. Please contact the owner!");
    62. }
    63. p.sendMessage(typeh + message);
    64. }
    65.  
    66. public static void saveConfig(){
    67. try {
    68. config.save(cfile);
    69. data.save(dfile);
    70. CUSTOM.save(C_file);
    71. NL.save(NL_file);
    72. EN.save(EN_file);
    73. } catch (IOException e) {
    74. e.printStackTrace();
    75. }
    76. }
    77. public static void loadConfig(){
    78. try {
    79. config.load(cfile);
    80. data.load(dfile);
    81. CUSTOM.load(C_file);
    82. NL.load(NL_file);
    83. EN.load(EN_file);
    84. } catch (Exception e) {
    85. e.printStackTrace();
    86. }
    87. }
    88.  
    89. public static void Enable(){
    90. //Config
    91. config = new YamlConfiguration();
    92. data = new YamlConfiguration();
    93. CUSTOM = new YamlConfiguration();
    94. NL = new YamlConfiguration();
    95. EN = new YamlConfiguration();
    96.  
    97. //File creation
    98. if (plugin.getDataFolder().exists()) {
    99. plugin.getDataFolder().mkdir();
    100. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    101. .toString()
    102. + "> "
    103. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold().toString()
    104. + "Created"
    105. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    106. + " > "
    107. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold().toString()
    108. + "Folder"
    109. + Ansi.ansi().reset());
    110. } else {
    111. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    112. .toString()
    113. + "> "
    114. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    115. .toString()
    116. + "Loaded"
    117. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    118. + " > "
    119. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    120. .toString() + "Folder" + Ansi.ansi().reset());
    121. }
    122. if (!cfile.exists()) {
    123. plugin.saveResource("config.yml", true);
    124. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    125. .toString()
    126. + "> "
    127. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    128. .toString()
    129. + "Created"
    130. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    131. + " > "
    132. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    133. .toString() + "config.yml" + Ansi.ansi().reset());
    134. } else {
    135. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    136. .toString()
    137. + "> "
    138. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    139. .toString()
    140. + "Loaded"
    141. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    142. + " > "
    143. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    144. .toString() + "config.yml" + Ansi.ansi().reset());
    145. }
    146. if (!dfile.exists()) {
    147. plugin.saveResource("data.yml", true);
    148. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    149. .toString()
    150. + "> "
    151. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    152. .toString()
    153. + "Created"
    154. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    155. + " > "
    156. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    157. .toString() + "data.yml" + Ansi.ansi().reset());
    158. } else {
    159. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    160. .toString()
    161. + "> "
    162. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    163. .toString()
    164. + "Loaded"
    165. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    166. + " > "
    167. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    168. .toString() + "data.yml" + Ansi.ansi().reset());
    169. }
    170. if (!NL_file.exists()) {
    171. plugin.saveResource("Messages" + File.separator + "NL.yml", true);
    172. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    173. .toString()
    174. + "> "
    175. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    176. .toString()
    177. + "Created"
    178. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    179. + " > "
    180. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    181. .toString()
    182. + "Messages/NL.yml"
    183. + Ansi.ansi().reset());
    184. } else {
    185. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    186. .toString()
    187. + "> "
    188. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    189. .toString()
    190. + "Loaded"
    191. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    192. + " > "
    193. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    194. .toString()
    195. + "Messages/NL.yml"
    196. + Ansi.ansi().reset());
    197. }
    198. if (!EN_file.exists()) {
    199. plugin.saveResource("Messages" + File.separator + "EN.yml", true);
    200. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    201. .toString()
    202. + "> "
    203. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    204. .toString()
    205. + "Created"
    206. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    207. + " > "
    208. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    209. .toString()
    210. + "Messages/EN.yml"
    211. + Ansi.ansi().reset());
    212. } else {
    213. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    214. .toString()
    215. + "> "
    216. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    217. .toString()
    218. + "Loaded"
    219. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    220. + " > "
    221. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    222. .toString()
    223. + "Messages/EN.yml"
    224. + Ansi.ansi().reset());
    225. }
    226. if (!C_file.exists()) {
    227. plugin.saveResource("Messages" + File.separator + "CUSTOM.yml", true);
    228. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    229. .toString()
    230. + "> "
    231. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    232. .toString()
    233. + "Created"
    234. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    235. + " > "
    236. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    237. .toString()
    238. + "Messages/CUSTOM.yml"
    239. + Ansi.ansi().reset());
    240. } else {
    241. plugin.logger.info(Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold()
    242. .toString()
    243. + "> "
    244. + Ansi.ansi().reset().fg(Ansi.Color.YELLOW).bold()
    245. .toString()
    246. + "Loaded"
    247. + Ansi.ansi().reset().fg(Ansi.Color.CYAN).bold().toString()
    248. + " > "
    249. + Ansi.ansi().reset().fg(Ansi.Color.DEFAULT).bold()
    250. .toString()
    251. + "Messages/CUSTOM.yml"
    252. + Ansi.ansi().reset());
    253. }
    254. }
    255.  
    256.  
    257. }


    seemethere Now I did it. Sorry.

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

    seemethere

    Jhtzb You never initiated cfile so in that instance cfile = null since you never set it to anything before.

    In fact, you only initiate your files in your Message method (line 31)

    Move lines 32-35 into your Enable method and that should clear up that problem.
     
  14. Offline

    Bammerbom

Thread Status:
Not open for further replies.

Share This Page