Solved How do I add a player to a config?

Discussion in 'Plugin Development' started by Scpp, Sep 3, 2017.

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

    Scpp

    So I am pretty new to plugins! I was wondering how would I fix this?

    if (args[0].equalsIgnoreCase("create"))
    {
    if (args.length == 1)
    {
    player.sendMessage(ChatColor.DARK_RED + "Usage:" + ChatColor.GRAY + " /nation create [name]");
    } else
    {
    if (getConfig().contains("nation." + args[1]))
    {
    player.sendMessage(ChatColor.DARK_RED + "Info:" + ChatColor.GRAY + " That name is already in use!");
    return true;
    } else
    {
    String path = "nation." + args[1] + ".owner";
    plugin.getConfig().addDefault(path, player.serialize());
    return true;
    }
    }
    return true;
    }
     
  2. Offline

    LRK

    I don't understand your issue completely but if you really want to add a player to a config use UUIDs.
    But if you really want to add player objects to your config file - which i think isn't a proper way - you could use plugin#getConfig()#getOfflinePlayer(PATH)
    Otherwise if you use uuids you could use:

    SET:
    Code:
    plugin.getConfig().addDefault("YourPath", player.getUniqueId().toString());
    
    GET:
    Code:
    String stringUUID = plugin.getConfig().getString(PATH);
    UUID uuid = UUID.fromString(stringUUID);
    if (uuid != null) {
       Player p = Bukkit.getServer().getPlayer(uuid);
       if (p != null) {
            // do something
       }
    }
    
     
  3. Offline

    Scpp

    That seem to be a better Idea! Thank you so much!
     
Thread Status:
Not open for further replies.

Share This Page