Cannot set to an empty path

Discussion in 'Plugin Development' started by Sahee, Feb 24, 2013.

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

    Sahee

    Why my path is empty? :/

    in onEnable:
    Code:
    configFile = new File(getDataFolder(), "Config.yml");
    config = new YamlConfiguration();
    My function:
    Code:
                x = lokacja.getBlockX();
                y = lokacja.getBlockY();
                z = lokacja.getBlockZ();
                String name = x + "-" + y + "-"+ z;
               
                try{
                Main.buttons.set("Buttons.", name);
                Main.buttons.set("Buttons." + name + ".range-min", rangemin);
                Main.buttons.set("Buttons." + name + ".range-max", rangemax);
                Main.saveYamls();
                }catch(Exception e){
                    e.printStackTrace();
                
    Error:
    Code:
    2013-02-24 19:16:38 [INFO] Sahee issued server command: /rlb create
    2013-02-24 19:16:38 [SEVERE] java.lang.IllegalArgumentException: Cannot set to an empty path
    2013-02-24 19:16:38 [SEVERE]    at org.apache.commons.lang.Validate.notEmpty(Validate.java:363)
    2013-02-24 19:16:38 [SEVERE]    at org.bukkit.configuration.MemorySection.set(MemorySection.java:159)
    2013-02-24 19:16:38 [SEVERE]    at org.bukkit.configuration.MemorySection.set(MemorySection.java:189)
    2013-02-24 19:16:38 [SEVERE]    at me.Sahee.Rlb.Functions.CreateButton.createdef(CreateButton.java:90)
    2013-02-24 19:16:38 [SEVERE]    at me.Sahee.Rlb.Commands.onCommand(Commands.java:29)
    2013-02-24 19:16:38 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    2013-02-24 19:16:38 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
    2013-02-24 19:16:38 [SEVERE]    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchCommand(CraftServer.java:514)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.PlayerConnection.handleCommand(PlayerConnection.java:980)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.PlayerConnection.chat(PlayerConnection.java:898)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.PlayerConnection.a(PlayerConnection.java:853)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.Packet3Chat.handle(Packet3Chat.java:44)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.NetworkManager.b(NetworkManager.java:290)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.PlayerConnection.d(PlayerConnection.java:113)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.ServerConnection.b(SourceFile:39)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:30)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    2013-02-24 19:16:38 [SEVERE]    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    Sahee
    You are trying to produce a invalid yaml. My suggestion is to write a valid yaml template, then try to replicate that in code.
     
  3. Offline

    Minecrell

    Sahee

    I think it is this line:
    Code:java
    1. Main.buttons.set("Buttons.", name);

    You try to set "Buttons." to the name, so it is:
    Code:
    Buttons:
      <empty_path>: name
    
    First with "Buttons." you go into the level in Buttons and there it is a emtpy path.
     
    Sahee likes this.
  4. Offline

    Sahee

    Minecrell, now its working but this dont add new button but set every time this one at top :/

    This now just changing x-y-z to other name
    Code:
    Buttons:
      244-66-166:
        range-min: 100
        range-max: 1000
     
  5. Offline

    Minecrell

    Sahee
    With what code do you try to set it now?
     
    Sahee likes this.
  6. Offline

    Sahee

    Main.buttons.set("Buttons.", name);
    Main.buttons.set("Buttons." + name + ".range-min", rangemin);
    Main.buttons.set("Buttons." + name + ".range-max", rangemax);
    Main.saveYamls();

    with this /|\
    I want to get:
    Code:
    Buttons:
      244-68-166:
        range-min: 100
        range-max: 1000
      244-66-166:
        range-min: 100
        range-max: 1000
      244-67-166:
        range-min: 100
        range-max: 1000

    3 buttons in same x and z but in other height
    and every time when i want to add next button this replace with 1st code :/
     
  7. Offline

    Minecrell

    You can not have multiple configuration sections with the same key, I think.
     
    Sahee likes this.
  8. Offline

    Sahee

    Then how can i do this?
    This is like add multiple factions in factions lol
     
  9. Offline

    Minecrell

    Wait... You want to get this with the code above?
    Code:
    Buttons:
      244-68-166:
        range-min: 100
        range-max: 1000
      244-66-166:
        range-min: 100
        range-max: 1000
      244-67-166:
        range-min: 100
        range-max: 1000
     
    Sahee likes this.
  10. Offline

    Sahee

    Yes i want to have buttons.yml file witch all buttons created by players with command
    /rlb create min-range max-range

    There is my function:
    Code:
    public static boolean create(String[] args, CommandSender s) {
     
            Player player = (Player) s;
            if (!s.hasPermission("rlb.create")) {
                s.sendMessage(Main.locales.getString("messages.no-permissions"));
                return false;
            }
           
     
                blok = player.getTargetBlock(null, 50).getTypeId();
                Location lokacja = player.getTargetBlock(null, 50).getLocation();
                List<Integer> bloki = Main.config.getIntegerList("BLOCKS-IDS");
                for (Integer jakiebloki : bloki) {
                    if (blok == jakiebloki && koniec == false) {
                        koniec = true;
                    }
                }
               
                if(koniec == false){
                    s.sendMessage("error.no-block");
                    return true;
                }
                x = lokacja.getBlockX();
                y = lokacja.getBlockY();
                z = lokacja.getBlockZ();
                /*if(!args[1].matches("0-9")){
                    s.sendMessage(ChatColor.RED + "your min range have to be integer.");
                    return false;
                }
               
               
               
               
                */
               
                rangemin = Integer.parseInt(args[1]);
                rangemax = Integer.parseInt(args[2]);
                String name = x + "-" + y + "-"+ z;
               
                if(Main.buttons.getConfigurationSection("Buttons." + name) != null){
                    //Checking if that guild already exists
                    s.sendMessage(ChatColor.RED + "This button is alredy used.");
                    return false;
                }
               
                Main.buttons.set("Buttons", name);
                Main.buttons.set("Buttons." + name + ".range-min", rangemin);
                Main.buttons.set("Buttons." + name + ".range-max", rangemax);
               
                Main.saveYamls();
               
                s.sendMessage(Main.locales.getString("messages.created"));
                return true;
     
        }
    And my command is using this function
     
  11. Offline

    Minecrell

    With Main.buttons.set("Buttons", name); you delete the hole settings because then the config will be set to
    Code:
    Buttons:'name'
    and than you add the sections.

    remove this line and it should work
     
    Sahee likes this.
  12. Offline

    Sahee

    Thanks bro! Tons of like for you :D
    I have one more problem. How can i delete an added button, this dont want to work:
    Code:
    x = lokacja.getBlockX();
        y = lokacja.getBlockY();
        z = lokacja.getBlockZ();
       
        Main.buttons.set("Buttons." + x + "-" + y + "-"+ z, null);
     
    Minecrell likes this.
  13. Offline

    Minecrell

    Hmm I think it should work... what is it doing? Nothing?
     
    Sahee likes this.
  14. Offline

    Sahee

    Ok, now its working. I had to saveYamls. Thanks for help :)!
     
Thread Status:
Not open for further replies.

Share This Page