Config setting strings help

Discussion in 'Plugin Development' started by tacos1223, Feb 15, 2016.

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

    tacos1223

    Probably a simple mistake but I always trip up over the most basic things, anyways, I am trying to set the x y and z coords when the player gives the correct command. The command executes flawlessly, but when I set the spawnpoint and open the config file, it remains unchanged.

    Code:
    if(args[0].equalsIgnoreCase("setlobbyspawn"))
                        {
                            Main.plugin.config.set("lobbyspawn.X", player.getLocation().getX());
                            Main.plugin.config.set("lobbyspawn.Y", player.getLocation().getY());
                            Main.plugin.config.set("lobbyspawn.Z", player.getLocation().getZ());
                            Main.plugin.config.set("lobbyspawn.world", player.getLocation().getWorld());
                            String message = Main.plugin.messages.getString("LOBBY_SPAWN");
                            String toMessage = ChatColor.translateAlternateColorCodes('&', message);
                            player.sendMessage(toMessage);
                            return true;
                        }
    and here is the config.yml:
    Code:
      ######################
      ##      SPAWNS      ##
      ######################
    
    lobbyspawn:
      X:
      Y:
      Z:
      world:
     
    ffa_gui_spawn:
      X:
      Y:
      Z:
    ffaspawn:
      X:
      Y:
      Z:
     
      ######################
      ##     PREFIXES     ##
      ######################
     
    prefix:
      allow-prefix: true
      allow-brackets: true
      prefix-id: '&9NitroPvP'
    Also the message is printed so I know everything is running through.

    Thanks,
    Tyler.
     
  2. Offline

    cococow123

    Save the config
     
  3. Offline

    tacos1223

    @cococow123

    I tried that but this happens:
    Code:
    Code:
    if(args[0].equalsIgnoreCase("setlobbyspawn"))
                        {
                            Main.plugin.config.set("lobbyspawn.X", player.getLocation().getX());
                            Main.plugin.config.set("lobbyspawn.Y", player.getLocation().getY());
                            Main.plugin.config.set("lobbyspawn.Z", player.getLocation().getZ());
                            Main.plugin.config.set("lobbyspawn.world", player.getLocation().getWorld());
                            Main.plugin.saveConfig();
                            String message = Main.plugin.messages.getString("LOBBY_SPAWN");
                            String toMessage = ChatColor.translateAlternateColorCodes('&', message);
                            player.sendMessage(toMessage);
                            return true;
                        }
    Config AfterEffect:
    Code:
    lobbyspawn: {}
    ffa_gui_spawn: {}
    ffaspawn: {}
    prefix:
      allow-prefix: true
      allow-brackets: true
      prefix-id: '&9NitroPvP'
    It also gets rid of the comments I had in default.

    Thanks,
    Tyler.
     
  4. @tacos1223
    If you're copying defaults from a config.yml in your plugin, comments are not copied across. You must set them manually in the code.

    Also, instead of doing "Main.plugin", create a method in your main class that returns the instance. Much better.
     
    cococow123 likes this.
  5. Offline

    tacos1223

    @Connor2weirdness
    @cococow123

    plugin returns the instance:
    Code:
    public static Main getInstance()
        {
            return plugin;
        }
    I appreciate the help, but I still don't understand why the values aren't being set in the config.

    Thanks,
    Tyler.
     
  6. Offline

    cococow123

    Try using a settings manager.

    ( On YT search "settings manager Pogo" and click the video by pogostick29)
     
  7. @tacos1223
    Have you done some null checks/debug messages?
     
Thread Status:
Not open for further replies.

Share This Page