Custom Configs

Discussion in 'Plugin Development' started by baugh70, Aug 27, 2014.

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

    baugh70

    After trying to make separate configs I made this in my main class to create custom configs:

    Code:java
    1.  
    2. package us.legioncraft.tokens;
    3.  
    4. import java.io.File;
    5. import java.io.IOException;
    6. import java.io.InputStreamReader;
    7. import java.io.Reader;
    8. import java.io.UnsupportedEncodingException;
    9. import java.util.UUID;
    10. import java.util.logging.Level;
    11.  
    12. import org.bukkit.configuration.file.FileConfiguration;
    13. import org.bukkit.configuration.file.YamlConfiguration;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. /**
    17.  *
    18.  * @author TheMindWreck
    19.  * @version 1.0
    20.  *
    21.  */
    22.  
    23. public class TokensAPI extends JavaPlugin{
    24. private FileConfiguration customConfig = null;
    25. private File customConfigFile = null;
    26.  
    27. /**
    28. * Standard plugin startup method
    29. * Loads config. Do not touch. Do it in your own code by using the plugin variable.
    30. */
    31. public void onEnable(){
    32. new Token(this);
    33. new TokenPlayer(this);
    34. }
    35.  
    36. public void reloadCustomConfig(UUID uuid) {
    37. if (customConfigFile == null) {
    38. customConfigFile = new File(getDataFolder(), uuid.toString() + ".yml");
    39. }
    40. customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    41.  
    42. // Look for defaults in the jar
    43. Reader defConfigStream;
    44. try {
    45. defConfigStream = new InputStreamReader(this.getResource(uuid.toString() + ".yml"), "UTF8");
    46. if (defConfigStream != null) {
    47. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    48. customConfig.setDefaults(defConfig);
    49. }
    50. e.printStackTrace();
    51. }
    52. }
    53.  
    54. public FileConfiguration getCustomConfig(UUID uuid) {
    55. if (customConfig == null) {
    56. reloadCustomConfig(uuid);
    57. }
    58. return customConfig;
    59. }
    60.  
    61. public void saveCustomConfig(UUID uuid) {
    62. if (customConfig == null || customConfigFile == null) {
    63. return;
    64. }
    65. try {
    66. getCustomConfig(uuid).save(customConfigFile);
    67. } catch (IOException ex) {
    68. getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
    69. }
    70. }
    71.  
    72. public void saveDefaultConfig(UUID uuid) {
    73. if (customConfigFile == null) {
    74. customConfigFile = new File(getDataFolder(), uuid.toString() + ".yml");
    75. }
    76. if (!customConfigFile.exists()) {
    77. saveResource(uuid.toString() + ".yml", false);
    78. }
    79. }
    80.  
    81. }
    82.  


    But there is something with line 44 or the line:

    Code:java
    1. defConfigStream = new InputStreamReader(this.getResource(uuid.toString() + ".yml"), "UTF8");


    The error in the plugin was this : http://pastebin.com/RPKS9Lwf

    If anyone can help me that would be great that would be fantastic.

    Thanks in advanced,
    Baugh70
     
  2. Offline

    Tecno_Wizard

    baugh70, The only thing I can think of is that the UUID is null, but not sure why.
     
  3. Offline

    Gerov

    baugh70 Spigot is an unsupported server mod.
     
  4. Offline

    JaguarJo Retired Staff

    Locked. These forums only support CraftBukkit servers. For help with other software such as Spigot, please contact the makers of that software.
     
Thread Status:
Not open for further replies.

Share This Page