Can't create config file

Discussion in 'Plugin Development' started by davidp027, Nov 29, 2014.

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

    davidp027

    I've been looking on how GriefPrevention does their config because I needed an add-on for it but it turned out to take me loads of time and I can't still find what's wrong
    And yes, i copy/pasted alot of code from their source, i know it's bad but i wanted to make it as quick as possible but it won't get released it's for a server i'm admin on. It's on craftbukkit 1.6.4.
    here's my main class code:
    Code:java
    1. package com.davidp027.leftprevent;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.block.Block;
    5. import org.bukkit.configuration.file.FileConfiguration;
    6. import org.bukkit.configuration.file.YamlConfiguration;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. import java.io.*;
    15. import java.util.*;
    16.  
    17. public class Main extends JavaPlugin implements Listener{
    18.  
    19. public MaterialCollection config_mods_blacklisted;
    20. protected final static String dataLayerFolderPath = "plugins" + File.separator + "LeftPrevent";
    21. final static String configFilePath = dataLayerFolderPath + File.separator + "config.yml";
    22.  
    23. public void loadConfig(){
    24. FileConfiguration config = YamlConfiguration.loadConfiguration(new File(configFilePath));
    25. FileConfiguration outConfig = new YamlConfiguration();
    26. this.config_mods_blacklisted = new MaterialCollection();
    27. List<String> containerTrustStrings = config.getStringList("LeftPrevent.Blacklisted");
    28. if(containerTrustStrings == null || containerTrustStrings.size() == 0)
    29. {
    30. containerTrustStrings.add(new MaterialInfo(9318, "Factorization Barrels").toString());
    31. }
    32. this.parseMaterialListFromConfig(containerTrustStrings, this.config_mods_blacklisted);
    33. outConfig.set("LeftPrevent.Blacklisted", this.config_mods_blacklisted);
    34. try
    35. {
    36. outConfig.save(configFilePath);
    37. }
    38. catch(IOException exception)
    39. {
    40. System.out.print("Unable to write to the configuration file at \"" + configFilePath + "\"");
    41. } catch (Exception e){
    42. e.printStackTrace();
    43. }
    44.  
    45. }
    46. public void onEnable(){
    47. Bukkit.getPluginManager().registerEvents(this, this);
    48. loadConfig();
    49. }
    50. public void onDisable(){
    51.  
    52. }
    53. @EventHandler
    54. public void onLeftClick(PlayerInteractEvent e){
    55. Block clickedBlock = e.getClickedBlock();
    56. if(e.getAction() == Action.LEFT_CLICK_BLOCK && clickedBlock != null){
    57. //Left clicked Block
    58. Player p = e.getPlayer();
    59. if(config_mods_blacklisted.Contains(new MaterialInfo(clickedBlock.getTypeId(), clickedBlock.getData(), null))){
    60.  
    61. }
    62. }
    63. }
    64. private void parseMaterialListFromConfig(List<String> stringsToParse, MaterialCollection materialCollection)
    65. {
    66. materialCollection.clear();
    67.  
    68. //for each string in the list
    69. for(int i = 0; i < stringsToParse.size(); i++)
    70. {
    71. //try to parse the string value into a material info
    72. MaterialInfo materialInfo = MaterialInfo.fromString(stringsToParse.get(i));
    73.  
    74. //null value returned indicates an error parsing the string from the config file
    75. if(materialInfo == null)
    76. {
    77. //show error in log
    78. System.out.print("ERROR: Unable to read a material entry from the config file. Please update your config.yml.");
    79.  
    80. //update string, which will go out to config file to help user find the error entry
    81. if(!stringsToParse.get(i).contains("can't"))
    82. {
    83. stringsToParse.set(i, stringsToParse.get(i) + " <-- can't understand this entry, see BukkitDev documentation");
    84. }
    85. }
    86.  
    87. //otherwise store the valid entry in config data
    88. else
    89. {
    90. materialCollection.Add(materialInfo);
    91. }
    92. }
    93. }
    94. }
    95.  

    Errors in the console:
    Code:
    20:48:22 [GRAVE] org.yaml.snakeyaml.error.YAMLException: No JavaBean properties
    found in com.davidp027.leftprevent.MaterialCollection
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.introspector.PropertyUtils.getProp
    ertiesMap(PropertyUtils.java:87)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.introspector.PropertyUtils.createP
    ropertySet(PropertyUtils.java:110)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.introspector.PropertyUtils.getProp
    erties(PropertyUtils.java:102)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.introspector.PropertyUtils.getProp
    erties(PropertyUtils.java:94)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.Representer.getPropert
    ies(Representer.java:239)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.Representer$RepresentJ
    avaBean.representData(Representer.java:50)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    entData(BaseRepresenter.java:110)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    entMapping(BaseRepresenter.java:164)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.SafeRepresenter$Repres
    entMap.representData(SafeRepresenter.java:201)
    20:48:22 [GRAVE]        at org.bukkit.configuration.file.YamlRepresenter$Represe
    ntConfigurationSection.representData(YamlRepresenter.java:23)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    entData(BaseRepresenter.java:96)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    entMapping(BaseRepresenter.java:164)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.SafeRepresenter$Repres
    entMap.representData(SafeRepresenter.java:201)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    entData(BaseRepresenter.java:96)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.representer.BaseRepresenter.repres
    ent(BaseRepresenter.java:66)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:270)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:261)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:233)
    20:48:22 [GRAVE]        at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209)
    20:48:22 [GRAVE]        at org.bukkit.configuration.file.YamlConfiguration.saveT
    oString(YamlConfiguration.java:38)
    20:48:22 [GRAVE]        at org.bukkit.configuration.file.FileConfiguration.save(
    FileConfiguration.java:54)
    20:48:22 [GRAVE]        at org.bukkit.configuration.file.FileConfiguration.save(
    FileConfiguration.java:78)
    20:48:22 [GRAVE]        at com.davidp027.leftprevent.Main.loadConfig(Main.java:3
    6)
    20:48:22 [GRAVE]        at com.davidp027.leftprevent.Main.onEnable(Main.java:48)
     
    20:48:22 [GRAVE]        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
    in.java:217)
    20:48:22 [GRAVE]        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(
    JavaPluginLoader.java:457)
    20:48:22 [GRAVE]        at org.bukkit.plugin.SimplePluginManager.enablePlugin(Si
    mplePluginManager.java:381)
    20:48:22 [GRAVE]        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin
    (CraftServer.java:284)
    20:48:22 [GRAVE]        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlug
    ins(CraftServer.java:266)
    20:48:22 [GRAVE]        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.reload(Cra
    ftServer.java:615)
    20:48:22 [GRAVE]        at org.bukkit.Bukkit.reload(Bukkit.java:277)
    20:48:22 [GRAVE]        at org.bukkit.command.defaults.ReloadCommand.execute(Rel
    oadCommand.java:23)
    20:48:22 [GRAVE]        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
    mmandMap.java:192)
    20:48:22 [GRAVE]        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCo
    mmand(CraftServer.java:528)
    20:48:22 [GRAVE]        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchSe
    rverCommand(CraftServer.java:515)
    20:48:22 [GRAVE]        at net.minecraft.server.v1_6_R3.DedicatedServer.as(Dedic
    atedServer.java:263)
    20:48:22 [GRAVE]        at net.minecraft.server.v1_6_R3.DedicatedServer.t(Dedica
    tedServer.java:228)
    20:48:22 [GRAVE]        at net.minecraft.server.v1_6_R3.MinecraftServer.s(Minecr
    aftServer.java:488)
    20:48:22 [GRAVE]        at net.minecraft.server.v1_6_R3.MinecraftServer.run(Mine
    craftServer.java:421)
    20:48:22 [GRAVE]        at net.minecraft.server.v1_6_R3.ThreadServerApplication.
    run(SourceFile:583)
    
     
  2. At the top add:
    Code:java
    1. @Override
    2. public void onEnable(){
    3. saveDefaultConfig();
    4. }
     
  3. Offline

    davidp027

    Just create an empty config and still getting the same error
     
  4. In the IDE, did you create a config.yml with the plugin.yml?
     
  5. Offline

    davidp027

    Shouldn't need to. Take a look at grief prevention source that's where most of my code comes from
    https://github.com/ryanhamshire/GriefPrevention
     
  6. Offline

    Skionz

    davidp027 So you copied the code? *facepalm*
     
  7. Offline

    HeadGam3z

     
  8. Offline

    davidp027

    Yeah need this plugin really quickly that's why I copied the code but it's not going anywhere else than the server I'm making it for.
     
Thread Status:
Not open for further replies.

Share This Page