Solved Configuration Help

Discussion in 'Plugin Development' started by Darkpicasa, Feb 6, 2015.

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

    Darkpicasa

    Code:
    package me.Darkpicasa.Companies.Commands;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import me.Darkpicasa.Companies.Companies;
    import me.Darkpicasa.Companies.CustomConfig;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.entity.Player;
    
    public class CFound {
        public void r(CommandSender sender, String[] args){
            if (sender instanceof Player){
                Player p = (Player) sender;
                if (!(p.hasPermission("company.command.found"))){
                    p.sendMessage(ChatColor.DARK_RED + "You do not have access to this command!");
                    return;
                }
                if (!(Companies.getInstance().getPlayerdata().getConfig().getString(p.getUniqueId().toString() + ".Company").equalsIgnoreCase("Null"))){
                    p.sendMessage(ChatColor.RED + "You are already part of a company!");
                    return;
                }
                if (args.length != 2){
                    p.sendMessage(ChatColor.WHITE + "Create a new Company!");
                    p.sendMessage(ChatColor.WHITE + "/company create <name>");
                    return;
                }
                CustomConfig company = Companies.getInstance().getCompany();
              
                if (company.getConfig().contains(args[1])){
                    p.sendMessage(ChatColor.RED + "Company with name " + ChatColor.GOLD + args[1] + ChatColor.RED + " already exists!");
                    return;
                }
              
                company.getConfig().createSection(args[1]);
                ConfigurationSection cs = company.getConfig().getConfigurationSection(args[1]);
                cs.createSection("CEO");
                cs.set("CEO", p.getUniqueId());
                company.saveConfig();
                cs.createSection("BoT");
                List<String> l = new ArrayList<String>();
                l.add("Null");
                l.add("Null2");
                cs.set("BoT", l);
                company.saveConfig();
                cs.createSection("Members");
                cs.set("Members", l);
                company.saveConfig();
                cs.createSection("Hired");
                cs.set("Hired", l);
                company.saveConfig();
                cs.createSection("Balance");
                cs.set("Balance", 0.00);
                company.saveConfig();
              
                CustomConfig playerdata = Companies.getInstance().getPlayerdata();
              
                playerdata.getConfig().set(p.getUniqueId() + ".Company", args[1]);
                playerdata.saveConfig();
              
                p.sendMessage(ChatColor.GOLD + "You successfully created a new clan!");
            }
        }
    }
    
    This is my code for one of my commands.

    When I run this command, it gets to the end of the function with no error.

    When I look at the config though, this is what I get:

    TestCompany:
    CEO: !!java.util.UUID {}
    BoT: &id001
    - 'Null'
    - Null2
    Members: *id001
    Hired: *id001
    Balance: 0.0


    Help would be appreciated, and yes, I know Java.
     
  2. Offline

    nverdier

  3. Offline

    Darkpicasa

    Thanks for pointing that out, forgot about that. Though that wasn't really my main issue, this is the config after adding the toString().

    Test:
    CEO: 629ea5f0-15d7-44c5-abcf-232cf5d7a275
    BoT: &id001
    - 'Null'
    - Null2
    Members: *id001
    Hired: *id001
    Balance: 0.0
     
  4. Offline

    nverdier

    @Darkpicasa Oh, I see. You want all of the items in the "Test" section? Why are you creating a new section? Just use ConfigurationSection#set(String path, Object value) and use a path with "Test" at the beginning, or args[1]. Also, make sure the test that there are enough items in the array!
     
  5. Offline

    Darkpicasa

    company.getConfig().createSection(args[1]);
    ConfigurationSection cs = company.getConfig().getConfigurationSection(args[1]);
    cs.createSection("CEO");
    cs.set("CEO", p.getUniqueId());
    company.saveConfig();
    cs.createSection("BoT");
    List<String> l = new ArrayList<String>();
    l.add("Null");
    l.add("Null2");
    cs.set("BoT", l);
    company.saveConfig();
    cs.createSection("Members");
    cs.set("Members", l);
    company.saveConfig();
    cs.createSection("Hired");
    cs.set("Hired", l);
    company.saveConfig();
    cs.createSection("Balance");
    cs.set("Balance", 0.00);
    company.saveConfig();

    I'm creating a new ConfigurationSection, called Test / args[1]. I then am calling that ConfigurationSection cs. Then I do stuff in that ConfigurationSection. This error has never happened to me before. My question is what is the &id001 and the *id001?
     
  6. Offline

    Darkpicasa

    Oh my bad, apparently it's a part of YAML parsing that just means that it has the same pointer as the thing above. Solved.
     
Thread Status:
Not open for further replies.

Share This Page