Solved Config Retrieving Issues

Discussion in 'Plugin Development' started by beastman3226, Sep 16, 2013.

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

    beastman3226

    I am having issues getting values from the config. For some reason "getConfig()" is taking throwing an "IllegalArgumentException: file cannot be null";

    Which is weird. Anyone have any idea how to fix this?

    Really need help.

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

    tommycake50

    Well, How sure are you that config.yml is an actual file?
     
  3. Offline

    beastman3226

    100%, isFile() is a beautiful method. tommycake50
    EDIT: I didn't mean to sound sound, ungrateful.
     
  4. Offline

    tommycake50

    Ok, thats odd.
    Can we see your code?
     
  5. Offline

    beastman3226

    Yes.
    Code:java
    1. package de.FlatCrafter.XRayLogger;
    2.  
    3. import java.io.File;
    4. import java.io.FileNotFoundException;
    5. import java.io.IOException;
    6. import java.util.Arrays;
    7. import java.util.HashMap;
    8. import java.util.List;
    9. import java.util.Set;
    10. import java.util.logging.Level;
    11. import java.util.logging.Logger;
    12. import net.milkbowl.vault.economy.Economy;
    13. import org.bukkit.command.CommandExecutor;
    14. import org.bukkit.configuration.InvalidConfigurationException;
    15. import org.bukkit.configuration.file.FileConfiguration;
    16. import org.bukkit.plugin.RegisteredServiceProvider;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class XRayLoggerMain extends JavaPlugin {
    20.  
    21. CommandExecutor exe = (new XLCmdExec(this));
    22. BlockBreakLoggerListener bbll = new BlockBreakLoggerListener();
    23. private Economy economy;
    24. private static HashMap<String, Object> defaults = new HashMap();
    25.  
    26. @Override
    27. public void onEnable() {
    28. getCommand("logs.check").setExecutor(exe);
    29. getCommand("logs.clear").setExecutor(exe);
    30. getCommand("me.hide").setExecutor(exe);
    31. getCommand("me.remove").setExecutor(exe);
    32. getCommand("logs.look").setExecutor(exe);
    33. getCommand("logs.hidden").setExecutor(exe);
    34. getCommand("player.hide").setExecutor(exe);
    35. getCommand("player.remove").setExecutor(exe);
    36. getServer().getPluginManager().registerEvents(bbll, this);
    37. File file = new File(getDataFolder() + "config.yml");
    38. if(!file.exists() && file.isFile() ) {
    39. System.out.println("Config file does not exist, creating...");
    40. this.reloadConfig();
    41. int sixteen = 16;
    42. int twenty = 20;
    43. int thirty_two = 32;
    44. int forty = 40;
    45. int one_twenty_eight = 128;
    46. int one_ninety_six = 196;
    47. boolean notTrue = false;
    48.  
    49. defaults.put("item-amount.diamond", sixteen);
    50. defaults.put("item-amount.gold", sixteen);
    51. defaults.put("item-amount.lapis", thirty_two);
    52. defaults.put("ban.enabled", notTrue);
    53. defaults.put("ban.ban-amount.diamond", one_twenty_eight);
    54. defaults.put("ban.ban-amount.gold", one_twenty_eight);
    55. defaults.put("ban.ban-amount.lapis", one_ninety_six);
    56. defaults.put("fine.enabled", notTrue);
    57. defaults.put("fine.fine-item-amount.diamond", twenty);
    58. defaults.put("fine.fine-item-amount.gold", twenty);
    59. defaults.put("fine.fine-item-amount.lapis", forty);
    60.  
    61. getConfig().createSection("logs");
    62. getConfig().createSection("hidden");
    63.  
    64. Set<String> keys = defaults.keySet();
    65. for(String string : keys) {
    66. getConfig().set(string, defaults.get(string));
    67. }
    68. }
    69.  
    70. saveConfig();
    71.  
    72. reloadConfig();
    73.  
    74.  
    75. if(getConfig().getBoolean("fine.enabled") && this.setupEconomy()) {
    76. this.setupEconomy();
    77. this.getLogger().info("Fining is enabled");
    78. } else {
    79. System.out.println("Vault hooked economy plugin: " + this.setupEconomy());
    80. System.out.println("Enabled in config: " + this.isFineable());
    81. }
    82. if(this.isBannable()) {
    83. System.out.println("[XRayLogger]: Banning is enabled");
    84. } else if(!this.isBannable()) {
    85. System.out.println("[XRayLogger]: Banning is disabled.");
    86. }
    87.  
    88.  
    89.  
    90. }
    91.  
    92.  
    93. @Override
    94. public void onDisable() {
    95. List<String> loggedXray;
    96. List<String> hiddenXray;
    97. String[] loggedArray = new String[bbll.loggedXray.size()];
    98. int i = 0;
    99. for(String string : bbll.loggedXray) {
    100. loggedArray[i] = string;
    101. i++;
    102. }
    103. loggedXray = Arrays.asList(loggedArray);
    104. i =0;
    105. String[] hiddenArray = new String[bbll.hideXray.size()];
    106. for (String string : bbll.hideXray) {
    107. hiddenArray[i] = string;
    108. i++;
    109. }
    110. hiddenXray = Arrays.asList(hiddenArray);
    111. getConfig().set("logs", loggedXray);
    112. getConfig().set("hidden", hiddenXray);
    113. saveConfig();
    114. }
    115.  
    116. public boolean isBannable() {
    117. return getConfig().getBoolean("ban.enabled");
    118. }
    119.  
    120. public boolean isFineable() {
    121. return getConfig().getBoolean("fine.enabled");
    122. }
    123.  
    124. public double getFine() {
    125. return getConfig().getDouble("fine.fine-amount");
    126. }
    127.  
    128. public int getDiamond() {
    129. return getConfig().getInt("item-amount.diamond");
    130. }
    131.  
    132. public int getGold() {
    133. return getConfig().getInt("item-amount.gold");
    134. }
    135.  
    136. public int getLapis() {
    137. return getConfig().getInt("item-amount.lapis");
    138. }
    139.  
    140. public int getDiamondBan() {
    141. return getConfig().getInt("ban.ban-amount.diamond");
    142. }
    143.  
    144. public int getGoldBan() {
    145. return getConfig().getInt("ban.ban-amount.gold");
    146. }
    147.  
    148. public int getLapisBan() {
    149. return getConfig().getInt("ban.ban-amount.lapis");
    150. }
    151.  
    152. public int getDiamondFine() {
    153. return getConfig().getInt("fine.fine-item-amount.diamond");
    154. }
    155.  
    156. public int getGoldFine() {
    157. return getConfig().getInt("fine.fine-item-amount.gold");
    158. }
    159.  
    160. public int getLapisFine() {
    161. return getConfig().getInt("fine.fine-item-amount.lapis");
    162. }
    163.  
    164. private boolean setupEconomy()
    165. {
    166. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    167. if (economyProvider != null) {
    168. economy = economyProvider.getProvider();
    169. }
    170. return (economy != null);
    171. }
    172.  
    173. public Economy getEcon() {
    174. return this.economy;
    175. }
    176. }
    177. [I][I][/I][/I][/i][/i]

    My Error is thrown onthe getters. @tommycake
     
  6. Offline

    metalhedd

    I may regret involving myself in this thread, but this:
    Code:java
    1. if(!file.exists() && file.isFile() )

    is definitely not what you wanted to do there.
     
  7. Offline

    beastman3226

  8. Offline

    tommycake50

    Instead of this:File file = new File(getDataFolder() + "config.yml");
    Maybe this:File file = new File(getDataFolder(), "config.yml");
    And you might want to saveConfig or saveDefaultConfig somewhere onenable.
     
  9. Offline

    beastman3226

    tommycake50
    Thank you but it didn't work.
    I find this weird because I reference getConfig() before and it worked then.
    I think I may just try get(Stringpath) and cast even though it isnt type safe.

    Thank you! My Execute class uses a new instance of my main class which doesn't like using configs.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page