Solved Need help with ConfigurationSection not being a ConfigurationSection

Discussion in 'Plugin Development' started by Maxx_Qc, Dec 13, 2017.

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

    Maxx_Qc

    Code:
    Code:
    System.out.println(plugin.config.isConfigurationSection(team + ".loc1"));
    
            System.out.println(plugin.config.isConfigurationSection(team + ".loc2"));
        
            System.out.println(plugin.config
                                .getConfigurationSection(team + ".loc1")
                                .getValues(true));
            System.out.println(plugin.config
                    .getConfigurationSection(team + ".loc2")
                    .getValues(true));
    Config:
    Code:
    verte:
      totem-id: 4ff7b346-00cb-4aba-93a0-53a94efe3663
      totem-hp: 992
      loc2:
        world: world
        x: -69.69999998807907
        y: 260.0
        z: -304.69999998807907
        pitch: 0.0
        yaw: 0.0
      loc1:
        world: world
        x: -63.4253482146536
        y: 0.0
        z: -298.42200136851733
        pitch: 0.0
        yaw: 0.0

    Problem:
    Hi, I'm trying to deserialize a Location that I saved to my config. However, the code doesn't recognise the configurationsection has a configurationsection. The first and second outputs print "false" and the two others just create some NPE. Btw I'm using Location.deserialize(plugin.config.getConfigurationSection(team + ".loc2").getValues(true)))); to deserialize the location but as I said it doesn't work. Sometimes one of them is considered as a configurationsection but I need both of them.

    EDIT: my NPE are at getValues location (line number)


    What you have tried:
    Tried many things with the code, but it didn't work out very well. Looking at the doc and making some searches on google to see if anyone else had this problem.

    Thank you!
     
    Last edited by a moderator: Dec 13, 2017
  2. Offline

    Caderape2

    @Maxx_Qc
    You created your own way for get the config.yml. This is probably why it dun work.
    Show your main class.
     
  3. Offline

    Maxx_Qc

    As I said, the NPE are on getValues. My plugin.config works just fine with everything else.
    Just to prove it to you:
    Code:
    public FileConfiguration config;
    
    public void onEnable() {
      config = this.getConfig();
    }
    Thank you anyway
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Maxx_Qc plugin.config.getKeys(true)
    Please print all values of the set that will be returned.
     
  5. Offline

    Maxx_Qc

    Code:
    state, season-nmb, map-size, team-size, open-mode, join-msg, leave-msg, rouge-name, bleue-name, jaune-name, verte-name, mauve-name, spec-place, start-pvp, end-pvp, difficulty, border-shrink, totem-hp, reward-points, reward-time, last-day, final-pvp-start, shop, shop.nourriture, shop.nourriture.icon, shop.nourriture.CARROT_ITEM, shop.nourriture.CARROT_ITEM.price, shop.nourriture.CARROT_ITEM.single, shop.nourriture.POTATO_ITEM, shop.nourriture.POTATO_ITEM.price, shop.nourriture.POTATO_ITEM.single, shop.armes_et_armures, shop.armes_et_armures.icon, shop.armes_et_armures.WOOD_SWORD, shop.armes_et_armures.WOOD_SWORD.price, shop.armes_et_armures.WOOD_SWORD.single, shop.armes_et_armures.LEATHER_CHESTPLATE, shop.armes_et_armures.LEATHER_CHESTPLATE.price, shop.armes_et_armures.LEATHER_CHESTPLATE.single, shop.nourriture.CARROT_ITEM.limit, shop.nourriture.POTATO_ITEM.limit, shop.armes_et_armures.WOOD_SWORD.limit, shop.armes_et_armures.LEATHER_CHESTPLATE.limit, bleue, bleue.totem-id, bleue.totem-hp, jaune, verte, verte.totem-id, verte.totem-hp, verte.loc2, verte.loc1, verte.loc1.world, verte.loc1.x, verte.loc1.y, verte.loc1.z, verte.loc1.pitch, verte.loc1.yaw
    Wow, I don't get why isn't verte.loc2.world, verte.loc2.x.... there.
    Here is a screenshot to my config file:
    upload_2017-12-14_11-49-56.png

    I don't get why isn't it working.
    It isn't the only configuration section in my config. The others are working.
    Full code of the command that set the loc1 and loc2:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender.isOp())) return true;
            if (!(sender instanceof Player)) return true;
          
            Player p = (Player) sender;
    
            if (args.length < 2) {
                sender.sendMessage(Util.colorize("&eUsage: /setbase <rouge/bleue/verte/jaune/mauve> <1/2>"));
                return true;
            }
          
            if ((!args[0].equalsIgnoreCase("rouge")) && (!args[0].equalsIgnoreCase("bleue")) && (!args[0].equalsIgnoreCase("verte")) &&
                    (!args[0].equalsIgnoreCase("jaune")) && (!args[0].equalsIgnoreCase("mauve"))) {
                sender.sendMessage(Util.colorize("&eUsage: /setbase <rouge/bleue/verte/jaune/mauve> <1/2>"));
                return true;
            }
          
            if (!args[1].equalsIgnoreCase("1") && !args[1].equalsIgnoreCase("2")) {
                sender.sendMessage(Util.colorize("&eUsage: /setbase <rouge/bleue/verte/jaune/mauve> <1/2>"));
                return true;
            }
          
            String team = args[0].toLowerCase();
            int point = Integer.valueOf(args[1]);
          
            plugin.config.set(team + ".loc" + point, new Location(Bukkit.getWorld("world"), p.getLocation().getX(), point == 1 ? 0 : 260, p.getLocation().getZ()).serialize());
            plugin.saveConfig();
          
            p.sendMessage(Util.colorize("&ePoint " + point + " de l'équipe " + Util.getTeamColor(plugin, team) + team + "&e a été définit!"));
          
          
          
            System.out.println(plugin.config.getKeys(true));
          
            System.out.println(plugin.config.isConfigurationSection(team + ".loc1"));
            System.out.println(plugin.config.isConfigurationSection(team + ".loc2"));
          
            System.out.println(plugin.config
                                .getConfigurationSection(team + ".loc1")
                                .getKeys(true));
            System.out.println(plugin.config
                    .getConfigurationSection(team + ".loc2")
                    .getValues(true));
          
            /*
            if (plugin.config.contains(team + ".loc1") && plugin.config.contains(team + ".loc2"))
                plugin.baseCuboids.put(team, new Cuboid("rouge",
                        Location.deserialize(plugin.config
                                .getConfigurationSection(team + ".loc1")
                                .getValues(true)),
                        Location.deserialize(plugin.config
                                .getConfigurationSection(team + ".loc2")
                                .getValues(true))));*/
          
            return true;
        }
     
    Last edited by a moderator: Dec 14, 2017
  6. Offline

    Maxx_Qc

    Bump! Plz :/

    EDIT: Got it to work, change loc1 to loc.1 and now it detects it as a configurationsection
     
    Last edited: Dec 15, 2017
    Drkmaster83 likes this.
Thread Status:
Not open for further replies.

Share This Page