Solved YAMLConfiguration still creating "!!"

Discussion in 'Bukkit Help' started by meowxiik, Sep 2, 2014.

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

    meowxiik

    Hello, I know, I posted a similiar thread few weeks ago BUT, It is doing again!! (Well, it fixed, but it is broken again) I don't know why, I don't even know how I fixed it last time, PLEASE HELP!

    P.S.:Every answer will be welcome, but don't tell me things like "Don't use that, I will never work..."
    It WAS working (Well, with Material datatype not MaterialData datatype, but thats not the reason, I think)

    My class for working with files:

    Code:java
    1. package cs.meowxiik.blockblocker;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5.  
    6. import org.bukkit.configuration.file.YamlConfiguration;
    7.  
    8.  
    9. public class FileManager {
    10.  
    11. private BlockBlocker plugin;
    12. final String pluginName = "BlockBlocker";
    13.  
    14. public FileManager(BlockBlocker blockBlocker) {
    15. this.plugin = blockBlocker;
    16. }
    17.  
    18. public YamlConfiguration getConfig(String name) {
    19. YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder().getParentFile()+ File.separator+ pluginName+ File.separator + name));
    20. try {
    21. config.save(plugin.getDataFolder().getParentFile() + File.separator+ pluginName + File.separator + name);
    22. } catch (IOException e) {
    23. logError("Error creating configuration file!");
    24. }
    25. return config;
    26. }
    27.  
    28. public void setData(YamlConfiguration file, String path, Object obj, String nameToSave){
    29. file.set(path, obj);
    30. try {file.save(plugin.getDataFolder().getParentFile() + File.separator+ pluginName + File.separator + nameToSave);
    31. } catch (IOException e) {logError("Error setting data to configuration file!");}
    32. }
    33.  
    34. public Object getData(YamlConfiguration file, String path){
    35. return file.get(path);
    36. }
    37.  
    38.  
    39. public void logError(String s){
    40. plugin.getLogger().warning(s);
    41. }
    42.  
    43. public void log(String s){
    44. plugin.getLogger().info(s);
    45. }
    46.  
    47. public int tryParse(String text) {
    48. if (text == null)
    49. return 0;
    50. try {
    51. return new Integer(text);
    52. } catch (NumberFormatException e) {
    53. return 0;
    54. }
    55. }
    56.  
    57. public boolean checkForConfig(YamlConfiguration file, String path){
    58. return (getData(file,path) != null);
    59. }
    60. }
    61.  


    My class for working wich is loading setting configs, adding banned items etc...
    Code:java
    1. package cs.meowxiik.blockblocker;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.configuration.file.YamlConfiguration;
    6. import org.bukkit.inventory.ItemStack;
    7. import org.bukkit.material.MaterialData;
    8.  
    9.  
    10. public class DataManager {
    11.  
    12. YamlConfiguration banned = new YamlConfiguration();
    13. ArrayList<MaterialData> materials = new ArrayList<MaterialData>();
    14. ArrayList<String> worlds = new ArrayList<String>();
    15. final String WORLDS_PATH = "banned.worlds";
    16. final String MATERIALS_PATH = "banned.materials";
    17. private BlockBlocker plugin;
    18. private FileManager fm;
    19.  
    20. public DataManager(FileManager fm, BlockBlocker plugin) {
    21. this.fm = fm;
    22. this.plugin = plugin;
    23. iniConfig();
    24. }
    25.  
    26. private void iniConfig(){
    27. if(fm.checkForConfig(banned, MATERIALS_PATH)){
    28. loadData();
    29. log("Config found...");
    30. }
    31. else {
    32. saveData();
    33. log("No config found...");
    34. }
    35. }
    36.  
    37. private void saveData() {
    38. log("Saving data...");
    39. fm.setData(banned, MATERIALS_PATH, materials, "banned.yml");
    40. fm.setData(banned, WORLDS_PATH, worlds, "banned.yml");
    41. }
    42.  
    43.  
    44. @SuppressWarnings("unchecked")
    45. private void loadData() {
    46. log("Loading data...");
    47.  
    48. this.materials = (ArrayList<MaterialData>) fm.getData(banned, MATERIALS_PATH);
    49. this.worlds = (ArrayList<String>) fm.getData(banned, WORLDS_PATH);
    50. if(materials == null || worlds == null){
    51. this.materials = new ArrayList<MaterialData>();
    52. this.worlds = new ArrayList<String>();
    53. }
    54. }
    55.  
    56. public void addBan(ItemStack item, String world){
    57. materials.add(item.getData());
    58. worlds.add(world);
    59. log("Item added " + item.getData() + " ,in world " + world);
    60. saveData();
    61. log(materials + "\n" + worlds);
    62. }
    63.  
    64. public void removeBan(ItemStack item, String world){
    65. for(MaterialData md : materials){
    66. if(md.equals(item.getData())){
    67. int i = (materials.indexOf(md));
    68. if(world.equals(i)){
    69. materials.remove(i);
    70. worlds.remove(i);
    71. log("Item removed " + item.getData() + " ,in world " + world);
    72. }
    73. }
    74. }
    75. log(materials + "\n" + worlds);
    76. saveData();
    77. }
    78.  
    79. public boolean isBanned(ItemStack item, String world){
    80. for(MaterialData md : materials){
    81. if(md == item.getData()){
    82. log(item + " is banned.");
    83. if(world == worlds.get(materials.indexOf(md)))return true;
    84. }
    85. }
    86. return false;
    87. }
    88.  
    89. private void log(Object o){
    90. if(plugin.debug){
    91. plugin.getLogger().info(o + "");
    92. }
    93. }
    94. }
    95.  


    And config file: (Can you see that "!!" there? I HATE THEM SO MUCH)
    Code:
    banned:
      materials:
      - !!org.bukkit.material.Wool
        color: GREEN
        data: 13
      worlds:
      - world
    
    P.S.: Please, If some knows, why is it doing this, let me know :(
     
  2. Offline

    mobkinz78

  3. Offline

    meowxiik

  4. Offline

    Necrodoom

    Maybe if you stopped trying to save objects to file and use primitives or strings, like you are supposed to.
    Read material javadocs.
     
Thread Status:
Not open for further replies.

Share This Page