Solved Setting Config Not Working

Discussion in 'Spigot Plugin Development' started by Futurize, Apr 13, 2017.

  1. This is my command to set a value in the config file. It is not working and no errors are popping up. Can't seem to figure out why it isn't working so any help would be appreciated. Thanks.

    Code (Text):
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

            if (command.getName().equalsIgnoreCase("spawnpoint")) {
                if (sender instanceof Player) {
                    Player p = (Player) sender;
                    if (p.hasPermission("arena.admin")) {
                        if (args.length != 1) {
                            p.sendMessage(ChatColor.RED + "Correct usage: /spawnpoint [number]");
                        } else {

                            String number = args[0];

                            double x = p.getLocation().getX();
                            double y = p.getLocation().getY();
                            double z = p.getLocation().getZ();

                            this.getConfig().set("spawnpoints." + number + ".x", x);
                            this.getConfig().set("spawnpoints." + number + ".y", y);
                            this.getConfig().set("spawnpoints." + number + ".z", z);

                            p.sendMessage(ChatColor.GREEN + "Set spawnpoint " + number + " at " + ChatColor.YELLOW + x + " "
                                    + y + " " + z);
                        }
                    }
                }
            }
            return true;
        }
     
  2. You need to save the config
     
    • Agree Agree x 2
  3. add saveConfig() after set
     
    • Agree Agree x 1
  4. It worked. Thanks!
     
    • Like Like x 1